|
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"; |
|
5 |
|
6 module.metadata = { |
|
7 "stability": "unstable" |
|
8 }; |
|
9 |
|
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) {} |
|
19 |
|
20 exports.usingJSON = usingJSON; |
|
21 |
|
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 } |
|
26 |
|
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 } |