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 1.9KB

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