flarum / flarum/issue-archive

Custom attribute name translations don't work

Open
#155 2 comments 0 reactions 0 assignees View on GitHub
type/bug
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## 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`.

Contributor guide

Open the contributing guide

Research direction

Start with Laravel's Concerns/FormatsMessages.php and Flarum's validation.yml, which the report identifies as the relevant translation paths. Compare Laravel's custom-attribute lookup with Symfony's translator behavior, then verify that validation errors use translated attribute names rather than the English snake-case name.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php, symfony
Domain
backend, localization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.