2025-07-13 15:39:12 +01:00
|
|
|
import i18n, { ParseKeys } from 'i18next';
|
2025-07-12 23:02:35 -07:00
|
|
|
import { initReactI18next } from 'react-i18next';
|
2025-07-14 15:26:41 +01:00
|
|
|
import Backend from 'i18next-http-backend';
|
|
|
|
|
|
|
|
|
|
const isDevelopment = !import.meta.env.PROD;
|
|
|
|
|
const isContributor = import.meta.env.VITE_CONTRIBUTOR_MODE === 'true';
|
|
|
|
|
|
|
|
|
|
const useLocize = isDevelopment && isContributor;
|
|
|
|
|
if (useLocize) {
|
|
|
|
|
const { default: LocizeBackend } = await import('i18next-locize-backend');
|
|
|
|
|
i18n.use(LocizeBackend);
|
|
|
|
|
console.log('Using Locize backend in development/contributor mode');
|
|
|
|
|
} else {
|
|
|
|
|
// Use static files in production
|
|
|
|
|
i18n.use(Backend);
|
|
|
|
|
}
|
2025-07-12 23:02:35 -07:00
|
|
|
|
2025-07-13 11:25:05 +01:00
|
|
|
const locizeOptions = {
|
2025-07-14 15:36:06 +01:00
|
|
|
projectId: 'e7156a3e-66fb-4035-a0f0-cebf1c63a3ba',
|
|
|
|
|
apiKey: import.meta.env.LOCIZE_API_KEY,
|
2025-07-13 11:25:05 +01:00
|
|
|
referenceLng: 'en',
|
|
|
|
|
version: 'latest'
|
|
|
|
|
};
|
2025-07-13 15:39:12 +01:00
|
|
|
|
2025-07-14 18:04:30 +01:00
|
|
|
export const validNamespaces: string[] = [
|
|
|
|
|
'string',
|
|
|
|
|
'number',
|
|
|
|
|
'video',
|
|
|
|
|
'list',
|
|
|
|
|
'json',
|
|
|
|
|
'time',
|
|
|
|
|
'csv',
|
|
|
|
|
'pdf',
|
|
|
|
|
'audio',
|
|
|
|
|
'xml',
|
|
|
|
|
'translation',
|
|
|
|
|
'image'
|
|
|
|
|
];
|
|
|
|
|
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 15:26:41 +01:00
|
|
|
i18n.use(initReactI18next).init({
|
2025-07-13 15:39:12 +01:00
|
|
|
lng: 'en',
|
|
|
|
|
fallbackLng: 'en',
|
2025-07-14 18:04:30 +01:00
|
|
|
debug: false,
|
2025-07-14 15:26:41 +01:00
|
|
|
backend: useLocize
|
|
|
|
|
? locizeOptions
|
|
|
|
|
: {
|
|
|
|
|
loadPath: '/locales/{{lng}}/{{ns}}.json'
|
2025-07-14 16:06:29 +01:00
|
|
|
},
|
|
|
|
|
saveMissing: useLocize,
|
|
|
|
|
updateMissing: useLocize
|
2025-07-13 15:39:12 +01:00
|
|
|
});
|
2025-07-12 23:02:35 -07:00
|
|
|
|
|
|
|
|
export default i18n;
|