-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21b5729
commit e02f2bd
Showing
5 changed files
with
79 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,56 @@ | ||
import i18next from 'i18next'; | ||
import jqueryI18next from 'jquery-i18next'; | ||
import LanguageDetector from 'i18next-browser-languagedetector'; | ||
import Backend from "i18next-http-backend"; | ||
import Backend from 'i18next-http-backend'; | ||
const DETECTION_OPTIONS = { | ||
order: ['localStorage', 'navigator'], | ||
caches: ['localStorage'] | ||
order: ['localStorage', 'navigator'], | ||
caches: ['localStorage'], | ||
}; | ||
|
||
async function initI18n() { | ||
await i18next | ||
.use(LanguageDetector) | ||
.use(Backend) | ||
// detect user language | ||
// learn more: https://github.com/i18next/i18next-browser-languageDetector | ||
// init i18next | ||
// for all options read: https://www.i18next.com/overview/configuration-options | ||
.init({ | ||
debug: false, | ||
fallbackLng: 'en', | ||
load: 'languageOnly', | ||
detection: DETECTION_OPTIONS, | ||
backend: { | ||
loadPath: './localization/locales/{{lng}}/{{ns}}.json', | ||
}, | ||
interpolation: { | ||
escapeValue: false, | ||
}, | ||
}, | ||
); | ||
} | ||
jqueryI18next.init(i18next, $, { useOptionsAttr: true }); | ||
await i18next | ||
.use(LanguageDetector) | ||
.use(Backend) | ||
// detect user language | ||
// learn more: https://github.com/i18next/i18next-browser-languageDetector | ||
// init i18next | ||
// for all options read: https://www.i18next.com/overview/configuration-options | ||
.init({ | ||
debug: false, | ||
fallbackLng: 'en', | ||
load: 'languageOnly', | ||
detection: DETECTION_OPTIONS, | ||
backend: { | ||
loadPath: './localization/locales/{{lng}}/{{ns}}.json', | ||
}, | ||
interpolation: { | ||
escapeValue: false, | ||
}, | ||
}); | ||
} | ||
jqueryI18next.init(i18next, $, {useOptionsAttr: true}); | ||
function translatePage() { | ||
|
||
$(document).localize(); | ||
setTimeout(() =>{ | ||
$('.loader').hide(); | ||
$('#menuContent').removeAttr('style'); | ||
},1000) | ||
$(document).localize(); | ||
setTimeout(() => { | ||
$('.loader').hide(); | ||
$('#menuContent').removeAttr('style'); | ||
}, 1000); | ||
} | ||
|
||
function bindLocaleSwitcher() { | ||
const $switcher = $("[data-i18n-switcher]"); | ||
const $switcher = $('[data-i18n-switcher]'); | ||
|
||
$switcher.val(i18next.language); | ||
$switcher.val(i18next.language); | ||
|
||
$switcher.on("change", async function () { | ||
const chosenLng = $(this).find("option:selected").attr('value'); | ||
await i18next.changeLanguage(chosenLng); | ||
translatePage(); | ||
}); | ||
$switcher.on('change', async function () { | ||
const chosenLng = $(this).find('option:selected').attr('value'); | ||
await i18next.changeLanguage(chosenLng); | ||
translatePage(); | ||
}); | ||
} | ||
|
||
(async function () { | ||
await initI18n(); | ||
translatePage(); | ||
bindLocaleSwitcher(); | ||
})(); | ||
await initI18n(); | ||
translatePage(); | ||
bindLocaleSwitcher(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters