mirror of
https://github.com/logto-io/logto.git
synced 2025-03-10 22:22:45 -05:00
fix(ui,core): fix i18n issue (#1548)
* fix(ui,core): fix i18n issue fix i18n issue * fix(core): cr fix cr fix
This commit is contained in:
parent
8cd59a5c4d
commit
6b58d8a161
3 changed files with 33 additions and 15 deletions
|
@ -65,12 +65,25 @@ export default function wellKnownRoutes<T extends AnonymousRouter>(router: T, pr
|
|||
];
|
||||
}, []);
|
||||
|
||||
const notification =
|
||||
interaction?.params.client_id === demoAppApplicationId
|
||||
? i18next.t('demo_app.notification')
|
||||
: undefined;
|
||||
// Insert Demo App Notification
|
||||
if (interaction?.params.client_id === demoAppApplicationId) {
|
||||
const {
|
||||
languageInfo: { autoDetect, fixedLanguage },
|
||||
} = signInExperience;
|
||||
|
||||
ctx.body = { ...signInExperience, socialConnectors, notification };
|
||||
ctx.body = {
|
||||
...signInExperience,
|
||||
socialConnectors,
|
||||
notification: i18next.t(
|
||||
'demo_app.notification',
|
||||
autoDetect ? undefined : { lng: fixedLanguage }
|
||||
),
|
||||
};
|
||||
|
||||
return next();
|
||||
}
|
||||
|
||||
ctx.body = { ...signInExperience, socialConnectors };
|
||||
|
||||
return next();
|
||||
},
|
||||
|
|
|
@ -33,7 +33,7 @@ const usePreview = (context: Context): [boolean, PreviewConfig?] => {
|
|||
}
|
||||
|
||||
// Init i18n
|
||||
void initI18n();
|
||||
void initI18n(undefined, isPreview);
|
||||
|
||||
// Block pointer event
|
||||
document.body.classList.add(conditionalString(styles.preview));
|
||||
|
|
|
@ -4,25 +4,30 @@ import i18next, { InitOptions } from 'i18next';
|
|||
import LanguageDetector from 'i18next-browser-languagedetector';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
|
||||
const initI18n = async (languageSettings?: LanguageInfo) => {
|
||||
const baseOptions: InitOptions = {
|
||||
const storageKey = 'i18nextLogtoUiLng';
|
||||
|
||||
const initI18n = async (languageSettings?: LanguageInfo, isPreview = false) => {
|
||||
const options: InitOptions = {
|
||||
resources,
|
||||
fallbackLng: languageSettings?.fallbackLanguage ?? 'en',
|
||||
lng: languageSettings?.autoDetect === false ? languageSettings.fixedLanguage : undefined,
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
detection: {
|
||||
lookupLocalStorage: 'i18nextLogtoUiLng',
|
||||
lookupSessionStorage: 'i18nextLogtoUiLng',
|
||||
lookupLocalStorage: storageKey,
|
||||
lookupSessionStorage: storageKey,
|
||||
},
|
||||
};
|
||||
|
||||
const options: InitOptions =
|
||||
languageSettings?.autoDetect === false
|
||||
? { ...baseOptions, lng: languageSettings.fixedLanguage }
|
||||
: baseOptions;
|
||||
i18next.use(initReactI18next);
|
||||
|
||||
const i18n = i18next.use(initReactI18next).use(LanguageDetector).init(options);
|
||||
// Should not apply auto detect if is preview or fix
|
||||
if (!isPreview && !(languageSettings?.autoDetect === false)) {
|
||||
i18next.use(LanguageDetector);
|
||||
}
|
||||
|
||||
const i18n = i18next.init(options);
|
||||
|
||||
// @ts-expect-error - i18next doesn't have a type definition for this. called after i18next is initialized
|
||||
i18next.services.formatter.add('zhOrSpaces', (value: string, lng) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue