Skip to content
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

Custom attribute name translations don't work #155

Open
askvortsov1 opened this issue Jan 26, 2021 · 2 comments
Open

Custom attribute name translations don't work #155

askvortsov1 opened this issue Jan 26, 2021 · 2 comments
Labels

Comments

@askvortsov1
Copy link
Sponsor Member

askvortsov1 commented Jan 26, 2021

Bug Report

Current Behavior
Discovered while working on flarum/framework#2408 (comment).

When a validation error occurs, attribute names aren't translated, even those included in validation.yml; instead, a snake-case-without-spaces version in English is shown.

This has been around for a while: https://discuss.flarum.org/d/18424-values-from-attributes-not-translated

Steps to Reproduce

  1. Go to any Flarum site (works better on foreign language sites like https://flarumtr.com)
  2. Try to start a discussion, but leave the content blank
  3. The english word "content" will be part of the error message

Expected Behavior
Attribute names should be translated as per validation.yml

Possible Solution
I've managed to track this down to https://github.com/illuminate/validation/blob/v8.24.0/Concerns/FormatsMessages.php (version is arbitrary, it's been that way since recent history). Looks like Laravel's translator tries to retrieve ALL custom attribute names as an array, then get the proper element via Arr::get. This is incompatible with our use of Symfony's translator, which will only return individual translated items, not translation sub-namespaces.

I don't think this is something we can change in Flarum, so a PR to Laravel feels most appropriate. As per https://laravel.com/docs/master/releases, v6.x should be eligible for bugfixes for quite a while.

EDIT: Laravel's implementation is significantly different enough that a common mechanism won't work. I'm not sure if there's a trivial fix for this, and I don't think we should maintain a custom subclass of Validator or Validation/Factory.

askvortsov1 referenced this issue in askvortsov1/framework Jan 26, 2021
Use interpolated dot string to directly fetch attribute translations instead of retrieving ALL custom attribute translations, then fetching from them via Arr::get

This improves support for alternate translator implementations.

Fixes https://github.com/flarum/core/issues/2572
askvortsov1 referenced this issue in askvortsov1/framework Jan 26, 2021
Use interpolated dot string to directly fetch attribute translations instead of retrieving ALL custom attribute translations, then fetching from them via Arr::get

This improves support for alternate translator implementations.

Fixes https://github.com/flarum/core/issues/2572
@askvortsov1
Copy link
Sponsor Member Author

When this is done, we should revisit https://github.com/flarum/core/pull/2408/files#r560572646

@stale
Copy link

stale bot commented Jun 3, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We do this to keep the amount of open issues to a manageable minimum.
In any case, thanks for taking an interest in this software and contributing by opening the issue in the first place!

@stale stale bot added the stale label Jun 3, 2021
@SychO9 SychO9 added the type/bug label Jun 5, 2021
@stale stale bot removed the stale label Jun 5, 2021
@askvortsov1 askvortsov1 transferred this issue from flarum/framework Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants