-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathtranslate.phtml
60 lines (53 loc) · 2.14 KB
/
translate.phtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/** @var \Magento\Translation\Block\Js $block */
?>
<!--
For frontend area dictionary file is inserted into html head in Magento/Translation/view/base/templates/dictionary.phtml
Same translation mechanism should be introduced for admin area in 2.4 version.
-->
<?php if ($block->dictionaryEnabled()) : ?>
<script>
require.config({
deps: [
'jquery',
'mage/translate',
'jquery/jquery-storageapi'
],
callback: function ($) {
'use strict';
var dependencies = [],
versionObj;
$.initNamespaceStorage('mage-translation-storage');
$.initNamespaceStorage('mage-translation-file-version');
versionObj = $.localStorage.get('mage-translation-file-version');
<?php $version = $block->getTranslationFileVersion(); ?>
if (versionObj.version !== '<?= $block->escapeJs($version) ?>') {
dependencies.push(
'text!<?= /* @noEscape */ Magento\Translation\Model\Js\Config::DICTIONARY_FILE_NAME ?>'
);
}
require.config({
deps: dependencies,
callback: function (string) {
if (typeof string === 'string') {
$.mage.translate.add(JSON.parse(string));
$.localStorage.set('mage-translation-storage', string);
$.localStorage.set(
'mage-translation-file-version',
{
version: '<?= $block->escapeJs($version) ?>'
}
);
} else {
$.mage.translate.add($.localStorage.get('mage-translation-storage'));
}
}
});
}
});
</script>
<?php endif; ?>