Skip to content

fix: sort tooltip shows raw %{field_lower_first} instead of column name (#716)#823

Open
dotWee wants to merge 2 commits into
Awesome-Technologies:masterfrom
dotWee:fix/716-tooltip-column-name
Open

fix: sort tooltip shows raw %{field_lower_first} instead of column name (#716)#823
dotWee wants to merge 2 commits into
Awesome-Technologies:masterfrom
dotWee:fix/716-tooltip-column-name

Conversation

@dotWee
Copy link
Copy Markdown
Contributor

@dotWee dotWee commented Mar 31, 2026

The upstream ra-language-english v5.14.4 changed the ra.sort.sort_by translation string from "%{field}" to "%{field_lower_first}". React-admin's DataTableHeadCell computes field_lower_first from the resolved field label, but only when that label is a string:

field_lower_first: typeof fieldLabel === 'string'
    ? fieldLabel.charAt(0).toLowerCase() + fieldLabel.slice(1)
    : undefined

When fieldLabel is not a string (e.g. undefined or a React element), field_lower_first is passed as undefined.

Polyglot.js does not interpolate placeholders whose value is undefined, so the literal text "%{field_lower_first}" leaks into the tooltip.

The "%{field}" variable, by contrast, is always passed by react-admin regardless of the fieldLabel type.

…me (Awesome-Technologies#716)

The upstream ra-language-english v5.14.4 changed the ra.sort.sort_by
translation string from "%{field}" to "%{field_lower_first}".
React-admin's DataTableHeadCell computes field_lower_first from the
resolved field label, but only when that label is a string:

    field_lower_first: typeof fieldLabel === 'string'
        ? fieldLabel.charAt(0).toLowerCase() + fieldLabel.slice(1)
        : undefined

When fieldLabel is not a string (e.g. undefined or a React element),
field_lower_first is passed as undefined. Polyglot.js does not
interpolate placeholders whose value is undefined, so the literal
text "%{field_lower_first}" leaks into the tooltip. The "%{field}"
variable, by contrast, is always passed by react-admin regardless of
the fieldLabel type.

Override ra.sort.sort_by in the English and French locale files to
use "%{field}" instead of "%{field_lower_first}". The other five
locales (German, Chinese, Italian, Farsi, Russian) already use
"%{field}" and are unaffected.

Add sortTranslations.test.ts covering all seven locales with six
assertions each: no field_lower_first in the template, correct
interpolation, and resilience when field_lower_first is undefined
or omitted.
@dotWee dotWee marked this pull request as ready for review April 15, 2026 09:56
Copilot AI review requested due to automatic review settings April 15, 2026 09:56
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates react-admin sort tooltip translations to avoid leaking the raw %{field_lower_first} placeholder (introduced upstream in ra-language-english@5.14.4) by overriding ra.sort.sort_by to use %{field} and adding regression tests across supported locales.

Changes:

  • Override ra.sort.sort_by in English and French message bundles to interpolate %{field} (not %{field_lower_first}).
  • Add a new Vitest suite asserting ra.sort.sort_by never outputs raw placeholders when field_lower_first is missing/undefined.
  • Add basic checks that ra.sort.ASC / ra.sort.DESC are defined for each locale.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/i18n/sortTranslations.test.ts Adds regression tests ensuring sort tooltip translations don’t leak raw placeholders across locales.
src/i18n/en.ts Overrides ra.sort.sort_by to use %{field} interpolation for English.
src/i18n/fr.ts Overrides ra.sort.sort_by to use %{field} interpolation for French.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/i18n/sortTranslations.test.ts Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants