Sync the list of locales between config & app code

This commit is contained in:
Lim Chee Aun 2024-08-14 17:16:56 +08:00
parent fcb85d1172
commit f359d36e9b
4 changed files with 13 additions and 8 deletions

View file

@ -1,5 +1,7 @@
import { LOCALES } from './src/locales';
const config = {
locales: ['en', 'pseudo-LOCALE'],
locales: LOCALES,
pseudoLocale: 'pseudo-LOCALE',
fallbackLocales: {
default: 'en',

View file

@ -1,6 +1,7 @@
import { useLingui } from '@lingui/react';
import { activateLang, DEFAULT_LANG, LOCALES } from '../utils/lang';
import { DEFAULT_LANG, LOCALES } from '../locales';
import { activateLang } from '../utils/lang';
import localeCode2Text from '../utils/localeCode2Text';
export default function LangSelector() {

7
src/locales.js Normal file
View file

@ -0,0 +1,7 @@
export const DEFAULT_LANG = 'en';
const locales = [DEFAULT_LANG];
if (import.meta.env.DEV) {
locales.push('pseudo-LOCALE');
}
export const LOCALES = locales;

View file

@ -7,17 +7,12 @@ import {
} from '@lingui/detect-locale';
import Locale from 'intl-locale-textinfo-polyfill';
import { DEFAULT_LANG, LOCALES } from '../locales';
import { messages } from '../locales/en.po';
import localeMatch from '../utils/locale-match';
const { PHANPY_DEFAULT_LANG } = import.meta.env;
export const DEFAULT_LANG = 'en';
export const LOCALES = [DEFAULT_LANG];
if (import.meta.env.DEV) {
LOCALES.push('pseudo-LOCALE');
}
i18n.load(DEFAULT_LANG, messages);
i18n.on('change', () => {
const lang = i18n.locale;