mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Refactor i18n language loading
This commit is contained in:
parent
1311fcdada
commit
3cf9d2d597
@ -5,8 +5,8 @@
|
||||
"InfoDialog_changePassword_title": "Change Password",
|
||||
"InfoDialog_iswitch_text": "If you run Hyperion more than once in your local network, you could switch between the web configurations. Select the Hyperion instance below and switch!",
|
||||
"InfoDialog_iswitch_title": "Hyperion switcher",
|
||||
"InfoDialog_lang_text": "If you don't like the result of the automatic language detection you could overwrite it here.",
|
||||
"InfoDialog_lang_title": "Language setting",
|
||||
"InfoDialog_nostorage_text": "Your browser does not support localStorage. You cannot save a specific language setting (fallback to 'auto detection') and access level (fallback to 'default'). Some wizards may be hidden. You could still use the webinterface without further issues",
|
||||
"InfoDialog_nostorage_title": "Cannot store settings",
|
||||
"InfoDialog_nowrite_foottext": "The WebUI will be unlocked automatically after you solved the problem!",
|
||||
"InfoDialog_nowrite_text": "Hyperion can't write to your current loaded configuration file. Please repair the file permissions to proceed.",
|
||||
"InfoDialog_nowrite_title": "write permission error!",
|
||||
|
@ -51,6 +51,8 @@
|
||||
<script src="js/lib/jquery.i18n/jquery.i18n.language.js"></script>
|
||||
<script src="js/lib/jquery.i18n/CLDRPluralRuleParser.js"></script>
|
||||
|
||||
<script src="js/languages.js"></script>
|
||||
|
||||
<!-- Bootstrap Core CSS -->
|
||||
<link href="css/bootstrap.min.css" rel="stylesheet">
|
||||
|
||||
@ -82,7 +84,6 @@
|
||||
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<noscript>
|
||||
<div style="color:red;margin: 40px 0;text-align:center">
|
||||
|
33
assets/webconfig/js/languages.js
Normal file
33
assets/webconfig/js/languages.js
Normal file
@ -0,0 +1,33 @@
|
||||
var storedLang;
|
||||
var availLang = ['cs', 'de', 'en', 'es', 'fr', 'it', 'nl', 'nb', 'pl', 'pt', 'ro', 'sv', 'vi', 'ru', 'tr', 'zh-CN'];
|
||||
var availLangText = ['Čeština', 'Deutsch', 'English', 'Español', 'Français', 'Italiano', 'Nederlands', 'Norsk Bokmål', 'Polski', 'Português', 'Română', 'Svenska', 'Tiếng Việt', 'русский', 'Türkçe', '汉语'];
|
||||
|
||||
//$.i18n.debug = true;
|
||||
|
||||
//i18n
|
||||
function initTrans(lc) {
|
||||
$.i18n().load("i18n", lc).done(
|
||||
function () {
|
||||
$.i18n().locale = lc;
|
||||
performTranslation();
|
||||
});
|
||||
}
|
||||
|
||||
storedLang = getStorage("langcode");
|
||||
if (storedLang == null || storedLang === "undefined") {
|
||||
|
||||
var langLocale = $.i18n().locale.substring(0, 2);
|
||||
//Test, if language is supported by hyperion
|
||||
var langIdx = availLang.indexOf(langLocale);
|
||||
if (langIdx === -1) {
|
||||
// If language is not supported by hyperion, try fallback language
|
||||
langLocale = $.i18n().options.fallbackLocale.substring(0, 2);
|
||||
langIdx = availLang.indexOf(langLocale);
|
||||
if (langIdx === -1) {
|
||||
langLocale = 'en';
|
||||
}
|
||||
}
|
||||
storedLang = langLocale;
|
||||
setStorage("langcode", storedLang);
|
||||
}
|
||||
initTrans(storedLang);
|
@ -1,10 +1,5 @@
|
||||
var storedAccess;
|
||||
var storedLang;
|
||||
var availLang = ['cs', 'de', 'en', 'es', 'fr', 'it', 'nl', 'nb', 'pl', 'pt', 'ro', 'sv', 'vi', 'ru', 'tr', 'zh-CN'];
|
||||
var availLangText = ['Čeština', 'Deutsch', 'English', 'Español', 'Français', 'Italiano', 'Nederlands', 'Norsk Bokmål', 'Polski', 'Português', 'Română', 'Svenska', 'Tiếng Việt', 'русский', 'Türkçe', '汉语'];
|
||||
var availAccess = ['default', 'advanced', 'expert'];
|
||||
|
||||
//$.i18n.debug = true;
|
||||
var storedAccess;
|
||||
|
||||
//Change Password
|
||||
function changePassword(){
|
||||
@ -28,46 +23,9 @@ function changePassword(){
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
//i18n
|
||||
function initTrans(lc){
|
||||
if (lc == 'auto')
|
||||
{
|
||||
$.i18n().load().done(
|
||||
function() {
|
||||
performTranslation();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
$.i18n().locale = lc;
|
||||
$.i18n().load( "i18n", lc ).done(
|
||||
function() {
|
||||
performTranslation();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (storageComp())
|
||||
{
|
||||
storedLang = getStorage("langcode");
|
||||
if (storedLang == null)
|
||||
{
|
||||
setStorage("langcode", 'auto');
|
||||
storedLang = 'auto';
|
||||
initTrans(storedLang);
|
||||
}
|
||||
else
|
||||
{
|
||||
initTrans(storedLang);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!storageComp()) {
|
||||
showInfoDialog('warning', "Can't store settings", "Your browser doesn't support localStorage. You can't save a specific language setting (fallback to 'auto detection') and access level (fallback to 'default'). Some wizards may be hidden. You could still use the webinterface without further issues");
|
||||
initTrans('auto');
|
||||
storedLang = 'auto';
|
||||
storedAccess = "default";
|
||||
$('#btn_setlang').attr("disabled", true);
|
||||
$('#language-select').attr("disabled", true);
|
||||
$('#btn_setaccess').attr("disabled", true);
|
||||
}
|
||||
|
||||
@ -75,10 +33,14 @@ $(document).ready( function() {
|
||||
|
||||
//access
|
||||
storedAccess = getStorage("accesslevel");
|
||||
if (storedAccess == null)
|
||||
{
|
||||
setStorage("accesslevel", "default");
|
||||
if (storedAccess == null) {
|
||||
storedAccess = "default";
|
||||
setStorage("accesslevel", storedAccess);
|
||||
}
|
||||
|
||||
if (!storageComp()) {
|
||||
showInfoDialog('warning', $.i18n('InfoDialog_nostorage_title'), $.i18n('InfoDialog_nostorage_text'));
|
||||
$('#btn_setlang').attr("disabled", true);
|
||||
}
|
||||
|
||||
$('#btn_setaccess').off().on('click',function() {
|
||||
|
@ -162,25 +162,22 @@ function initLanguageSelection() {
|
||||
|
||||
var langLocale = storedLang;
|
||||
|
||||
// If no language has been set, resolve browser locale
|
||||
if (langLocale === 'auto') {
|
||||
langLocale = $.i18n().locale.substring(0, 2);
|
||||
}
|
||||
|
||||
// Resolve text for language code
|
||||
var langText = 'Please Select';
|
||||
|
||||
//Test, if language is supported by hyperion
|
||||
var langIdx = availLang.indexOf(langLocale);
|
||||
if (langIdx > -1) {
|
||||
langText = availLangText[langIdx];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// If language is not supported by hyperion, try fallback language
|
||||
langLocale = $.i18n().options.fallbackLocale.substring(0, 2);
|
||||
langIdx = availLang.indexOf(langLocale);
|
||||
if (langIdx > -1) {
|
||||
langText = availLangText[langIdx];
|
||||
} else {
|
||||
langLocale = 'en';
|
||||
langIdx = availLang.indexOf(langLocale);
|
||||
if (langIdx > -1) {
|
||||
langText = availLangText[langIdx];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user