feat: WIP: Initial setup for i18next

This commit is contained in:
Ased Mammad 2024-03-01 08:10:36 +03:30
parent 9b86e0bb41
commit fab89a76b1
17 changed files with 180 additions and 25 deletions

30
src/lib/i18n/index.ts Normal file
View file

@ -0,0 +1,30 @@
import i18next from 'i18next';
import resourcesToBackend from 'i18next-resources-to-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
import { createI18nStore, isLoading as isLoadingStore } from './store';
i18next
.use(
resourcesToBackend((language, namespace) => import(`./locales/${language}/${namespace}.json`))
)
.use(LanguageDetector)
.init({
debug: true,
detection: {
order: ['querystring', 'localStorage', 'navigator'],
caches: ['localStorage'],
lookupQuerystring: 'lang',
lookupLocalStorage: 'locale'
},
fallbackLng: 'en',
ns: 'common',
// backend: {
// loadPath: '/locales/{{lng}}/{{ns}}.json'
// }
interpolation: {
escapeValue: false // not needed for svelte as it escapes by default
}
});
const i18n = createI18nStore(i18next);
export default i18n;
export const isLoading = isLoadingStore;