Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(i18n): use correct i18n text bundle #6720

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/base/src/asset-registries/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,15 @@ const _loadMessageBundleOnce = (packageName: string, localeId: string) => {
const _showAssetsWarningOnce = (packageName: string) => {
if (!warningShown.has(packageName)) {
console.warn(`[${packageName}]: Message bundle assets are not configured. Falling back to English texts.`, /* eslint-disable-line */
` Add \`import "${packageName}/dist/Assets.js"\` in your bundle and make sure your build tool supports dynamic imports and JSON imports. See section "Assets" in the documentation for more information.`); /* eslint-disable-line */
` Add \`import "${packageName}/dist/Assets.js"\` in your bundle and make sure your build tool supports dynamic imports and JSON imports. See section "Assets" in the documentation for more information.`); /* eslint-disable-line */
warningShown.add(packageName);
}
};

const useFallbackBundle = (packageName: string, localeId: string) => {
return localeId !== DEFAULT_LANGUAGE && !_hasLoader(packageName, localeId);
};

/**
* This method preforms the asynchronous task of fetching the actual text resources. It will fetch
* each text resource over the network once (even for multiple calls to the same method).
Expand All @@ -75,10 +79,14 @@ const _showAssetsWarningOnce = (packageName: string) => {
const fetchI18nBundle = async (packageName: string) => {
const language = getLocale().getLanguage();
const region = getLocale().getRegion();
let localeId = normalizeLocale(language + (region ? `-${region}` : ``));
let localeId = language + (region ? `-${region}` : ``);

while (localeId !== DEFAULT_LANGUAGE && !_hasLoader(packageName, localeId)) {
localeId = nextFallbackLocale(localeId);
if (useFallbackBundle(packageName, localeId)) {
localeId = normalizeLocale(localeId);

while (useFallbackBundle(packageName, localeId)) {
localeId = nextFallbackLocale(localeId);
}
}

// use default language unless configured to always fetch it from the network
Expand Down