fix(frontend): isolate subscription language preference (#6394)
* fix(frontend): isolate subscription language preference * fix(frontend): defer date locale resolution
This commit is contained in:
1 parent
0c72dd8384
commit
ded2aa150c
5 files changed
+95
-23
No files matched your search
@@ -12,7 +12,7 @@ if (messageContainer) {
|
||||
message.config({ getContainer: () => messageContainer });
|
||||
}
|
||||
|
||||
readyI18n().then(() => {
|
||||
readyI18n('subscription').then(() => {
|
||||
const root = document.getElementById('app');
|
||||
if (root) {
|
||||
createRoot(root).render(
|
||||
|
||||
@@ -2,6 +2,7 @@ import i18next from 'i18next';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
|
||||
import { LanguageManager } from '@/utils';
|
||||
import type { LanguageScope } from '@/utils';
|
||||
import enUS from '../../../internal/web/translation/en-US.json';
|
||||
|
||||
const FALLBACK = 'en-US';
|
||||
@@ -15,15 +16,15 @@ function moduleKeyFor(code: string): string {
|
||||
return `../../../internal/web/translation/${code}.json`;
|
||||
}
|
||||
|
||||
let active: string = LanguageManager.getLanguage();
|
||||
if (
|
||||
active !== FALLBACK &&
|
||||
!Object.prototype.hasOwnProperty.call(lazyModules, moduleKeyFor(active))
|
||||
) {
|
||||
active = FALLBACK;
|
||||
}
|
||||
export async function readyI18n(scope: LanguageScope = 'panel') {
|
||||
let active = LanguageManager.getLanguage(scope);
|
||||
if (
|
||||
active !== FALLBACK &&
|
||||
!Object.prototype.hasOwnProperty.call(lazyModules, moduleKeyFor(active))
|
||||
) {
|
||||
active = FALLBACK;
|
||||
}
|
||||
|
||||
export async function readyI18n() {
|
||||
await i18next.use(initReactI18next).init({
|
||||
lng: active,
|
||||
fallbackLng: FALLBACK,
|
||||
|
||||
@@ -93,11 +93,11 @@ export default function SubPage() {
|
||||
setMessageInstance(messageApi);
|
||||
}, [messageApi]);
|
||||
const { isMobile } = useMediaQuery(576);
|
||||
const [lang, setLang] = useState<string>(() => LanguageManager.getLanguage());
|
||||
const [lang, setLang] = useState<string>(() => LanguageManager.getLanguage('subscription'));
|
||||
|
||||
const onLangChange = useCallback((next: string) => {
|
||||
setLang(next);
|
||||
LanguageManager.setLanguage(next);
|
||||
LanguageManager.setLanguage(next, 'subscription');
|
||||
}, []);
|
||||
|
||||
const cycleTheme = useCallback(() => {
|
||||
@@ -186,16 +186,18 @@ export default function SubPage() {
|
||||
items.push({
|
||||
key: 'lastOnline',
|
||||
label: t('lastOnline'),
|
||||
children: lastOnlineMs > 0 ? IntlUtil.formatDate(lastOnlineMs, datepicker) : '-',
|
||||
children: lastOnlineMs > 0 ? IntlUtil.formatDate(lastOnlineMs, datepicker, lang) : '-',
|
||||
});
|
||||
items.push({
|
||||
key: 'expiry',
|
||||
label: t('subscription.expiry'),
|
||||
children:
|
||||
expireMs === 0 ? t('subscription.noExpiry') : IntlUtil.formatDate(expireMs, datepicker),
|
||||
expireMs === 0
|
||||
? t('subscription.noExpiry')
|
||||
: IntlUtil.formatDate(expireMs, datepicker, lang),
|
||||
});
|
||||
return items;
|
||||
}, [t]);
|
||||
}, [t, lang]);
|
||||
|
||||
const androidMenuItems = useMemo(
|
||||
() => [
|
||||
|
||||
Loaded 3 of 5 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user