Page MenuHomePhabricator

Graph localization support
Open, LowPublicFeature

Assigned To
Authored By
May 26 2015, 6:35 PM
Referenced Files
"Doubloon" token, awarded by The_RedBurn."Mountain of Wealth" token, awarded by Noe."Mountain of Wealth" token, awarded by Liuxinyu970226."Mountain of Wealth" token, awarded by Automatik.


Graph now uses English number format, while e.g. {{formatnum:}} is available for number formatting in content language. Please use it (or an equivalent). It would be simply great if user could change the language (e.g. for Commons), it could be placed with a “language” key in the main level of JSON array.

First step is to use vg.util.format.locale('fr-FR') to the the correct format. This requires php code to come up with that string.

Event Timeline

Tacsipacsi raised the priority of this task from to Needs Triage.
Tacsipacsi updated the task description. (Show Details)
Tacsipacsi added a subscriber: Tacsipacsi.
TheDJ renamed this task from Graph should use localized numbers to Graphoid should render Graph images with numbers in the locale of the transclusion.Jul 16 2015, 6:43 AM
TheDJ added a project: Graphoid.
TheDJ set Security to None.
Amire80 triaged this task as Medium priority.Aug 30 2015, 10:55 AM
Yurik renamed this task from Graphoid should render Graph images with numbers in the locale of the transclusion to Graph localization support .Dec 28 2015, 3:34 AM

MediaWiki-extensions-Graph / Graphoid use D3 library, which supports number formatting and time formatting localizatIion by defining a pre-set objects like here. There are about 25 presets (numbers, time), but I think MediaWiki has a more extensive system for number and date formatting. The question is how to bring these settings to Vega. I don't think we need to expose the entire js-side localization library just yet. Instead we can tell Vega how to format numbers (decimal separator, grouping) and time (month names, order, separators). Is this information available in the browser? Do we have it packaged as NPM for nodejs?

I don't think you use any other library to format time as specified in MediaWiki. Language::sprintfDate is complex beast and as far as I know there is no JavaScript equivalent of it.

CLDR provides data-driven number formatting, which should be quite close to MediaWiki's, but not exactly as we don't use those for all languages.

@Nikerabbit, the first step solution is to set Vega/d3 to one of these supported strings:
ca-ES, cs-CZ, de-CH, de-DE, en-CA, en-GB, en-US, es-ES, fi-FI, fr-CA, fr-FR, he-IL, hu-HU, it-IT, ja-JP, ko-KR, mk-MK, nl-NL, pl-PL, pt-BR, ru-RU, sv-SE, zh-CN

Is there a way to get them from MediaWiki (PHP) for a given language/wiki, preferably with a fallback that is in this list?

A manual mapping is needed. I wish projects would stop using too specific locale codes but that is not up to me to decide.

I wish all projects used one big localization library, but we are not. So my guess - I will have to hardcode the list, and for now simply offer a one to one mapping for about 15 languages, and english for everyone else.

All because we don't have this library in javascript supporting all our languages:

Is there a phabricator ticket or page outlining why D3 was chosen, to understand its benefits and characteristics?

Is there a phabricator ticket or page outlining why D3 was chosen, to understand its benefits and characteristics?

I don't know, but you can see Vega is among the most popular visualization grammars. Vega is built on d3, and nobody who has done visualizations at least once would ever wonder why :-)

Ah sorry, I thought d3 was the i18n library. So d3 doesn't use a library, but a custom d3-format thingy? If so, perhaps they should be convinced to adopt something more standard: cldrjs is possibly the current target of the JavaScript ecosystem near us, in the context of , but Krinkle would know better.

Sorry, I missed another important library - d3-time-format. Together with d3-format, they use a set of values, like these for fr-CA. It would be great if we can generate this set of values on the server and include it in the javascript config variables sent to the client (I don't think we need to support client-side per-country, its enough to do it per wiki)

decimal: ",",
thousands: "\xa0",
grouping: [3],
currency: ["", "$"]
dateTime: "%a %e %b %Y %X",
date: "%Y-%m-%d",
time: "%H:%M:%S",
periods: ["", ""],
days: ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
shortDays: ["dim", "lun", "mar", "mer", "jeu", "ven", "sam"],
months: ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"],
shortMonths: ["jan", "fév", "mar", "avr", "mai", "jui", "jul", "aoû", "sep", "oct", "nov", "déc"]

MediaWiki does have most of that data. I have no idea what is periods. Date and time formats cannot be automatically converted from MediaWiki unless you can override the formatting and implement sprintfDate and it's dependencies in JavaScript or make WebAPI for it. People are doing something already with Moment.js but I am not sure what exactly.

I am not sure how would you deliver this to the client. Perhaps a custom resource loader module, but do we really want one custom module for each upstream library that needs i18n data in slightly different format?

periods - the A.M. and P.M. equivalents (e.g., ["AM", "PM"]).

Is there any news about this? We need such feature on the French Wiktionary because name of the months are currently displayed in English (see the discussion (in French))

Is there any news about this?

No, otherwise the update would be listed in this very task. Patches always welcome. :)

TheDJ changed the subtype of this task from "Task" to "Feature Request".Jan 20 2022, 2:06 PM

{{Népességdiagram}} on huwiki uses Graph, and numbers on the Y axis appear with comma as a thousands separator (example), while in Hungarian spaces or dots should be used.

As this is now clientside only, and we know exactly what locale we are in.. this should probably be an easy fix...
Might have to update beyond vega2 first though...

Jdlrobson lowered the priority of this task from Medium to Low.Apr 26 2023, 12:33 AM