Migrate to lingui

Switch to "lingui" for better DX.
Tried to persist existing languages as much as possible.

Removed "vite-plugin-node-polyfills" because it's incompatible with "lingui"
This commit is contained in:
schroda
2026-01-10 19:45:02 +01:00
parent c1ac58f4d6
commit 65a9a905be
287 changed files with 120766 additions and 37748 deletions

View File

@@ -6,11 +6,13 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
export const defaultPromiseErrorHandler = (name: string) => (error: any) => {
if (import.meta.env.PROD) {
return;
}
export const defaultPromiseErrorHandler =
(name: string, allowProd: boolean = false) =>
(error: any) => {
if (!allowProd && import.meta.env.PROD) {
return;
}
// eslint-disable-next-line no-console
console.error(`${name} failed due to`, error);
};
// eslint-disable-next-line no-console
console.error(`${name} failed due to`, error);
};

View File

@@ -12,6 +12,72 @@ export type LanguageObject = ISOLanguage & { orgCode: string; isoCode: string };
export const DEFAULT_LANGUAGE = 'en';
// source: https://github.com/i18next/i18next/blob/485b4ec8183952b3de8fe5e79dff6467c3afd9d3/src/i18next.js#L561
const RTL_LANGUAGES = [
'ar',
'shu',
'sqr',
'ssh',
'xaa',
'yhd',
'yud',
'aao',
'abh',
'abv',
'acm',
'acq',
'acw',
'acx',
'acy',
'adf',
'ads',
'aeb',
'aec',
'afb',
'ajp',
'apc',
'apd',
'arb',
'arq',
'ars',
'ary',
'arz',
'auz',
'avl',
'ayh',
'ayl',
'ayn',
'ayp',
'bbz',
'pga',
'he',
'iw',
'ps',
'pbt',
'pbu',
'pst',
'prp',
'prd',
'ug',
'ur',
'ydd',
'yds',
'yih',
'ji',
'yi',
'hbo',
'men',
'xmn',
'fa',
'jpr',
'peo',
'pes',
'prs',
'dv',
'sam',
'ckb',
];
export function getISOLanguageFor(code: string, orgCode: string = code, isoCode: string = code): LanguageObject | null {
if (IsoLanguages[code]) {
return {
@@ -53,3 +119,21 @@ export function getPreferredISOLanguageCodes(): readonly string[] {
return preferredLanguages;
}
export function getLanguageReadingDirection(code: string): 'ltr' | 'rtl' {
const language = getISOLanguage(code);
if (code.toLowerCase().includes('-latn') || language?.isoCode.includes('-latn')) {
return 'ltr';
}
if (code.toLowerCase().includes('-arab') || language?.isoCode.toLowerCase().includes('-arab')) {
return 'rtl';
}
if (RTL_LANGUAGES.includes(code) || RTL_LANGUAGES.includes(language?.isoCode as string)) {
return 'rtl';
}
return 'ltr';
}