Laravel-Lang / publisher

Publisher provides functionality for working with application localization
https://laravel-lang.com/packages-publisher.html
MIT License
211 stars 25 forks source link

Translation was override if has same key #293

Closed skys215 closed 2 years ago

skys215 commented 2 years ago

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}

andrey-helldar commented 2 years ago

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:

image

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.

andrey-helldar commented 2 years ago

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?

skys215 commented 2 years ago

It is correct. Perhaps because I'm migrating from older projects. Sorry for disturbing.

andrey-helldar commented 2 years ago

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/