addon-sdk/source/lib/sdk/l10n/json/core.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/lib/sdk/l10n/json/core.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,35 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 + "use strict";
     1.8 +
     1.9 +module.metadata = {
    1.10 +  "stability": "unstable"
    1.11 +};
    1.12 +
    1.13 +let usingJSON = false;
    1.14 +let hash = {}, bestMatchingLocale = null;
    1.15 +try {
    1.16 +  let data = require("@l10n/data");
    1.17 +  hash = data.hash;
    1.18 +  bestMatchingLocale = data.bestMatchingLocale;
    1.19 +  usingJSON = true;
    1.20 +}
    1.21 +catch(e) {}
    1.22 +
    1.23 +exports.usingJSON = usingJSON;
    1.24 +
    1.25 +// Returns the translation for a given key, if available.
    1.26 +exports.get = function get(k) {
    1.27 +  return k in hash ? hash[k] : null;
    1.28 +}
    1.29 +
    1.30 +// Returns the full length locale code: ja-JP-mac, en-US or fr
    1.31 +exports.locale = function locale() {
    1.32 +  return bestMatchingLocale;
    1.33 +}
    1.34 +// Returns the short locale code: ja, en, fr
    1.35 +exports.language = function language() {
    1.36 +  return bestMatchingLocale ? bestMatchingLocale.split("-")[0].toLowerCase()
    1.37 +                            : null;
    1.38 +}

mercurial