Skip to content

Commit

Permalink
fix(i18n): use correct i18n text bundle (#6720)
Browse files Browse the repository at this point in the history
Co-authored-by: Nayden Naydenov <nnaydenow.work@sap.com>
  • Loading branch information
nnaydenow and Nayden Naydenov authored Mar 17, 2023
1 parent 9ea5c93 commit 9636000
Showing 1 changed file with 12 additions and 4 deletions.
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

0 comments on commit 9636000

Please sign in to comment.