File tree Expand file tree Collapse file tree 3 files changed +42
-61
lines changed
app/code/Magento/Translation Expand file tree Collapse file tree 3 files changed +42
-61
lines changed Original file line number Diff line number Diff line change 8
8
9
9
use Magento \Framework \View \Element \Template ;
10
10
use Magento \Translation \Model \Js \Config ;
11
- use Magento \Framework \Escaper ;
12
11
13
12
/**
14
13
* @api
Original file line number Diff line number Diff line change 9
9
/** @var \Magento\Translation\Block\Js $block */
10
10
?>
11
11
<?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
+ );
12
35
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 ) ?> "
23
36
}
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
+ });
24
55
}
25
- }
56
+ });
26
57
</script>
27
58
<?php endif ; ?>
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments