Closed renky closed 1 year ago
Laravel does convert passed names, but not all of them:
This feature is documented: https://laravel.com/docs/10.x/localization#replacing-parameters-in-translation-strings
Next, regarding the transformation. Based on the Str::ucfirst()
function that Laravel calls for variables like :Attribute
, it capitalizes only the first letter without touching the rest:
Str::ucfirst('e-mail addresse') // E-mail addresse
Str::ucfirst('e-Mail Addresse') // E-Mail Addresse
Str::ucfirst('E-Mail Addresse'); // E-Mail Addresse
return [
'email' => 'The :attribute field must be a valid email address.'
// :Attribute muss eine gültige E-Mail-Adresse sein.
];
__(':Attribute muss eine gültige E-Mail-Adresse sein.', ['attribute' => 'E-Mail Addresse'])
// E-Mail Addresse muss eine gültige E-Mail-Adresse sein.
You also specified the version "Laravel Lang 3.1.1". In fact, I can suggest that this is a version of the laravel-lang/common
package, which, among other things, installs the laravel-lang/attributes
dependency.
Also a feature of Laravel is that the field names can be automatically renamed, and this is where we are faced with the fact that you get "E-mail addresse" instead of "E-Mail Addresse" for the German language because the file
contains incorrect, from the point of view German grammars, translations.
@sotten, @WhereIsLucas, can you help update the locales/de/php.json
file in the Laravel Lang: Attributes
project?
Ok, got it - then in fact this was "broken" when switching to the new structure 9 months ago... in the old validation.php files all attributes had capital letters - maybe this was done by a script? In meanwhile a few arguments have already been fixed but not all...
Indeed, I did not pay attention to it. My apologies.
I updated the values to match the previous version and released
the hotfix. Update the dependencies with the composer update
command and check again. Everything should be right now.
Thanks for the help!
Thanks 👍
Environment
Issue description
Email-Validation with a wrong email leads to the following error message in German: "E-mail-adresse muss eine gültige E-Mail-Adresse sein." As visible the first automatically replaced "E-mail-adresse" has the wrong casing - should be written like the latter "E-Mail-Adresse" with upper cases.
In older versions of laravel-lang the attributes have been replaced with ":attribute" and correct casing in the validation.php attribute list 'email' => 'E-Mail-Adresse'. In the current version it is done with ":Attribute" and 'email' => 'e-mail-adresse', what finally results in the capital first letter (which I guess is a laravel feature thats not documented?!)
The question is now: is it a Bug in laravel-lang, or in laravels localization feature? For all other attributes this migth be ok, but I guess there are more cases where a dash is used!?
Since the official laravel installation doesn't use :attribute I'd prefer the old solution...
Steps to reproduce
just validate with german translation file