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: add fallbackLocales to show translations even if there is no connection to the server #1259

Merged
merged 2 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
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
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