You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ac-nh-turnip-prices/js/translations.js

56 lines
1.5 KiB
JavaScript

function updateContent() {
update();
5 years ago
$('body').localize();
}
5 years ago
const defaultLanguage = 'en';
i18next
.use(i18nextXHRBackend)
.use(i18nextBrowserLanguageDetector)
.init({
5 years ago
fallbackLng: defaultLanguage,
debug: true,
backend: {
loadPath: 'locales/{{lng}}.json',
},
}, (err, t) => {
const languages = [
5 years ago
['de', 'Deutsch'],
5 years ago
['en', 'English'],
['es-ES', 'Español'],
['fr', 'Français'],
['hu', 'magyar'],
['it', 'Italiano'],
['ja', '日本語'],
['ko', '한국어'],
['nl', 'Nederlands'],
['pt-BR', 'Português'],
['ru', 'Русский'],
5 years ago
['zh-CN', '简体中文'],
5 years ago
['zh-TW', '繁體中文']
].sort(),
languageSelector = $('#language');
languages.map(([code, name]) => {
languageSelector.append(`<option value="${code}"${code == i18next.language ? ' selected' : ''}>${name}</option>`);
});
5 years ago
if (!languageSelector.find('[selected]').length)
languageSelector.val(defaultLanguage);
languageSelector.on('change', function () {
if (this.value == i18next.language)
return;
i18next.changeLanguage(this.value);
});
jqueryI18next.init(i18next, $);
i18next.on('languageChanged', lng => {
if (!languageSelector.find(`[value=${lng}]`).length) {
5 years ago
i18next.changeLanguage(defaultLanguage);
return;
}
languageSelector.val(lng);
updateContent();
});
// init set content
$(document).ready(initialize);
5 years ago
$(document).on('input', updateContent);
$('input[type = radio]').on('change', updateContent);
});