Skip to content

Commit d25efa8

Browse files
merge magento/2.3-develop into magento-epam/MC-18709
2 parents 4395ad8 + 71c781d commit d25efa8

File tree

11 files changed

+124
-43
lines changed

11 files changed

+124
-43
lines changed

app/code/Magento/Backend/view/adminhtml/requirejs-config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
var config = {
77
map: {
88
'*': {
9-
'mediaUploader': 'Magento_Backend/js/media-uploader'
9+
'mediaUploader': 'Magento_Backend/js/media-uploader',
10+
'mage/translate': 'Magento_Backend/js/translate'
1011
}
1112
}
1213
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/* eslint-disable strict */
7+
(function (factory) {
8+
if (typeof define === 'function' && define.amd) {
9+
define([
10+
'jquery',
11+
'mage/mage'
12+
], factory);
13+
} else {
14+
factory(jQuery);
15+
}
16+
}(function ($) {
17+
$.extend(true, $, {
18+
mage: {
19+
translate: (function () {
20+
/**
21+
* Key-value translations storage
22+
* @type {Object}
23+
* @private
24+
*/
25+
var _data = {};
26+
27+
/**
28+
* Add new translation (two string parameters) or several translations (object)
29+
*/
30+
this.add = function () {
31+
if (arguments.length > 1) {
32+
_data[arguments[0]] = arguments[1];
33+
} else if (typeof arguments[0] === 'object') {
34+
$.extend(_data, arguments[0]);
35+
}
36+
};
37+
38+
/**
39+
* Make a translation with parsing (to handle case when _data represents tuple)
40+
* @param {String} text
41+
* @return {String}
42+
*/
43+
this.translate = function (text) {
44+
return _data[text] ? _data[text] : text;
45+
};
46+
47+
return this;
48+
}())
49+
}
50+
});
51+
$.mage.__ = $.proxy($.mage.translate.translate, $.mage.translate);
52+
53+
return $.mage.__;
54+
}));

app/code/Magento/Checkout/Test/Mftf/Section/CheckoutPaymentSection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<element name="cartItemsAreaActive" type="textarea" selector="div.block.items-in-cart.active" timeout="30"/>
3232
<element name="checkMoneyOrderPayment" type="radio" selector="input#checkmo.radio" timeout="30"/>
3333
<element name="placeOrder" type="button" selector=".payment-method._active button.action.primary.checkout" timeout="30"/>
34-
<element name="paymentSectionTitle" type="text" selector="//*[@id='checkout-payment-method-load']//div[text()='Payment Method']" />
34+
<element name="paymentSectionTitle" type="text" selector="//*[@id='checkout-payment-method-load']//div[@data-role='title']" />
3535
<element name="orderSummarySubtotal" type="text" selector="//tr[@class='totals sub']//span[@class='price']" />
3636
<element name="orderSummaryShippingTotal" type="text" selector="//tr[@class='totals shipping excl']//span[@class='price']" />
3737
<element name="orderSummaryShippingMethod" type="text" selector="//tr[@class='totals shipping excl']//span[@class='value']" />

app/code/Magento/Theme/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"magento/module-widget": "*"
2020
},
2121
"suggest": {
22-
"magento/module-translation": "*",
2322
"magento/module-theme-sample-data": "*",
2423
"magento/module-deploy": "*",
2524
"magento/module-directory": "*"

app/code/Magento/Theme/view/frontend/layout/default.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
<block name="require.js" class="Magento\Framework\View\Element\Template" template="Magento_Theme::page/js/require_js.phtml" />
1212
<referenceContainer name="after.body.start">
1313
<block class="Magento\RequireJs\Block\Html\Head\Config" name="requirejs-config"/>
14-
<block class="Magento\Translation\Block\Html\Head\Config" name="translate-config"/>
15-
<block class="Magento\Translation\Block\Js" name="translate" template="Magento_Translation::translate.phtml"/>
1614
<block class="Magento\Framework\View\Element\Js\Cookie" name="js_cookies" template="Magento_Theme::js/cookie.phtml"/>
1715
<block class="Magento\Theme\Block\Html\Notices" name="global_notices" template="Magento_Theme::html/notices.phtml"/>
1816
</referenceContainer>

app/code/Magento/Translation/view/base/templates/translate.phtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
/** @var \Magento\Translation\Block\Js $block */
88
?>
9+
<!--
10+
For frontend area dictionary file is inserted into html head in Magento/Translation/view/base/templates/dictionary.phtml
11+
Same translation mechanism should be introduced for admin area in 2.4 version.
12+
-->
913
<?php if ($block->dictionaryEnabled()) : ?>
1014
<script>
1115
require.config({
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'text!js-translation.json'
8+
], function (dict) {
9+
'use strict';
10+
11+
return JSON.parse(dict);
12+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
9+
<body>
10+
<referenceBlock name="head.additional">
11+
<block class="Magento\Translation\Block\Html\Head\Config" name="translate-config"/>
12+
</referenceBlock>
13+
</body>
14+
</page>

app/code/Magento/Translation/view/frontend/requirejs-config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ var config = {
88
'*': {
99
editTrigger: 'mage/edit-trigger',
1010
addClass: 'Magento_Translation/js/add-class',
11-
'Magento_Translation/add-class': 'Magento_Translation/js/add-class'
11+
'Magento_Translation/add-class': 'Magento_Translation/js/add-class',
12+
mageTranslationDictionary: 'Magento_Translation/js/mage-translation-dictionary'
1213
}
1314
},
1415
deps: [
15-
'mage/translate-inline'
16+
'mage/translate-inline',
17+
'mageTranslationDictionary'
1618
]
1719
};

dev/tests/js/jasmine/tests/lib/mage/translate.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ define([
99
], function ($) {
1010
'use strict';
1111

12+
// be careful with test variation order as one variation can affect another one
1213
describe('Test for mage/translate jQuery plugin', function () {
1314
it('works with one string as parameter', function () {
1415
$.mage.translate.add('Hello World!');
1516
expect('Hello World!').toEqual($.mage.translate.translate('Hello World!'));
1617
});
18+
it('works with translation alias __', function () {
19+
$.mage.translate.add('Hello World!');
20+
expect('Hello World!').toEqual($.mage.__('Hello World!'));
21+
});
1722
it('works with one array as parameter', function () {
1823
$.mage.translate.add(['Hello World!', 'Bonjour tout le monde!']);
1924
expect('Hello World!').toEqual($.mage.translate.translate('Hello World!'));
@@ -40,10 +45,6 @@ define([
4045
$.mage.translate.add('Hello World!', 'Bonjour tout le monde!');
4146
expect('Bonjour tout le monde!').toEqual($.mage.translate.translate('Hello World!'));
4247
});
43-
it('works with translation alias __', function () {
44-
$.mage.translate.add('Hello World!');
45-
expect('Hello World!').toEqual($.mage.__('Hello World!'));
46-
});
4748
});
4849

4950
});

lib/web/mage/translate.js

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33
* See COPYING.txt for license details.
44
*/
55

6-
/* eslint-disable strict */
7-
(function (factory) {
8-
if (typeof define === 'function' && define.amd) {
9-
define([
10-
'jquery',
11-
'mage/mage'
12-
], factory);
13-
} else {
14-
factory(jQuery);
15-
}
16-
}(function ($) {
6+
define([
7+
'jquery',
8+
'mage/mage',
9+
'mageTranslationDictionary'
10+
], function ($, mage, dictionary) {
11+
'use strict';
12+
1713
$.extend(true, $, {
1814
mage: {
1915
translate: (function () {
@@ -22,33 +18,33 @@
2218
* @type {Object}
2319
* @private
2420
*/
25-
var _data = {};
21+
var _data = dictionary;
2622

27-
/**
28-
* Add new translation (two string parameters) or several translations (object)
29-
*/
30-
this.add = function () {
31-
if (arguments.length > 1) {
32-
_data[arguments[0]] = arguments[1];
33-
} else if (typeof arguments[0] === 'object') {
34-
$.extend(_data, arguments[0]);
35-
}
36-
};
23+
return {
24+
/**
25+
* Add new translation (two string parameters) or several translations (object)
26+
*/
27+
add: function () {
28+
if (arguments.length > 1) {
29+
_data[arguments[0]] = arguments[1];
30+
} else if (typeof arguments[0] === 'object') {
31+
$.extend(_data, arguments[0]);
32+
}
33+
},
3734

38-
/**
39-
* Make a translation with parsing (to handle case when _data represents tuple)
40-
* @param {String} text
41-
* @return {String}
42-
*/
43-
this.translate = function (text) {
44-
return _data[text] ? _data[text] : text;
35+
/**
36+
* Make a translation with parsing (to handle case when _data represents tuple)
37+
* @param {String} text
38+
* @return {String}
39+
*/
40+
translate: function (text) {
41+
return _data[text] ? _data[text] : text;
42+
}
4543
};
46-
47-
return this;
4844
}())
4945
}
5046
});
5147
$.mage.__ = $.proxy($.mage.translate.translate, $.mage.translate);
5248

5349
return $.mage.__;
54-
}));
50+
});

0 commit comments

Comments
 (0)