Translation was override if has same key
skys215 opened this issue · 4 comments
- Lang Publisher Version: 14.3
- Laravel Version: 9.24.0
- PHP Version: 8.1.6
Description:
It's quite common that there are same key inside different files.
Inside the json.josn#L444 has a key with password
, which will be written to auth.php
used for the label for password input box.
At the same time, in php.json#L82 also has a key named password
. It is used for showing error when password is incorrect.
When the locale was generated, the one in the php.json
is reserved (or it replaced the value which generated from json.json
). It causes to show wrong string at password input box.
Steps To Reproduce:
php artisan lang:add {any language}
In this case, there is no error. The password
and Password
are different keys.
The php
keys are used for php file translations like auth.php
, pagination.php
, passwords.php
and validation.php
while json files are used for json translations.
// auth.php is correct
return [
'failed' => 'These credentials do not match our records.',
'password' => 'The password is incorrect.',
'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
];
The Password
key translation is used in other projects:
For example:
composer require laravel/ui
php artisan lang:add fr
// lang/fr/auth.php
return [
'failed' => 'Ces identifiants ne correspondent pas à nos enregistrements.',
'password' => 'Le mot de passe est incorrect',
'throttle' => 'Tentatives de connexion trop nombreuses. Veuillez essayer de nouveau dans :seconds secondes.',
];
// lang/fr.json
{
...
"Password": "Mot de passe",
}
It's correct.
Inside the json.json#L444 has a key with password, which will be written to auth.php used for the label for password input box.
Not certainly in that way. This key is used for translations in projects such as Breeze, Jetstream, Nova and UI.
Thus, when calling __('auth.password')
in the English localization, we will get the The password is incorrect.
string.
Do you have it differently?
It is correct. Perhaps because I'm migrating from older projects.
Sorry for disturbing.
Don't worry. By the way, in order to remove extra keys from translation files, you can call the php artisan lang:reset
command.
If you are upgrading a project with Laravel Lang, we recommend that you follow the upgrade instructions: https://publisher.laravel-lang.com/installation/upgrade/