Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

65 righe
1.9 KiB

  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'jquery',
  7. 'mage/mage',
  8. 'mageTranslationDictionary',
  9. 'underscore'
  10. ], function ($, mage, dictionary, _) {
  11. 'use strict';
  12. $.extend(true, $, {
  13. mage: {
  14. translate: (function () {
  15. /**
  16. * Key-value translations storage
  17. * @type {Object}
  18. * @private
  19. */
  20. var _data = dictionary;
  21. return {
  22. /**
  23. * Add new translation (two string parameters) or several translations (object)
  24. */
  25. add: function () {
  26. if (arguments.length > 1) {
  27. _data[arguments[0]] = arguments[1];
  28. } else if (typeof arguments[0] === 'object') {
  29. $.extend(_data, arguments[0]);
  30. }
  31. },
  32. /**
  33. * Make a translation with parsing (to handle case when _data represents tuple)
  34. * @param {String} text
  35. * @return {String}
  36. */
  37. translate: function (text) {
  38. return typeof _data[text] !== 'undefined' ? _data[text] : text;
  39. }
  40. };
  41. }())
  42. }
  43. });
  44. $.mage.__ = $.proxy($.mage.translate.translate, $.mage.translate);
  45. // Provide i18n wrapper to be used in underscore templates for translation
  46. _.extend(_, {
  47. /**
  48. * Make a translation using $.mage.__
  49. *
  50. * @param {String} text
  51. * @return {String}
  52. */
  53. i18n: function (text) {
  54. return $.mage.__(text);
  55. }
  56. });
  57. return $.mage.__;
  58. });