Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lang.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = lang;
  6. var _en = require('../../../locale/en');
  7. var _en2 = _interopRequireDefault(_en);
  8. var _helpers = require('../../../util/helpers');
  9. var _console = require('../../../util/console');
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  12. var LANG_PREFIX = '$vuetify.';
  13. var fallback = Symbol('Lang fallback');
  14. function getTranslation(locale, key) {
  15. var usingFallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  16. var shortKey = key.replace(LANG_PREFIX, '');
  17. var translation = (0, _helpers.getObjectValueByPath)(locale, shortKey, fallback);
  18. if (translation === fallback) {
  19. if (usingFallback) {
  20. (0, _console.consoleError)('Translation key "' + shortKey + '" not found in fallback');
  21. translation = key;
  22. } else {
  23. (0, _console.consoleWarn)('Translation key "' + shortKey + '" not found, falling back to default');
  24. translation = getTranslation(_en2.default, key, true);
  25. }
  26. }
  27. return translation;
  28. }
  29. function lang() {
  30. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  31. return {
  32. locales: Object.assign({ en: _en2.default }, config.locales),
  33. current: config.current || 'en',
  34. t: function t(key) {
  35. for (var _len = arguments.length, params = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  36. params[_key - 1] = arguments[_key];
  37. }
  38. if (!key.startsWith(LANG_PREFIX)) return key;
  39. if (config.t) return config.t.apply(config, [key].concat(_toConsumableArray(params)));
  40. var translation = getTranslation(this.locales[this.current], key);
  41. return translation.replace(/\{(\d+)\}/g, function (match, index) {
  42. return String(params[+index]);
  43. });
  44. }
  45. };
  46. }
  47. //# sourceMappingURL=lang.js.map