Rework how to import and adding new translations.
This commit is contained in:
parent
a3904c626b
commit
f6209b119d
|
@ -1,20 +1,8 @@
|
|||
import translation_en from './src/translations/en.js'
|
||||
import translation_de from './src/translations/de.js'
|
||||
import translation_ru from './src/translations/ru.js'
|
||||
import translation_nl from './src/translations/nl.js'
|
||||
import translation_fr from './src/translations/fr.js'
|
||||
import translations from './src/translations/index.mjs'
|
||||
|
||||
const langs = ["en", "de", "ru", "nl", "fr"];
|
||||
const langs = Object.getOwnPropertyNames(translations);
|
||||
|
||||
const translations_dict = {
|
||||
en: translation_en,
|
||||
de: translation_de,
|
||||
ru: translation_ru,
|
||||
nl: translation_nl,
|
||||
fr: translation_fr,
|
||||
}
|
||||
|
||||
let en_keys = [...new Map(Object.entries(translations_dict.en)).keys()];
|
||||
let en_keys = [...new Map(Object.entries(translations.en)).keys()];
|
||||
|
||||
function arrayDiff(a, b) {
|
||||
return {
|
||||
|
@ -24,7 +12,7 @@ function arrayDiff(a, b) {
|
|||
}
|
||||
|
||||
for (let lang_num in langs) {
|
||||
let lang = new Map(Object.entries(translations_dict[langs[lang_num]]));
|
||||
let lang = new Map(Object.entries(translations[langs[lang_num]]));
|
||||
if (lang == "en") continue;
|
||||
let lang_keys = [...lang.keys()];
|
||||
let di = arrayDiff(en_keys, [...lang.keys()])
|
||||
|
|
17
src/main.js
17
src/main.js
|
@ -68,14 +68,9 @@ const pages = {
|
|||
};
|
||||
|
||||
// Translations
|
||||
import {formatDistance} from './formatDistance.js';
|
||||
import { formatDistance } from './formatDistance.js';
|
||||
import i18next from 'i18next';
|
||||
import translation_de from './translations/de.js'
|
||||
import translation_en from './translations/en.js'
|
||||
import translation_fr from './translations/fr.js'
|
||||
import translation_nl from './translations/nl.js'
|
||||
import translation_ru from './translations/ru.js'
|
||||
|
||||
import translations from './translations/index.mjs'
|
||||
|
||||
/*import "en-GB" as date_locale_en from 'date-fns/locale'
|
||||
|
||||
|
@ -188,13 +183,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||
lng: pageState.language,
|
||||
fallbackLng: 'en',
|
||||
debug: true,
|
||||
resources: {
|
||||
en: { translation: translation_en },
|
||||
de: { translation: translation_de },
|
||||
ru: { translation: translation_ru },
|
||||
nl: { translation: translation_nl },
|
||||
fr: { translation: translation_fr },
|
||||
},
|
||||
resources: Object.fromEntries(Object.entries(translations).map(([k, v]) => [k, { translation: v }])),
|
||||
interpolation: {
|
||||
format: function (value, format, _) {
|
||||
if (format === 'until_date' && value instanceof Date) return formatDistance(new Date(), new Date(value));
|
||||
|
|
|
@ -3,8 +3,9 @@ import { Page } from "../types/Page.js";
|
|||
import { changePage, setPageContent } from "../pageUtils.js";
|
||||
import { makeElement } from "../htmlUtils.js";
|
||||
import i18next from 'i18next';
|
||||
import translations from "../translations/index.mjs";
|
||||
|
||||
let languages = ["en", "de", "nl", "ru", "fr"];
|
||||
let languageIDs = Object.getOwnPropertyNames(translations);
|
||||
|
||||
export class SetLanguagePage extends Page {
|
||||
constructor() {
|
||||
|
@ -21,7 +22,7 @@ export class SetLanguagePage extends Page {
|
|||
attributes: {
|
||||
name: "language"
|
||||
},
|
||||
children: languages.map(function (languageID) {
|
||||
children: languageIDs.map(function (languageID) {
|
||||
return makeElement({
|
||||
tag: "option",
|
||||
text: i18next.getFixedT(languageID, null)("language_name"),
|
||||
|
|
15
src/translations/index.mjs
Normal file
15
src/translations/index.mjs
Normal file
|
@ -0,0 +1,15 @@
|
|||
import de from './de.js'
|
||||
import en from './en.js'
|
||||
import fr from './fr.js'
|
||||
import nl from './nl.js'
|
||||
import ru from './ru.js'
|
||||
|
||||
const translations = {
|
||||
de: de,
|
||||
en: en,
|
||||
fr: fr,
|
||||
nl: nl,
|
||||
ru: ru,
|
||||
}
|
||||
|
||||
export default translations;
|
Loading…
Reference in a new issue