genericl10n.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2018 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. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.GenericL10n = void 0;
  27. var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
  28. require("../external/webL10n/l10n");
  29. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  30. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  31. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  32. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  33. 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); } }
  34. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  35. var webL10n = document.webL10n;
  36. var GenericL10n =
  37. /*#__PURE__*/
  38. function () {
  39. function GenericL10n(lang) {
  40. _classCallCheck(this, GenericL10n);
  41. this._lang = lang;
  42. this._ready = new Promise(function (resolve, reject) {
  43. webL10n.setLanguage(lang, function () {
  44. resolve(webL10n);
  45. });
  46. });
  47. }
  48. _createClass(GenericL10n, [{
  49. key: "getLanguage",
  50. value: function () {
  51. var _getLanguage = _asyncToGenerator(
  52. /*#__PURE__*/
  53. _regenerator.default.mark(function _callee() {
  54. var l10n;
  55. return _regenerator.default.wrap(function _callee$(_context) {
  56. while (1) {
  57. switch (_context.prev = _context.next) {
  58. case 0:
  59. _context.next = 2;
  60. return this._ready;
  61. case 2:
  62. l10n = _context.sent;
  63. return _context.abrupt("return", l10n.getLanguage());
  64. case 4:
  65. case "end":
  66. return _context.stop();
  67. }
  68. }
  69. }, _callee, this);
  70. }));
  71. function getLanguage() {
  72. return _getLanguage.apply(this, arguments);
  73. }
  74. return getLanguage;
  75. }()
  76. }, {
  77. key: "getDirection",
  78. value: function () {
  79. var _getDirection = _asyncToGenerator(
  80. /*#__PURE__*/
  81. _regenerator.default.mark(function _callee2() {
  82. var l10n;
  83. return _regenerator.default.wrap(function _callee2$(_context2) {
  84. while (1) {
  85. switch (_context2.prev = _context2.next) {
  86. case 0:
  87. _context2.next = 2;
  88. return this._ready;
  89. case 2:
  90. l10n = _context2.sent;
  91. return _context2.abrupt("return", l10n.getDirection());
  92. case 4:
  93. case "end":
  94. return _context2.stop();
  95. }
  96. }
  97. }, _callee2, this);
  98. }));
  99. function getDirection() {
  100. return _getDirection.apply(this, arguments);
  101. }
  102. return getDirection;
  103. }()
  104. }, {
  105. key: "get",
  106. value: function () {
  107. var _get = _asyncToGenerator(
  108. /*#__PURE__*/
  109. _regenerator.default.mark(function _callee3(property, args, fallback) {
  110. var l10n;
  111. return _regenerator.default.wrap(function _callee3$(_context3) {
  112. while (1) {
  113. switch (_context3.prev = _context3.next) {
  114. case 0:
  115. _context3.next = 2;
  116. return this._ready;
  117. case 2:
  118. l10n = _context3.sent;
  119. return _context3.abrupt("return", l10n.get(property, args, fallback));
  120. case 4:
  121. case "end":
  122. return _context3.stop();
  123. }
  124. }
  125. }, _callee3, this);
  126. }));
  127. function get(_x, _x2, _x3) {
  128. return _get.apply(this, arguments);
  129. }
  130. return get;
  131. }()
  132. }, {
  133. key: "translate",
  134. value: function () {
  135. var _translate = _asyncToGenerator(
  136. /*#__PURE__*/
  137. _regenerator.default.mark(function _callee4(element) {
  138. var l10n;
  139. return _regenerator.default.wrap(function _callee4$(_context4) {
  140. while (1) {
  141. switch (_context4.prev = _context4.next) {
  142. case 0:
  143. _context4.next = 2;
  144. return this._ready;
  145. case 2:
  146. l10n = _context4.sent;
  147. return _context4.abrupt("return", l10n.translate(element));
  148. case 4:
  149. case "end":
  150. return _context4.stop();
  151. }
  152. }
  153. }, _callee4, this);
  154. }));
  155. function translate(_x4) {
  156. return _translate.apply(this, arguments);
  157. }
  158. return translate;
  159. }()
  160. }]);
  161. return GenericL10n;
  162. }();
  163. exports.GenericL10n = GenericL10n;