🌐 Added i18next

This commit is contained in:
Mawoka
2022-03-25 18:23:41 +01:00
parent 326780c8d7
commit 8f8e152c32
16 changed files with 4457 additions and 2495 deletions
+46
View File
@@ -0,0 +1,46 @@
import i18next from 'i18next';
import translations from './translations';
import en from './locales/en.json';
import type { i18n, Resource } from 'i18next';
const INITIAL_LANGUAGE = 'en';
export class I18nService {
// expose i18next
i18n: i18n;
constructor() {
this.i18n = i18next;
this.initialize();
this.changeLanguage(INITIAL_LANGUAGE);
}
// Our translation function
t(key: string, replacements?: Record<string, unknown>): string {
return this.i18n.t(key, replacements);
}
// Initializing i18n
initialize() {
this.i18n.init({
lng: INITIAL_LANGUAGE,
fallbackLng: 'en',
debug: false,
defaultNS: 'translation',
fallbackNS: 'common',
resources: translations as Resource,
interpolation: {
escapeValue: false
},
detection: {
order: ['querystring', 'navigator'],
lookupQuerystring: 'lng'
}
});
this.i18n.addResourceBundle('en', 'translation', en);
}
changeLanguage(language: string) {
this.i18n.changeLanguage(language);
}
}