Page MenuHomePhabricator

Multiple languages showing on charts
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

What happens?:

The axis values and the values on hover are using the language of the user, but the other labels are in English.

What should have happened instead?:

All labels should have been in the user language.

Other information (browser name/version, screenshots, etc.):

Screenshot from 2025-01-11 14-47-45.png (868×1 px, 117 KB)


This patch's acceptance criteria:

  • String localization language in charts on wiki pages should match the target language of the page render (content language by default, page view language if a page has overridden its language), not the user language
  • Number formatting localization in charts on the above pages should match the target language of the page render, not the user language
  • -> test the above on a Commons page with default English -- strings in English, formatting in English
  • -> and one that has been changed to another language via https://commons.wikimedia.org/wiki/Special:PageLanguage (requires admin) -- strings in other language, formatting in other language

See also follow-up patches on T392725;

Details

Related Changes in Gerrit:
Related Changes in GitLab:
TitleReferenceAuthorSource BranchDest Branch
Pass locale on to the <wiki-chart lang> attributerepos/mediawiki/services/chart-renderer!76bvibberuselangmain
Customize query in GitLab

Event Timeline

Aklapper renamed this task from Mutliple languages showing on charts to Multiple languages showing on charts.Jan 11 2025, 4:34 PM

@aude can you check if we are passing the language correctly to the service (and any caching is considering the input language?) Thanks in advance!

I _think_ what's happening is we're passing the _content_ language down to the chart render, but the _user language_ is getting picked up for the client-side formatting.

If I copy the chart onto svwiki where content language is Swedish I can reverse it! :D

https://sv.wikipedia.org/wiki/Anv%C3%A4ndare:Brooke_Vibber_(WMF)/chart-test-2?uselang=en

image.png (1×2 px, 298 KB)

I'm not sure the current caching implications of using the user lang in parser output (does that just bifurcate cache for that page or does it break stuff?); we could 'resolve' this by always using content lang on both ends but that might not be the best for multi-lingual sites where user lang might be preferable to begin with.

bvibber moved this task from Up Next to Current Sprint on the Charts board.
bvibber edited projects, added Charts (Current Sprint); removed Charts.

Going to do a quick spike on fixing this with user language, see if it works

Change #1139112 had a related patch set uploaded (by Bvibber; author: Bvibber):

[mediawiki/extensions/Chart@master] Proposed fix for language mismatch on Charts

https://gerrit.wikimedia.org/r/1139112

Change #1139116 had a related patch set uploaded (by Bvibber; author: Bvibber):

[mediawiki/extensions/Chart@master] Alternate proposed fix for mismatched user langugae on Chart

https://gerrit.wikimedia.org/r/1139116

Change #1139112 abandoned by Bvibber:

[mediawiki/extensions/Chart@master] Proposed fix for language mismatch on Charts

Reason:

abandoned in favor of more conservative patch 1139116

https://gerrit.wikimedia.org/r/1139112

Second proposed patch https://gerrit.wikimedia.org/r/1139116 is very conservative and just switches from wgUserLang to wgPageViewLang on the client-side formatting. This matches global content language or per-page language on a multilingual site, and means our formatters now match with the localized text and data from the axis labels and the tabular fields.

If we want to make it easier to preview the chart format page in other languages, let's do that in a proper UI rather than relying on ?uselang=

Ok current state:

conservative initial patch, uses wgPageViewLanguage for client-side localized formatting to try to match page/content lang:

follow-up patch to add per-invocation 'lang' attribute on the output, so client rendering can always rely on that if we add fancier setups in future to allow uselang= on Data:.chart previews (added in second patch) or an override in the parser function (not implemented, just the underpinning):

Change #1139116 merged by jenkins-bot:

[mediawiki/extensions/Chart@master] Initial fix for mismatched user language on Chart

https://gerrit.wikimedia.org/r/1139116

Things look good on-wiki but don't seem to be working as expected on Commons. I'm still only seeing https://commons.wikimedia.org/wiki/Data:Swedish_aid.chart?uselang=sv render in English.

Ok it's ... in process. Once merged I'll backport to 1.45 and deploy with SpiderPig. :D

Rather than deploy Friday afternoon, I'm gonna push it to deployment Monday morning. :)