-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4848 from magento-performance/MC-19247
[Performance] Broken JS translations with advanced bundling
- Loading branch information
Showing
11 changed files
with
124 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
app/code/Magento/Backend/view/adminhtml/web/js/translate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
/* eslint-disable strict */ | ||
(function (factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
define([ | ||
'jquery', | ||
'mage/mage' | ||
], factory); | ||
} else { | ||
factory(jQuery); | ||
} | ||
}(function ($) { | ||
$.extend(true, $, { | ||
mage: { | ||
translate: (function () { | ||
/** | ||
* Key-value translations storage | ||
* @type {Object} | ||
* @private | ||
*/ | ||
var _data = {}; | ||
|
||
/** | ||
* Add new translation (two string parameters) or several translations (object) | ||
*/ | ||
this.add = function () { | ||
if (arguments.length > 1) { | ||
_data[arguments[0]] = arguments[1]; | ||
} else if (typeof arguments[0] === 'object') { | ||
$.extend(_data, arguments[0]); | ||
} | ||
}; | ||
|
||
/** | ||
* Make a translation with parsing (to handle case when _data represents tuple) | ||
* @param {String} text | ||
* @return {String} | ||
*/ | ||
this.translate = function (text) { | ||
return _data[text] ? _data[text] : text; | ||
}; | ||
|
||
return this; | ||
}()) | ||
} | ||
}); | ||
$.mage.__ = $.proxy($.mage.translate.translate, $.mage.translate); | ||
|
||
return $.mage.__; | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/code/Magento/Translation/view/base/web/js/mage-translation-dictionary.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
define([ | ||
'text!js-translation.json' | ||
], function (dict) { | ||
'use strict'; | ||
|
||
return JSON.parse(dict); | ||
}); |
14 changes: 14 additions & 0 deletions
14
app/code/Magento/Translation/view/frontend/layout/default.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceBlock name="head.additional"> | ||
<block class="Magento\Translation\Block\Html\Head\Config" name="translate-config"/> | ||
</referenceBlock> | ||
</body> | ||
</page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters