Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

49 linhas
1.4 KiB

  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. /* eslint-disable strict */
  6. define([
  7. 'jquery',
  8. 'mage/mage'
  9. ], function ($) {
  10. $.extend(true, $, {
  11. mage: {
  12. translate: (function () {
  13. /**
  14. * Key-value translations storage
  15. * @type {Object}
  16. * @private
  17. */
  18. var _data = {};
  19. /**
  20. * Add new translation (two string parameters) or several translations (object)
  21. */
  22. this.add = function () {
  23. if (arguments.length > 1) {
  24. _data[arguments[0]] = arguments[1];
  25. } else if (typeof arguments[0] === 'object') {
  26. $.extend(_data, arguments[0]);
  27. }
  28. };
  29. /**
  30. * Make a translation with parsing (to handle case when _data represents tuple)
  31. * @param {String} text
  32. * @return {String}
  33. */
  34. this.translate = function (text) {
  35. return typeof _data[text] === 'string' ? _data[text] : text;
  36. };
  37. return this;
  38. }())
  39. }
  40. });
  41. $.mage.__ = $.proxy($.mage.translate.translate, $.mage.translate);
  42. return $.mage.__;
  43. });