-
-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translated validation attributes #209
Comments
Hey, good point. The first way would be to add all of them to your validation translations file. I PR I would be open to merge is a change in the rule factory or any method to run in service provider to automatically add all the locale specific translation keys by copy'n'paste the original translation value. A simple example I have in mind: RuleFactory::copyAttributeTranslations(
['name']
);
// logic
foreach $attributes as $attribute
$trans = trans(validation.attributes.$attribute)
foreach $locales as $locale
Translator::add(validation.attributes.$locale.$attribute) |
I tried adding this to my AppServiceProvider: $translator = app('translator');
$currentLocale = $translator->getLocale();
$translator->addLines([
"validation.attributes.nl.name" => 'naam', // this can be dynamic
], $currentLocale); But that doesn't work and breaks all other public function attributes()
{
return RuleFactory::make([
'%name%' => __('validation.attributes.name'),
'%description%' => __('validation.attributes.description'),
]);
} But would love a cleaner solution. |
I will check this out and why the first one errors and how to possibly solve this. But I think that the last one with a dedicated method would be the cleanest! |
Personally I'm already satisfied with the solution I have. I also think that this way is more clear for programmers than doing all behind the scenes (for example in your TranslatableServiceProvider). I think the best solution would be to add something like this to the public function attributes()
{
return RuleFactory::translatedValidationAttributes(); // don't know if RuleFactory is the best place for this logic
} And perhaps make it possible to add your own if the field name isn't in the public function attributes()
{
return RuleFactory::translatedValidationAttributes([
'age' => __('default.age'),
]);
// which would result in: ['nl.age' => 'leeftijd', 'fr.age' => 'leeftijd', ... all the other attributes]
} What do you think? |
This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days |
I'm sorry if this has been asked before, but I can't seem to find an answer.
I validate my fields with the
RuleFactory::make
command. For example:When I show the errors below the inputs, I get something like:
fr.name is verplicht
.How can I translate the attribute name so
fr.name
is translated in the app locale (dutch in this case):naam
The text was updated successfully, but these errors were encountered: