genericl10n.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.GenericL10n = void 0;
  27. require("../external/webL10n/l10n.js");
  28. var _l10n_utils = require("./l10n_utils.js");
  29. const webL10n = document.webL10n;
  30. class GenericL10n {
  31. constructor(lang) {
  32. this._lang = lang;
  33. this._ready = new Promise((resolve, reject) => {
  34. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  35. resolve(webL10n);
  36. });
  37. });
  38. }
  39. async getLanguage() {
  40. const l10n = await this._ready;
  41. return l10n.getLanguage();
  42. }
  43. async getDirection() {
  44. const l10n = await this._ready;
  45. return l10n.getDirection();
  46. }
  47. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  48. const l10n = await this._ready;
  49. return l10n.get(key, args, fallback);
  50. }
  51. async translate(element) {
  52. const l10n = await this._ready;
  53. return l10n.translate(element);
  54. }
  55. }
  56. exports.GenericL10n = GenericL10n;