mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-21 06:59:33 +02:00
40 lines
894 B
TypeScript
40 lines
894 B
TypeScript
import i18n, { Namespace, ParseKeys } from 'i18next';
|
|
import { initReactI18next } from 'react-i18next';
|
|
import Backend from 'i18next-http-backend';
|
|
|
|
export const validNamespaces = [
|
|
'string',
|
|
'number',
|
|
'video',
|
|
'list',
|
|
'json',
|
|
'time',
|
|
'csv',
|
|
'pdf',
|
|
'audio',
|
|
'xml',
|
|
'translation',
|
|
'image'
|
|
] as const satisfies readonly Namespace[];
|
|
|
|
export type I18nNamespaces = (typeof validNamespaces)[number];
|
|
export type FullI18nKey = {
|
|
[K in I18nNamespaces]: `${K}:${ParseKeys<K>}`;
|
|
}[I18nNamespaces];
|
|
|
|
i18n
|
|
.use(Backend)
|
|
.use(initReactI18next)
|
|
.init({
|
|
lng: localStorage.getItem('lang') || 'en',
|
|
fallbackLng: 'en',
|
|
interpolation: {
|
|
escapeValue: false // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape
|
|
},
|
|
backend: {
|
|
loadPath: '/locales/{{lng}}/{{ns}}.json'
|
|
}
|
|
});
|
|
|
|
export default i18n;
|