Skip to content

Commit 3aeaacf

Browse files
committed
MC-19247: Broken translations with advanced bundling
- Add json parse to dictionary file content in template;
1 parent c80da40 commit 3aeaacf

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
/** @var \Magento\Translation\ViewModel\Dictionary $viewModel */
88
$viewModel = $block->getData('dictionary_view_model');
9+
$dictionary = json_encode($viewModel->getTranslationDictionary(), JSON_HEX_APOS | JSON_UNESCAPED_SLASHES);
910
?>
1011
<script>
1112
define('dictionary', function () {
12-
return <?= /* @noEscape */ $viewModel->getTranslationDictionary() ?>;
13+
var dict = <?= /* @noEscape */ $dictionary ?>;
14+
// Use of JSON.parse is intentional as JSON is significantly faster to parse than JavaScript
15+
return JSON.parse(dict);
1316
});
1417
</script>

dev/tests/js/jasmine/tests/lib/mage/fake-dictionary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5-
// Fake dictionary for js unit tests as real dictionary is defined is template and cannot be initialized by requirejs
5+
// Fake dictionary for js unit tests as real dictionary is defined in template and cannot be initialized by requirejs
66
define([], function () {
77
'use strict';
88

0 commit comments

Comments
 (0)