UNPKG

@qooxdoo/framework

Version:

The JS Framework for Coders

114 lines (94 loc) 3.21 kB
/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: MIT: https://opensource.org/licenses/MIT See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Martin Wittemann (martinwittemann) ************************************************************************ */ /** * This class comes with all relevant information regarding * the client's selected locale. * * This class is used by {@link qx.core.Environment} and should not be used * directly. Please check its class comment for details how to use it. * * @internal * @require(qx.bom.client.OperatingSystem) */ qx.Bootstrap.define("qx.bom.client.Locale", { /* ***************************************************************************** STATICS ***************************************************************************** */ statics: { /** * The name of the system locale e.g. "de" when the full locale is "de_AT" * @return {String} The current locale * @internal */ getLocale() { var locale = qx.bom.client.Locale.__getNavigatorLocale(); var index = locale.indexOf("-"); if (index != -1) { locale = locale.substr(0, index); } return locale; }, /** * The name of the variant for the system locale e.g. "at" when the * full locale is "de_AT" * * @return {String} The locales variant. * @internal */ getVariant() { var locale = qx.bom.client.Locale.__getNavigatorLocale(); var variant = ""; var index = locale.indexOf("-"); if (index != -1) { variant = locale.substr(index + 1); } return variant; }, /** * Internal helper for accessing the navigators language. * * @return {String} The language set by the navigator. */ __getNavigatorLocale() { var locale = navigator.userLanguage || navigator.language || ""; // Android Bug: Android does not return the system language from the // navigator language before version 4.4.x. Try to parse the language // from the userAgent. // See http://code.google.com/p/android/issues/detail?id=4641 if (qx.bom.client.OperatingSystem.getName() == "android") { var version = /^(\d+)\.(\d+)(\..+)?/i.exec( qx.bom.client.OperatingSystem.getVersion() ); if (qx.lang.Type.isArray(version) && version.length >= 3) { if ( parseInt(version[1]) < 4 || (parseInt(version[1]) === 4 && parseInt(version[2]) < 4) ) { var match = /(\w{2})-(\w{2})/i.exec(navigator.userAgent); if (match) { locale = match[0]; } } } } return locale.toLowerCase(); } }, defer(statics) { qx.core.Environment.add("locale", statics.getLocale); qx.core.Environment.add("locale.variant", statics.getVariant); qx.core.Environment.add("locale.default", "C"); } });