-
-
Notifications
You must be signed in to change notification settings - Fork 835
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 |
Fixes #0000
Note
This PR aims to implement the translation of attributes of validation errors, a feature initially started nearly a decade ago (see this commit) but seemingly never completed.
Changes proposed in this pull request:
core
totags
per discussion in Move locale files from language pack to core #2408 (comment)Reviewers should focus on:
First and foremost, evaluate if this change is not a breaking change and can safely be done on
1.x
. The only concern with my implementation is that some extensions may have already defined a key in thevalidation
namespace, likevalidation.attributes.name
, which could lead to unexpected behavior. In any case, I recommend reading the discussion in Move locale files from language pack to core #2408 (comment) to get more context on this.Would there be a way how the same could be achieved without having to explicitly return a translation key for each attribute? Let's say there was some kind of generic solution, how would we handle cases such as this:
framework/extensions/package-manager/src/ConfigureComposerValidator.php
Lines 18 to 24 in 5bd7e5d
The only validation logic I knowingly didn't change is the
SettingsValidator
, as in that case it would certainly not be maintainable to add support for every possible case:framework/framework/core/src/Settings/SettingsValidator.php
Lines 24 to 53 in 5bd7e5d
Should a similar solution be PR'd for
2.x
or are you looking for something more lean perhaps without the risk of a breaking change?Screenshot
QA
flarum-lang/german
orflarum-lang/dutch
title
orcontent
Necessity
Confirmed
composer test
).Required changes: