translate.phtml 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. // @codingStandardsIgnoreFile
  7. /** @var \Magento\Translation\Block\Js $block */
  8. ?>
  9. <?php if ($block->dictionaryEnabled()): ?>
  10. <script>
  11. require.config({
  12. deps: [
  13. 'jquery',
  14. 'mage/translate',
  15. 'jquery/jquery-storageapi'
  16. ],
  17. callback: function ($) {
  18. 'use strict';
  19. var dependencies = [],
  20. versionObj;
  21. $.initNamespaceStorage('mage-translation-storage');
  22. $.initNamespaceStorage('mage-translation-file-version');
  23. versionObj = $.localStorage.get('mage-translation-file-version');
  24. <?php $version = $block->getTranslationFileVersion(); ?>
  25. if (versionObj.version !== '<?= /* @escapeNotVerified */ $block->escapeJsQuote($version) ?>') {
  26. dependencies.push(
  27. 'text!<?= /* @noEscape */ Magento\Translation\Model\Js\Config::DICTIONARY_FILE_NAME ?>'
  28. );
  29. }
  30. require.config({
  31. deps: dependencies,
  32. callback: function (string) {
  33. if (typeof string === 'string') {
  34. $.mage.translate.add(JSON.parse(string));
  35. $.localStorage.set('mage-translation-storage', string);
  36. $.localStorage.set(
  37. 'mage-translation-file-version',
  38. {
  39. version: '<?= /* @escapeNotVerified */ $block->escapeJsQuote($version) ?>'
  40. }
  41. );
  42. } else {
  43. $.mage.translate.add($.localStorage.get('mage-translation-storage'));
  44. }
  45. }
  46. });
  47. }
  48. });
  49. </script>
  50. <?php endif; ?>