2025-02-08 18:42:39 -08:00
|
|
|
import i18n from "i18next";
|
|
|
|
|
import { initReactI18next } from "react-i18next";
|
2026-02-12 19:13:53 +00:00
|
|
|
import type { Resource } from "i18next";
|
2025-02-07 01:59:54 +03:00
|
|
|
|
2025-05-27 10:01:10 -07:00
|
|
|
const primaryLanguage = "en";
|
2025-02-07 01:59:54 +03:00
|
|
|
|
2026-02-12 19:13:53 +00:00
|
|
|
interface TranslationModule {
|
|
|
|
|
default?: Record<string, unknown>;
|
|
|
|
|
[key: string]: unknown;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-30 15:03:32 -07:00
|
|
|
// Load all translation files eagerly
|
2026-02-12 19:13:53 +00:00
|
|
|
const translations = import.meta.glob<TranslationModule>("../locales/*.json", {
|
|
|
|
|
eager: true,
|
|
|
|
|
});
|
2025-02-07 01:59:54 +03:00
|
|
|
|
2026-02-12 19:13:53 +00:00
|
|
|
const resources: Resource = {};
|
2025-02-07 01:59:54 +03:00
|
|
|
Object.keys(translations).forEach((path) => {
|
2026-02-12 19:13:53 +00:00
|
|
|
const match = path.match(/\/([^/]+)\.json$/);
|
|
|
|
|
if (!match) return;
|
|
|
|
|
const langCode = match[1];
|
2025-02-08 18:42:39 -08:00
|
|
|
resources[langCode] = {
|
2026-02-12 19:13:53 +00:00
|
|
|
translation: translations[path].default ?? translations[path],
|
2025-02-08 18:42:39 -08:00
|
|
|
};
|
2025-02-07 01:59:54 +03:00
|
|
|
});
|
|
|
|
|
|
2025-02-08 18:42:39 -08:00
|
|
|
i18n.use(initReactI18next).init({
|
|
|
|
|
resources,
|
2025-05-30 15:03:32 -07:00
|
|
|
lng: primaryLanguage,
|
2025-02-08 18:42:39 -08:00
|
|
|
fallbackLng: primaryLanguage,
|
|
|
|
|
debug: import.meta.env.MODE === "development",
|
|
|
|
|
ns: ["translation"],
|
|
|
|
|
defaultNS: "translation",
|
|
|
|
|
interpolation: {
|
|
|
|
|
escapeValue: false,
|
|
|
|
|
},
|
2025-06-24 10:44:16 +08:00
|
|
|
returnEmptyString: false,
|
2025-02-08 18:42:39 -08:00
|
|
|
});
|
2025-02-07 01:59:54 +03:00
|
|
|
|
|
|
|
|
export default i18n;
|