UNPKG

1.78 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * JavaScript code in this page
4 *
5 * Copyright 2022 Mozilla Foundation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * @licend The above is the entire license notice for the
20 * JavaScript code in this page
21 */
22"use strict";
23
24Object.defineProperty(exports, "__esModule", {
25 value: true
26});
27exports.GenericL10n = void 0;
28
29require("../external/webL10n/l10n.js");
30
31var _l10n_utils = require("./l10n_utils.js");
32
33const webL10n = document.webL10n;
34
35class GenericL10n {
36 constructor(lang) {
37 this._lang = lang;
38 this._ready = new Promise((resolve, reject) => {
39 webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
40 resolve(webL10n);
41 });
42 });
43 }
44
45 async getLanguage() {
46 const l10n = await this._ready;
47 return l10n.getLanguage();
48 }
49
50 async getDirection() {
51 const l10n = await this._ready;
52 return l10n.getDirection();
53 }
54
55 async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
56 const l10n = await this._ready;
57 return l10n.get(key, args, fallback);
58 }
59
60 async translate(element) {
61 const l10n = await this._ready;
62 return l10n.translate(element);
63 }
64
65}
66
67exports.GenericL10n = GenericL10n;
\No newline at end of file