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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     4  "use strict";
     6 module.metadata = {
     7   "stability": "unstable"
     8 };
    10 let usingJSON = false;
    11 let hash = {}, bestMatchingLocale = null;
    12 try {
    13   let data = require("@l10n/data");
    14   hash = data.hash;
    15   bestMatchingLocale = data.bestMatchingLocale;
    16   usingJSON = true;
    17 }
    18 catch(e) {}
    20 exports.usingJSON = usingJSON;
    22 // Returns the translation for a given key, if available.
    23 exports.get = function get(k) {
    24   return k in hash ? hash[k] : null;
    25 }
    27 // Returns the full length locale code: ja-JP-mac, en-US or fr
    28 exports.locale = function locale() {
    29   return bestMatchingLocale;
    30 }
    31 // Returns the short locale code: ja, en, fr
    32 exports.language = function language() {
    33   return bestMatchingLocale ? bestMatchingLocale.split("-")[0].toLowerCase()
    34                             : null;
    35 }

mercurial