Files
omni-tools/src/i18n/index.ts

40 lines
894 B
TypeScript
Raw Normal View History

2025-07-15 19:42:34 +01:00
import i18n, { Namespace, ParseKeys } from 'i18next';
2025-07-12 23:02:35 -07:00
import { initReactI18next } from 'react-i18next';
import Backend from 'i18next-http-backend';
2025-07-15 19:42:34 +01:00
export const validNamespaces = [
2025-07-14 18:04:30 +01:00
'string',
'number',
'video',
'list',
'json',
'time',
'csv',
'pdf',
'audio',
'xml',
'translation',
'image'
2025-07-15 19:42:34 +01:00
] as const satisfies readonly Namespace[];
2025-07-14 18:04:30 +01:00
export type I18nNamespaces = (typeof validNamespaces)[number];
2025-07-13 16:59:57 +01:00
export type FullI18nKey = {
[K in I18nNamespaces]: `${K}:${ParseKeys<K>}`;
}[I18nNamespaces];
2025-07-12 23:02:35 -07:00
2025-07-14 19:38:46 +01:00
i18n
.use(Backend)
.use(initReactI18next)
.init({
lng: localStorage.getItem('lang') || 'en',
fallbackLng: 'en',
2025-07-15 19:58:56 +01:00
interpolation: {
escapeValue: false // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape
},
2025-07-14 19:38:46 +01:00
backend: {
loadPath: '/locales/{{lng}}/{{ns}}.json'
}
});
2025-07-12 23:02:35 -07:00
export default i18n;