flarum / issue-archive

0 stars 0 forks source link

Custom attribute name translations don't work #155

Open askvortsov1 opened 3 years ago

askvortsov1 commented 3 years ago

Bug Report

Current Behavior Discovered while working on https://github.com/flarum/core/pull/2408#discussion_r561134991.

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 commented 3 years ago

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

stale[bot] commented 3 years ago

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!