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

68 lines
1.8 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 = [
['ca', 'Català'],
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', '简体中文'],
['zh-TW', '繁體中文'],
['th-TH', 'ไทย'],
['pl', 'Polski'],
].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);
let delayTimer;
$(document).on('input', function() {
// adding short delay after input to help mitigate potential lag after keystrokes
clearTimeout(delayTimer);
delayTimer = setTimeout(function() {
updateContent();
}, 500);
});
5 years ago
$('input[type = radio]').on('change', updateContent);
});