UNPKG

2.77 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * Javascript code in this page
4 *
5 * Copyright 2017 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 = undefined;
28
29var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
30
31require('../external/webL10n/l10n');
32
33function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
34
35var webL10n = document.webL10n;
36
37var GenericL10n = function () {
38 function GenericL10n(lang) {
39 _classCallCheck(this, GenericL10n);
40
41 this._lang = lang;
42 this._ready = new Promise(function (resolve, reject) {
43 webL10n.setLanguage(lang, function () {
44 resolve(webL10n);
45 });
46 });
47 }
48
49 _createClass(GenericL10n, [{
50 key: 'getLanguage',
51 value: function getLanguage() {
52 return this._ready.then(function (l10n) {
53 return l10n.getLanguage();
54 });
55 }
56 }, {
57 key: 'getDirection',
58 value: function getDirection() {
59 return this._ready.then(function (l10n) {
60 return l10n.getDirection();
61 });
62 }
63 }, {
64 key: 'get',
65 value: function get(property, args, fallback) {
66 return this._ready.then(function (l10n) {
67 return l10n.get(property, args, fallback);
68 });
69 }
70 }, {
71 key: 'translate',
72 value: function translate(element) {
73 return this._ready.then(function (l10n) {
74 return l10n.translate(element);
75 });
76 }
77 }]);
78
79 return GenericL10n;
80}();
81
82exports.GenericL10n = GenericL10n;
\No newline at end of file