-
-
Notifications
You must be signed in to change notification settings - Fork 836
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
[1.x] Implement Support for Translatable Validation Attribute Errors #4070
base: 1.x
Are you sure you want to change the base?
[1.x] Implement Support for Translatable Validation Attribute Errors #4070
Conversation
It should be possible to edit AbstractValidator and manipulate the messages to dynamically check for the existence of a validation attribute translation. Mainly, the result of |
The only concern is potential conflicts in attribute names between extensions. So might be better to put extension validation under the extension namespace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @SychO9 suggests, we run the possibility of conflicts here if extensions register the same attribute names, but want a different translation.
Let's scope everything under the extension name(s) please
@imorland I moved the validation translations to the extension namespaces
@SychO9 Can you make an example of what you were thinking? Now that some validation strings are in the extension namespaces, I feel like it would get messy if the |
here is a proof of concept of how you can obtain the extension ID related to the validator: // this would be nice in a trait, used by the abstract validator in this case
protected function getClassExtensionId(): ?string
{
$extensions = resolve(ExtensionManager::class);
return $extensions->getExtensions()
->mapWithKeys(function (\Flarum\Extension\Extension $extension) {
return [$extension->getId() => $extension->getNamespace()];
})
->where(function ($namespace) use ($class) {
return $namespace && str_starts_with(static::class, $namespace);
})
->keys()
->first();
} you would have to add this to public function getNamespace(): ?string
{
return Collection::make($this->composerJsonAttribute('autoload.psr-4'))
->filter(function ($source) {
return $source === 'src/';
})
->keys()
->first();
} once you have that, you could theoretically use it in the getMessages method to automatically point to also imo it's not necessary to replace |
I'll tentatively add this to the |
c264e2a
to
356624b
Compare
@imorland I've now refactored the implementation per Samis suggestion. Three cases that are knowingly missing here is for example the validation logic in framework/extensions/tags/src/Listener/SaveTagsToDatabase.php Lines 131 to 145 in 8eb56b1
There are two other examples where a new validator is created instead of the
Should refactoring of the non-standard validation logic be done in this PR or separately (or not at all)? Also, would it make sense to add tests for this? |
Fixes #0000
Changes proposed in this pull request:
Reviewers should focus on:
Screenshot
QA
flarum-lang/german
orflarum-lang/dutch
title
orcontent
Necessity
Confirmed
composer test
).Required changes: