File tree Expand file tree Collapse file tree 3 files changed +61
-42
lines changed
app/code/Magento/Translation Expand file tree Collapse file tree 3 files changed +61
-42
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 ;
11
12
12
13
/**
13
14
* @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
- );
35
12
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 ) ?> "
36
23
}
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
- });
55
24
}
56
- });
25
+ }
57
26
</script>
58
27
<?php endif ; ?>
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright © Magento, Inc. All rights reserved.
3
+ * See COPYING.txt for license details.
4
+ */
5
+
6
+ define ( [
7
+ 'jquery' ,
8
+ 'mage/translate' ,
9
+ 'jquery/jquery-storageapi'
10
+ ] , function ( $ ) {
11
+ 'use strict' ;
12
+
13
+ return function ( pageOptions ) {
14
+ var dependencies = [ ] ,
15
+ versionObj ;
16
+
17
+ $ . initNamespaceStorage ( 'mage-translation-storage' ) ;
18
+ $ . initNamespaceStorage ( 'mage-translation-file-version' ) ;
19
+ versionObj = $ . localStorage . get ( 'mage-translation-file-version' ) ;
20
+
21
+ if ( versionObj . version !== pageOptions . version ) {
22
+ dependencies . push (
23
+ pageOptions . dictionaryFile
24
+ ) ;
25
+ }
26
+
27
+ require . config ( {
28
+ deps : dependencies ,
29
+
30
+ /**
31
+ * @param {String } string
32
+ */
33
+ callback : function ( string ) {
34
+ if ( typeof string === 'string' ) {
35
+ $ . mage . translate . add ( JSON . parse ( string ) ) ;
36
+ $ . localStorage . set ( 'mage-translation-storage' , string ) ;
37
+ $ . localStorage . set (
38
+ 'mage-translation-file-version' ,
39
+ {
40
+ version : pageOptions . version
41
+ }
42
+ ) ;
43
+ } else {
44
+ $ . mage . translate . add ( $ . localStorage . get ( 'mage-translation-storage' ) ) ;
45
+ }
46
+ }
47
+ } ) ;
48
+ } ;
49
+ } ) ;
You can’t perform that action at this time.
0 commit comments