Fixes translations by re-running the loadData for its correct locale #10913
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When running
setup:static-content:deploy
with multiple languages specified, it will generate a js-translation.json. Even if the locale is set properly for each language, it will translate just based on$this->translator->getData();
in Magento\Framework\Phrase\RendererIn other words it will use the data retrieved from the
loadData
function in the Framework/Translation.phpThis uses a constructor which sets the locale;
\Magento\Framework\Locale\ResolverInterface $locale
and obviously followed by$this->_locale = $locale;
The problem here is that the loadData only gets ran once on init. It will keep using this for every other locale as 'base'. Therefore a potential locale change should also re-run the loadData.
By forcing a "rebuild" of the loadData with the correct locale, we will parse the data with the correct translations.
As extra because we are forcing the locale & rebuild we can remove the FallbackContext filler for the locale as we are setting it anyways.
Fixed Issues
Manual testing scenarios
1 Run
php bin/magento setup:static-content:deploy -f -t Magento/luma nl_NL fr_FR
2 Run
diff -rwq pub/static/frontend/Magento/luma/nl_NL/ pub/static/frontend/Magento/luma/fr_FR/
3 js-translation.json are now different from each other with the correct language translations