Merge pull request #701 from LoekJanssen/master

Localization support added for messages
This commit is contained in:
Samuel Mannehed 2016-10-28 13:41:48 +02:00 committed by GitHub
commit e3ded092e2
5 changed files with 125 additions and 5 deletions

View File

@ -0,0 +1,13 @@
Language = {
"Connected (encrypted) to ": "Verbunden mit (verschlüsselt) ",
"Connected (unencrypted) to ": "Verbunden mit (unverschlüsselt) ",
"Must set host and port": "Richten Sie Host und Port ein",
"Disconnect timeout": "Timeout beim trennen",
"Password is required": "Passwort ist erforderlich",
"Forcing clipping mode since scrollbars aren't supported by IE in fullscreen": "'Clipping-Modus' aktiviert, Scrollbalken in 'IE-Vollbildmodus' werden nicht unterstützt",
"Connecting": "Verbunden",
"Disconnecting": "Verbindung trennen",
"Disconnected": "Verbindung zum Server getrennt",
"Invalid state": "Falscher Status",
"Unable to create RFB client -- ": "RFB Client kann nicht erstellt werden -- ",
};

View File

@ -0,0 +1,13 @@
Language = {
"Connected (encrypted) to ": "Connected (encrypted) to ",
"Connected (unencrypted) to ": "Connected (unencrypted) to ",
"Must set host and port": "Must set host and port",
"Disconnect timeout": "Disconnect timeout",
"Password is required": "Password is required",
"Forcing clipping mode since scrollbars aren't supported by IE in fullscreen": "Forcing clipping mode since scrollbars aren't supported by IE in fullscreen",
"Connecting": "Connecting",
"Disconnecting": "Disconnecting",
"Disconnected": "Disconnected",
"Invalid state": "Invalid state",
"Unable to create RFB client -- ": "Unable to create RFB client -- ",
};

View File

@ -0,0 +1,13 @@
Language = {
"Connected (encrypted) to ": "Verbonden (versleuteld) met ",
"Connected (unencrypted) to ": "Verbonden (onversleuteld) met ",
"Must set host and port": "Host en poort moeten worden ingesteld",
"Disconnect timeout": "Timeout tijdens verbreken van verbinding",
"Password is required": "Wachtwoord is vereist",
"Forcing clipping mode since scrollbars aren't supported by IE in fullscreen": "''Clipping mode' ingeschakeld, omdat schuifbalken in volledige-scherm-modus in IE niet worden ondersteund",
"Connecting": "Verbinden",
"Disconnecting": "Verbinding verbreken",
"Disconnected": "Verbinding verbroken",
"Invalid state": "Ongeldige toestand",
"Unable to create RFB client -- ": "Kan geen RFB client aanmaken -- ",
};

View File

@ -27,7 +27,7 @@ var UI;
/* [begin skip-as-module] */
// Load supporting scripts
WebUtil.load_scripts(
{'core': ["base64.js", "websock.js", "des.js", "input/keysymdef.js",
{'core': [Util.Localisation.getLanguageFileLocation(), "base64.js", "websock.js", "des.js", "input/keysymdef.js",
"input/xtscancodes.js", "input/util.js", "input/devices.js",
"display.js", "inflator.js", "rfb.js", "input/keysym.js"]});
@ -347,7 +347,7 @@ var UI;
'onDesktopName': UI.updateDesktopName});
return true;
} catch (exc) {
var msg = 'Unable to create RFB client -- ' + exc;
var msg = Util.Localisation.get("Unable to create RFB client -- ") + exc;
Util.Error(msg);
UI.showStatus(msg, 'error');
return false;
@ -369,9 +369,9 @@ var UI;
case 'connected':
UI.connected = true;
if (rfb && rfb.get_encrypt()) {
msg = "Connected (encrypted) to " + UI.desktopName;
msg = Util.Localisation.get("Connected (encrypted) to ") + UI.desktopName;
} else {
msg = "Connected (unencrypted) to " + UI.desktopName;
msg = Util.Localisation.get("Connected (unencrypted) to ") + UI.desktopName;
}
UI.showStatus(msg);
break;
@ -476,7 +476,7 @@ var UI;
break;
}
statusElem.innerHTML = text;
statusElem.innerHTML = Util.Localisation.get(text);
statusElem.classList.add("noVNC_open");
// If no time was specified, show the status for 1.5 seconds

View File

@ -366,4 +366,85 @@ Util.Flash = (function () {
return {version: parseInt(version[0] || 0 + '.' + version[1], 10) || 0, build: parseInt(version[2], 10) || 0};
}());
Util.Localisation = {
defaultLanguage: 'en-GB',
/*
* Not all languages have been translated
* Some countries prefer a certain language
*/
supportedLanguages: {
'en': 'en-GB',
'en-GB': 'en-GB',
'en-US': 'en-GB',
'nl': 'nl-NL',
'nl-NL': 'nl-NL',
'nl-BE': 'nl-NL',
'de': 'de-DE',
'de-DE': 'de-DE'
},
// Get language file location
getLanguageFileLocation: function () {
return '../app/locale/locale-'+Util.Localisation.getLanguageCode()+'.js';
},
// Get language code from browser and verify it
getLanguageCode: function () {
var languageCode = Util.Localisation.getUserPreferredLanguage();
for (var index = 0; index < languageCode.length; index++) {
var supportedLanguageCode = Util.Localisation.getSupportedLanguageCode(languageCode[index]);
if (supportedLanguageCode) {
return supportedLanguageCode;
}
}
return Util.Localisation.defaultLanguage;
},
/*
* Retrieve user preferred languages
* Navigator.languages only available in Chrome (32+) and FireFox (32+)
* Fall back to navigator.language for other browsers
*/
getUserPreferredLanguage: function () {
if (typeof window.navigator.languages == 'object') {
return window.navigator.languages;
} else {
var userLang = navigator.language || navigator.userLanguage;
return [userLang];
}
},
/*
* Verify if languagecode is supported
* Return the languagecode of the language to use or null if not available
*/
getSupportedLanguageCode: function (languageCode) {
var supportedLanguages = Util.Localisation.supportedLanguages;
for (var key in supportedLanguages) {
if (supportedLanguages.hasOwnProperty(key)) {
if (key === languageCode) {
// Return the supported language or good alternative
return supportedLanguages[key];
}
}
}
// LanguageCode not supported
return null;
},
// Retrieve localised text
get: function (id) {
if (Language[id]) {
return Language[id];
} else {
return id;
}
}
};
/* [module] export default Util; */