Skip to content

translation data load after price-box.js #7363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gabs77 opened this issue Nov 8, 2016 · 6 comments
Closed

translation data load after price-box.js #7363

gabs77 opened this issue Nov 8, 2016 · 6 comments
Labels
bug report Component: Translation Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed

Comments

@gabs77
Copy link

gabs77 commented Nov 8, 2016

Preconditions

Magento 2.1
The translation-js load after some javascript.

Steps to reproduce

  1. I override the price-box.js like following method : app/design/frontend/vendor/package/Magento_Catalog/web/js/price-box.js
  2. i add in define array the following line :
    'mage/translate'
  3. in reloaPrice function, i add the following line :
    var regexResult = $.mage.__('$1$2.$3');
    and i add in i18n file the translation
    For example :
    "$1$2.$3","my custom regex"

For debug, I edit the following file: lib/web/mage/translate.js
this.translate = function (text) { console.log(text); console.log(_data[text]); console.log(_data); return _data[text] ? _data[text] : text; };

Expected result

in console log, we have :
Translate translate.js (ligne 45) undefined translate.js (ligne 46) Object {} translate.js (ligne 47) Submit translate.js (ligne 45) undefined translate.js (ligne 46) Object {} translate.js (ligne 47) Close translate.js (ligne 45) undefined translate.js (ligne 46) Object {} translate.js (ligne 47) $1$2.$3 translate.js (ligne 45) undefined translate.js (ligne 46) Object {} translate.js (ligne 47) GET http://xxx/pub/static/frontend/vendor/package/fr_CA/js-translation.json GET http://xxx/pub/static/frontend/vendor/package/fr_CA/Magento_Ui/templates/tooltip/tooltip.html text.js (ligne 131) Select Date translate.js (ligne 45) Sélectionner une date translate.js (ligne 46) Object { Method %s does not exist on jQuery.decorate="La méthode %s n’existe p...ie dans jQuery.decorate", Close="Fermer", Please wait...="Veuillez patienter...", plus...} translate.js (ligne 47)

Actual result

Object {} must be filled with translation data before the javascript pass to reloadPrice function in price-box.js file

@OktarinTentakel
Copy link

OktarinTentakel commented Nov 15, 2016

We actually have witnessed the same behaviour, where calls to translate partly happen before translation.add and partly afterwards, resulting in completely disfunctional js-translations, partly querying empty _data objects.

The main problem seems to be the require part for translations in translation.phtml, which just tries to build data from dependencies asyncronously, but offers no real dependency chain, so that later scripts can never be sure that code has really been called already.

Just adding a name via define proves difficult, because of the dependency callback inside the outer callback. -.-

Any quick solutions for this coming to mind?

BTW: this happens in version 2.1.2

@Aldecoez
Copy link

In 2.0 sub-tree we got same bug ( we use 2.0.11 ). Translation initiation from phtml is triggered too late for many js translations used in other js files. As @OktarinTentakel said , there's no way to be sure that script inside translate.phtml is done.

@EliasKotlyar
Copy link
Contributor

EliasKotlyar commented Jun 22, 2017

Hello everyone,

We encounter the same bug. The translations are triggered from the translation.phtml file and sometimes are too late for being used in the Javascript-Code. We tried several things but found only one solution for now:

We have implemented a module, which will be loaded first before all the other modules. Its a blocking thing, but it needs to be to be "on time". This solution works by loading the translations over a synchronous ajax-call or the localstorage(depending how it needs to load). I am aware that my solution is not perfect and needs refactoring - but its working pretty good. Unfortunately i am not so much familiar with Javascript to make the whole thing asynchronous. Feel free to improve it, and maybe it will become part of the core one day.

Greetings
Elias

@EliasKotlyar
Copy link
Contributor

Hello everyone,

I made a video for the reproduction of this bug:
https://www.youtube.com/watch?v=Z1OyY4W1hCA&feature=youtu.be

I hope you can reproduce it and provide some better solution than me.

Greetings
Elias

@magento-engcom-team magento-engcom-team added 2.1.x bug report Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Component: Translation labels Sep 11, 2017
@okorshenko okorshenko added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Sep 29, 2017
@magento-engcom-team
Copy link
Contributor

@gabs77, thank you for your report.
The issue is already fixed in 2.2.0

@ameshca
Copy link

ameshca commented Aug 27, 2019

We are still getting this issue in 2.3.2 version also. Any solution for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Translation Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed
Projects
None yet
Development

No branches or pull requests

8 participants