2022-04-02 20:25:24 +02:00
|
|
|
import i18n from 'sveltekit-i18n';
|
|
|
|
import lang from './lang.json';
|
2022-04-03 21:47:58 +02:00
|
|
|
import * as fs from 'fs';
|
|
|
|
|
|
|
|
// Get all translations files
|
|
|
|
const loaders = [];
|
|
|
|
const translations = {};
|
|
|
|
fs.readdir('src/lib/locales/', (err, files) => {
|
|
|
|
files.forEach((file) => {
|
|
|
|
if (file.endsWith('.json')) {
|
|
|
|
const lang_iso = file.replace('.json', '');
|
|
|
|
|
|
|
|
loaders.push({
|
|
|
|
locale: file.replace('.json', ''),
|
|
|
|
key: '',
|
|
|
|
/* @vite-ignore */
|
|
|
|
loader: async () => (await import(`./locales/${lang_iso}.json`)).default
|
|
|
|
});
|
|
|
|
|
|
|
|
translations[lang_iso] = { lang };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2022-04-02 20:25:24 +02:00
|
|
|
|
|
|
|
/** @type {import('sveltekit-i18n').Config} */
|
|
|
|
const config = {
|
|
|
|
fallbackLocale: 'en',
|
2022-04-03 21:47:58 +02:00
|
|
|
translations: translations,
|
|
|
|
loaders: loaders
|
2022-04-02 20:25:24 +02:00
|
|
|
};
|
|
|
|
|
2022-04-02 21:08:55 +02:00
|
|
|
export const { t, loading, locales, locale, loadTranslations } = new i18n(config);
|
2022-04-02 20:25:24 +02:00
|
|
|
|
2022-04-02 21:08:55 +02:00
|
|
|
loading.subscribe(($loading) => $loading);
|