Skip to content

Commit 013f780

Browse files
ENGCOM-4073: Reverting javascript translation refactoring which broke javascript translation #20109
- Merge Pull Request #20109 from mfickers/magento2:2.3-develop - Merged commits: 1. dbf5c45 2. a185ca1
2 parents 88d0413 + a185ca1 commit 013f780

File tree

3 files changed

+42
-61
lines changed

3 files changed

+42
-61
lines changed

app/code/Magento/Translation/Block/Js.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
use Magento\Framework\View\Element\Template;
1010
use Magento\Translation\Model\Js\Config;
11-
use Magento\Framework\Escaper;
1211

1312
/**
1413
* @api

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

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,50 @@
99
/** @var \Magento\Translation\Block\Js $block */
1010
?>
1111
<?php if ($block->dictionaryEnabled()): ?>
12+
<script>
13+
require.config({
14+
deps: [
15+
'jquery',
16+
'mage/translate',
17+
'jquery/jquery-storageapi'
18+
],
19+
callback: function ($) {
20+
'use strict';
21+
22+
var dependencies = [],
23+
versionObj;
24+
25+
$.initNamespaceStorage('mage-translation-storage');
26+
$.initNamespaceStorage('mage-translation-file-version');
27+
versionObj = $.localStorage.get('mage-translation-file-version');
28+
29+
<?php $version = $block->getTranslationFileVersion(); ?>
30+
31+
if (versionObj.version !== '<?= /* @escapeNotVerified */ $block->escapeJsQuote($version) ?>') {
32+
dependencies.push(
33+
'text!<?= /* @noEscape */ Magento\Translation\Model\Js\Config::DICTIONARY_FILE_NAME ?>'
34+
);
1235

13-
<?php
14-
$version = $block->getTranslationFileVersion();
15-
$fileName = Magento\Translation\Model\Js\Config::DICTIONARY_FILE_NAME;
16-
?>
17-
<script type="text/x-magento-init">
18-
{
19-
"*": {
20-
"mage/translate-init": {
21-
"dictionaryFile": "text!<?= $block->escapeJs($fileName); ?>",
22-
"version": "<?= $block->escapeJs($version) ?>"
2336
}
37+
38+
require.config({
39+
deps: dependencies,
40+
callback: function (string) {
41+
if (typeof string === 'string') {
42+
$.mage.translate.add(JSON.parse(string));
43+
$.localStorage.set('mage-translation-storage', string);
44+
$.localStorage.set(
45+
'mage-translation-file-version',
46+
{
47+
version: '<?= /* @escapeNotVerified */ $block->escapeJsQuote($version) ?>'
48+
}
49+
);
50+
} else {
51+
$.mage.translate.add($.localStorage.get('mage-translation-storage'));
52+
}
53+
}
54+
});
2455
}
25-
}
56+
});
2657
</script>
2758
<?php endif; ?>

lib/web/mage/translate-init.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)