L
L
lagudal2020-02-06 15:43:37
Magento
lagudal, 2020-02-06 15:43:37

Why are language variables in M2 translated normally by means of php, but not by means of js?

Such a question is ripe:
there are 2 different language locales in M2 - en and de
Many variables of their own, everything is fine if you output from the phtml template - echo __('Variable name').
Here I wanted to make a small edit with Javascript, but also to display a string depending on the locale.
There is quite a lot on the topic in Google, such a simple construction is offered

require([
'jquery', // jquery Library
'jquery/ui', // Jquery UI Library
'mage/translate' // Magento text translate (Validation message translte as per language)
], function($){
    $(window).load(function() {
        alert($.mage.__('Fast Shipping'));
    });
});

where Fast Shipping is a language variable found in the de_De.csv translation file.
But!
An interesting movie is being made. For some reason, this construction displays language variables only selectively.
Those. some are displayed with translation, and some are not, why this happens - I don’t understand, and no logic can be traced.
For example, in my example 'Fast Shipping' is displayed without translation, and Shipping - with translation, and so on - one word or line from the csv file is translated, the next one is not.
If you translate in template files, through php, everything is translated normally. And through js - through time ...
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Belevtsov, 2020-05-31
@denistrator

in the translation file de_De.csv.

title is not in the correct format. correct - de_DE.csv

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question