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:
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user