Skip to content

Commit

Permalink
fix: add fallbackLocales to show translations even if there is no con…
Browse files Browse the repository at this point in the history
…nection to the server (#1259)
  • Loading branch information
SGrueber authored Sep 2, 2022
1 parent 9e079a2 commit 9b3ec42
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ConfigurationState {
features?: string[];
addFeatures?: string[];
defaultLocale?: string;
fallbackLocales?: string[];
localeCurrencyOverride?: { [locale: string]: string | string[] };
lang?: string;
currency?: string;
Expand All @@ -36,6 +37,7 @@ const initialState: ConfigurationState = {
features: undefined,
addFeatures: [],
defaultLocale: environment.defaultLocale,
fallbackLocales: environment.fallbackLocales,
localeCurrencyOverride: environment.localeCurrencyOverride,
lang: undefined,
currency: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ export const getFeatures = createSelector(getConfigurationState, state =>

const internalDefaultLocale = createSelector(getConfigurationState, state => state.defaultLocale);

const internalFallbackLocales = createSelector(getConfigurationState, state => state.fallbackLocales);

const internalCurrencyFilter = createSelector(getConfigurationState, state => state.localeCurrencyOverride);

/**
* locales configured in ICM
*/
export const getAvailableLocales = createSelector(getServerConfigParameter<string[]>('general.locales'), activated =>
activated?.length ? activated : undefined
export const getAvailableLocales = createSelector(
internalFallbackLocales,
getServerConfigParameter<string[]>('general.locales'),
(fallbackLocales, serverLocales) => (serverLocales?.length ? serverLocales : fallbackLocales)
);

const internalRequestedLocale = createSelector(getConfigurationState, state => state.lang);
Expand Down
4 changes: 4 additions & 0 deletions src/environments/environment.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export interface Environment {
// default locale that is used as fallback if no default locale from the ICM REST call is available (should only be set for local development)
defaultLocale?: string;

// fallback locales if the locales from the configurations REST call are not available/not responding (to have a working translation functionality with the translations provided as source code)
fallbackLocales?: string[];

// configuration filtering available locales and their active currencies
localeCurrencyOverride?: { [locale: string]: string | string[] };

Expand Down Expand Up @@ -146,6 +149,7 @@ export const ENVIRONMENT_DEFAULTS: Omit<Environment, 'icmChannel'> = {
},
defaultProductListingViewType: 'grid',
defaultDeviceType: 'mobile',
fallbackLocales: ['en_US', 'de_DE', 'fr_FR'],
multiSiteLocaleMap: {
en_US: '/en',
de_DE: '/de',
Expand Down

0 comments on commit 9b3ec42

Please sign in to comment.