Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 47 additions & 33 deletions app/code/Magento/Translation/view/base/templates/translate.phtml
Original file line number Diff line number Diff line change
@@ -1,58 +1,72 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

/** @var \Magento\Translation\Block\Js $block */
?>
<?php /** @var $block \Magento\Translation\Block\Js */ ?>
<?php if ($block->dictionaryEnabled()): ?>
<script>
require.config({
deps: [
config: {
'mage/advancedtranslate': {
currentVersion: '<?php echo sha1($block->getTranslationFileTimestamp() . $block->getTranslationFilePath()) ?>',
dictFile: '<?php echo Magento\Translation\Model\Js\Config::DICTIONARY_FILE_NAME; ?>'
}
}
});
define("mage/advancedtranslate",
[
'jquery',
'mage/translate',
'jquery/jquery-storageapi'
'jquery/jquery-storageapi',
'module'
],
callback: function ($) {
'use strict';

var dependencies = [],
versionObj;
function ($, translate, storageApi, module) {
console.log("Started Advancedtranslate...");
var versionObj;

$.initNamespaceStorage('mage-translation-storage');
$.initNamespaceStorage('mage-translation-file-version');
versionObj = $.localStorage.get('mage-translation-file-version');

<?php $version = sha1($block->getTranslationFileTimestamp() . $block->getTranslationFilePath()); ?>
var text = null;
// Comment out for fetching all translations only over AJAX and not over LocalStorage
//versionObj.version = null;
if (versionObj.version !== module.config().currentVersion) {
var url = require.toUrl(module.config().dictFile);
console.log("Mismatch of Versions...");
console.log("Getting the Data from " + url);
text = $.ajax({
type: "GET",
url: url,
cache: false,
async: false
}).responseText;
//console.log(text);
}

if (versionObj.version !== '<?php /* @noEscape */ echo $version ?>') {
dependencies.push(
'text!<?php /* @noEscape */ echo Magento\Translation\Model\Js\Config::DICTIONARY_FILE_NAME ?>'
);

}
if (typeof text === 'string') {

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: '<?php /* @noEscape */ echo $version ?>'
}
);
} else {
$.mage.translate.add($.localStorage.get('mage-translation-storage'));
$.mage.translate.add(JSON.parse(text));
$.localStorage.set('mage-translation-storage', text);
$.localStorage.set(
'mage-translation-file-version',
{
version: module.config().currentVersion
}
}
});
);
} else {
$.mage.translate.add($.localStorage.get('mage-translation-storage'));
}
}
);

require(['mage/advancedtranslate'], function () {

});

</script>
<?php endif; ?>