Skip to content

Commit a846ecc

Browse files
committed
MC-19247: Broken translations with advanced bundling
- Add fake dictionary for js unit tests;
1 parent 6b9f71a commit a846ecc

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
$viewModel = $block->getData('dictionary_view_model');
99
?>
1010
<script>
11-
define('text!dictionary', function () {
12-
return "[]";
11+
define('dictionary', function () {
12+
return <?= /* @noEscape */ $viewModel->getTranslationDictionary() ?>;
1313
});
1414
</script>

dev/tests/js/jasmine/require.conf.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ require.config({
1919
'tests': '../../../../../../dev/tests/js/jasmine',
2020
'squire': '../../../../../../node_modules/squirejs/src/Squire'
2121
},
22+
map: {
23+
'*': {
24+
dictionary: '../../../../../../dev/tests/js/jasmine/tests/lib/mage/fake-dictionary'
25+
}
26+
},
2227
shim: {
2328
squire: {
2429
exports: 'squire'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
// Fake dictionary for js unit tests as real dictionary is defined is template and cannot be initialized by requirejs
6+
define([], function () {
7+
return {};
8+
});

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ define([
1414
$.mage.translate.add('Hello World!');
1515
expect('Hello World!').toEqual($.mage.translate.translate('Hello World!'));
1616
});
17+
it('works with translation alias __', function () {
18+
$.mage.translate.add('Hello World!');
19+
expect('Hello World!').toEqual($.mage.__('Hello World!'));
20+
});
1721
it('works with one array as parameter', function () {
1822
$.mage.translate.add(['Hello World!', 'Bonjour tout le monde!']);
1923
expect('Hello World!').toEqual($.mage.translate.translate('Hello World!'));
@@ -40,10 +44,6 @@ define([
4044
$.mage.translate.add('Hello World!', 'Bonjour tout le monde!');
4145
expect('Bonjour tout le monde!').toEqual($.mage.translate.translate('Hello World!'));
4246
});
43-
it('works with translation alias __', function () {
44-
$.mage.translate.add('Hello World!');
45-
expect('Hello World!').toEqual($.mage.__('Hello World!'));
46-
});
4747
});
4848

4949
});

lib/web/mage/translate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
define([
77
'jquery',
88
'mage/mage',
9-
'text!dictionary'
9+
'dictionary'
1010
], function ($, mage, dictionary) {
1111
'use strict';
1212

0 commit comments

Comments
 (0)