Magento2: mage/translate - window context / checkout missing translations

Created on 13 Dec 2018  路  6Comments  路  Source: magento/magento2

Summary (*

In every Magento 2.x version I had the problem that sometimes the translations in the checkout were missing .. but after pressing STRG+F5 they are suddenly correct.

After some digging I found out that there is a conflict between mage/translate and the wirecard datastorage js. The problem is that both files have a function called "add". Both files have this function i the context of a function where this is window.

Examples (*)

$:mage.translate.add() is the same as window.add()

And since wirecard is using the same approach .. the module overrides the window.add().

I think mage/translate should has it's own context. Here is the version I am using right now to fix this.

Proposed solution

/**
 * 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 ($) {
    /**
     * Key-value translations storage
     * @type {Object}
     * @private
     */
    var _data = {};

    $.extend(true, $, {
        mage: {
            translate: {
                /**
                 * Add new translation (two string parameters) or several translations (object)
                 */
                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}
                 */
                translate: function (text) {
                    return _data[text] ? _data[text] : text;
                }
            }
        }
    });
    $.mage.__ = $.proxy($.mage.translate.translate, $.mage.translate);

    return $.mage.__;
}));

Translation Clear Description Confirmed Format is valid Ready for Work Reproduced on 2.2.x Reproduced on 2.3.x help wanted

Most helpful comment

@engcom-backlog-nazar Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-97148, MAGETWO-97149 were created

All 6 comments

Hi @mvenghaus. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me $VERSION instance

where $VERSION is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop).
For more details, please, review the Magento Contributor Assistant documentation.

@mvenghaus do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 6. Add label Issue: Confirmed once verification is complete.

  • [ ] 7. Make sure that automatic system confirms that report has been added to the backlog.

HI @mvenghaus thank you for you report, wirecard
the GitHub issue tracker is intended for Magento Core technical issues only.
Please refer to the Community Forums or the Magento Stack Exchange site for advice or general discussion about this issue.

@engcom-backlog-nazar i know, but the problem is caused because of the wrong context of mage/translate. I think it's s.th. you should optimize. If you google this type of error there are a lot of people who have this problem with different 3rd party modules.

mage/translate lives in the context of window:
window.add()
window.translate()

It should only live in:
$.mage.translate.XXX

image

@engcom-backlog-nazar Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-97148, MAGETWO-97149 were created

@mvenghaus, thank you for your report.

Unfortunately, we are archiving this ticket now as it did not get much attention from both Magento Community and Core developers for an extended period. This is done in an effort to create a quality, community-driven backlog which will allow us to allocate the required attention more easily.

Please feel free to comment, reopen or create new ticket according to the Issue reporting guidelines
if you are still facing this issue on the latest 2.3-develop branch. Thank you for collaboration.

Was this page helpful?
0 / 5 - 0 ratings