Skip to main content
43 votes
Accepted

Magento2 translating Javascript (KO) template text

So I was finally able to figure out the problem. Seems that the JS template translation are read from js-translation.json which is generated during setup:static-content:deploy execution. In order to ...
Atish Goswami's user avatar
13 votes

How to translate JS error message or text in Magento 2?

This worked for me: define( [ 'mage/translate' ], function ( $tr ) { $tr('<your text>'), } );
Sharfaraz Bheda's user avatar
11 votes

How to translate JS error message or text in Magento 2?

Additional note: if you need to include some variable to translation (in js), you can use this: $.mage.__('Hello %1').replace('%1', yourVariable);
Roman Snitko's user avatar
7 votes
Accepted

Magento 2: Translate input placeholder attribute string in Knockout html template

You can write like this <input type="text" data-bind="attr:{placeholder: $t('Email')} " /> Run below commands php bin/magento setup:upgrade php bin/magento setup:static-content:deploy php ...
Suresh Chikani's user avatar
5 votes

Magento 2 translate the "You added ... to your shopping cart." line

if you are using following line in i18n on theme as translation source "You added %1 to your shopping cart." then change it to "You added %1 to your <a href=""%2"&...
Shuvankar Paul's user avatar
5 votes
Accepted

How to properly translate strings in JavaScript

Write your strings to be translated like so: $.mage.__('Foobar') $('.readmorebutton').click(function() { if (! $('.readmore').hasClass('open') ) { $('.readmorebutton').text($.mage.__('...
Eamonn's user avatar
  • 508
4 votes
Accepted

Javascript translation not working properly

Best approach for this would be to use 'domReady!' in your define to make sure document is fully loaded once translation is applied. define([ 'jquery', 'underscore', 'domReady!' ], ...
Magarusu's user avatar
  • 357
4 votes
Accepted

Magento 2 : the JS messages do not translated!

1) magento 2.0.5 (test - true) lib/web/mage/validation.js line 246 : replace : 'Please enter a valid email address (Ex: [email protected]).' $.mage.__('Please enter a valid email address (Ex: ...
Wise Ltd.'s user avatar
  • 101
4 votes
Accepted

The "i18n:collect-phrases" command does not collect all translatable strings from JS

Magento 2 use the \Magento\Setup\Module\I18n\Parser\Adapter\Js::_parse() method to collect all translatable lines (strings) from a files. It will open all js files one-by-one and read each line of ...
Siarhey Uchukhlebau's user avatar
4 votes
Accepted

js-translation.json fails to generated

Use this command : Please set Vendor= Your vendor name and Theme= Your theme name for frontend php bin/magento setup:static-content:deploy --theme=Vendor/Theme en_US php bin/magento setup:static-...
Jugal Kishor's user avatar
  • 1,225
4 votes

Magento 2 translate the "You added ... to your shopping cart." line

I have actually managed to find the solution myself, the right file to edit is: "vendor/magento/module-checkout/view/frontend/templates/messages/addCartSuccessMessage.phtml"
alexcr's user avatar
  • 1,487
3 votes

Magento2-Translation not working in js files

For me, I understood that flushing the translation cache was not deleting the js-translation.json in pub/static/path/to/appropriate/theme/locale. After deleting, the file was renewed and things where ...
Christophe Ferreboeuf's user avatar
3 votes

Magento 2 can't translate modal's title

Came here for the same issue. But found out you will need to use php to get it translated. title: "<?php echo __('Test string')?>"
Johnny Longneck's user avatar
3 votes
Accepted

Magento 2 Translate Checkout

After much head banging and trying I finally figured out what the problem was. Localizing inside a theme such as app/design/frontend/Company/theme/i18n/en_US.csv does appear to get incorporated into ...
Eirik's user avatar
  • 2,073
2 votes

How to translate JS error message or text in Magento 2?

it throw error if you use __ so follow below code require([ 'jquery', // jquery Library 'mage/translate' ], function($,$t){ $(window).load(function() { alert($t('...
Pradeep Kumar's user avatar
2 votes

Javascript translation not working properly

I wrote a post here regard to my the same issue. You can read to understand why it happens and how to fix https://mrvts.wordpress.com/2018/07/19/magento-2-javascript-translation-sometime-translate-...
V.Tran's user avatar
  • 131
2 votes
Accepted

How to escape a % in magento translation

For a literal percent character, use %% Reference: Magento uses vsprintf to format translations https://secure.php.net/vsprintf
Fabian Schmengler's user avatar
1 vote
Accepted

translate "Please enter the same value again"

Maybe you've missed the dot? Place the following in app/design/%vendor%/%theme%/i18n/en_US.csv "Please enter the same value again.","Please enter the same value again." If it's a ...
Stevie-Ray Hartog's user avatar
1 vote

Magento 2: translate in js?

The problem with "View and Edit Cart" seems to have fixed itself somehow, I didn't change anything and just started to show up in the right language. For popup massage You added %1 to your shopping ...
Bhavin Pethani's user avatar
1 vote

Magento 2 JS Translation Not Working

It may be due to Magento bug. In vendor/magento/module-translation/Model/Json/PreProcessor.php $area = $this->areaList->getArea($areaCode); $area->load(\Magento\Framework\App\Area::...
Gediminas's user avatar
  • 448
1 vote

Magento 2 Translate Checkout

Before you delete this empty file Normally this file is generated by language you have to launch a php bin/magento setup:static-content:deploy fr_FR en_US tell me if that work
Mohamed El Mrabet's user avatar
1 vote
Accepted

How to translate city/region dropdown on magento 2

Those translations are located into the database. You can create a specific module to setup your data. You need to update the directory_country_region_name table using region_id field from the ...
DependencyHell's user avatar
1 vote

Magento 2 - Error Messaging Text Change

Please check that validation errors text in lib/web/mage/validation.js is like $.mage.__('validation error msg') and not like 'validation error msg'. If it is not using $.mage.__() it will not be ...
Sarvagya's user avatar
  • 1,217
1 vote

Magento2 translating Javascript (KO) template text

As I described in the Github issue (https://github.com/magento/magento2/issues/7525#issuecomment-316690100) there is another (easier) solution to that problem. You just need to make sure to deploy ...
FaHu's user avatar
  • 238
1 vote

Javascript translation not working properly

You must use $.mage.__('excl. VAT') as it will be automatically parsed by an internal magento code and generate a JSON file in pub/static folder eg : pub/static/frontend/Magento/Luma/fr_FR/js-...
eInyzant's user avatar
  • 331
1 vote

Javascript translation not working properly

it throw error if you use __ so follow below code require([ 'jquery', // jquery Library 'mage/translate' ], function($,$t){ alert($t('Enter Your message here')); });
Pradeep Kumar's user avatar
1 vote

Javascript translation not working properly

it's about timing the translation. Magento had the same Problem in the Checkout or the Catalog in early Versions. Here is an example: In an old Version, the Add to Cart Button was not translated ...
David Verholen's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible