genericl10n.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. Object.defineProperty(exports, "__esModule", {
  17. value: true
  18. });
  19. exports.GenericL10n = undefined;
  20. var _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; }; }();
  21. require('../external/webL10n/l10n');
  22. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  23. var webL10n = document.webL10n;
  24. var GenericL10n = function () {
  25. function GenericL10n(lang) {
  26. _classCallCheck(this, GenericL10n);
  27. this._lang = lang;
  28. this._ready = new Promise(function (resolve, reject) {
  29. webL10n.setLanguage(lang, function () {
  30. resolve(webL10n);
  31. });
  32. });
  33. }
  34. _createClass(GenericL10n, [{
  35. key: 'getDirection',
  36. value: function getDirection() {
  37. return this._ready.then(function (l10n) {
  38. return l10n.getDirection();
  39. });
  40. }
  41. }, {
  42. key: 'get',
  43. value: function get(property, args, fallback) {
  44. return this._ready.then(function (l10n) {
  45. return l10n.get(property, args, fallback);
  46. });
  47. }
  48. }, {
  49. key: 'translate',
  50. value: function translate(element) {
  51. return this._ready.then(function (l10n) {
  52. return l10n.translate(element);
  53. });
  54. }
  55. }]);
  56. return GenericL10n;
  57. }();
  58. exports.GenericL10n = GenericL10n;