Magento 2.1.7 - Translating the wrong input messages on creating account
-
16-01-2021 - |
Question
So we have a registration form with the fields Email, Password and Confirm Password as you can see in the picture:
What happens is that the messages which appear once the input has been written keep being showed in English after changing the language to Spanish:
I have modified the: <vendor>\app\i18n\<module>\es_ES\es_ES.csv
file:
"Please enter the same value again.","Por favor, ingrese el mismo valor."
"Please enter a valid email address (Ex: johndoe@domain.com).","Por favor, ingrese una dirección de correo electrónico válida. (Ej: johndoe@dominio.com)."
"Minimum length of this field must be equal or greater than %1 symbols. Leading and trailing spaces will be ignored.","La longitud mínima de este campo tiene que ser igual o superior a %1 símbolos. Los espacios iniciales y finales serán ignorados."
As far as I have understood, about the .csv columns is that if I only write the first 2 (the old translation and the new one), it applies everywhere it finds it. And I did search the sentences in the vendor folder and the email sentence comes from a translation csv but I could only find the other 2 sentences in javascript files.
After changing all this I ran the below commands:
rm -rf pub/static/*;
php bin/magento setup:upgrade; php bin/magento setup:static-content:deploy;
php bin/magento setup:static-content:deploy es_ES;
I also know and read about that both files:
app/design/frontend/vendor/theme/i18n/en_US.csv
app/design/frontend/vendor/theme/i18n/es_ES.csv
Don't have priority over(Atleast in my version):
app/i18n/...
I've read aswell some info about javascript translation but I don't understand it because i don't know about it.
Solution 2
I managed to fix it parcially, I couldn't do it totally because we don't modify vendor.
You need to modify the javascript libraries and make sure the strings are translatable. Have a look at these:
https://github.com/magento/magento2/commit/3109c8e96bcd08041f558be65a2a4e3d213d22a4
The first one fixes the email and confirm password and the second one in theory fixes the Password Validation.
I got stuck in the Password validation because as I said, I can't modify Magento main folders, I want to overwrite them.
OTHER TIPS
you need to create your module in app/i18n directory
create below directory
app/i18n/ModuleName/es_ES
create registration.php file include below code in it.
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::LANGUAGE,
'moduleName_es_es',
__DIR__
);
create language.xml file include below code
add translate csv file es_ES.csv in above directory
app/i18n/ModuleName/es_ES/es_ES.csv
add translatation in above file
Please enter a valid email.,Bitte geben Sie eine gültige eMail-Adresse ein.,module,Magento_CustomerImportExport
run below command to register language pack
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy es_ES