Page MenuHomePhabricator

Graph localization support
Open, NormalPublic


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 updated the task description. (Show Details)
Tacsipacsi raised the priority of this task from to Needs Triage.
Tacsipacsi added projects: Graphs, I18n.
Tacsipacsi added a subscriber: Tacsipacsi.
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMay 26 2015, 6:35 PM
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 Normal 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

Graphs / 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.

Yurik added a comment.Feb 16 2016, 4:48 AM

@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?

Yurik updated the task description. (Show Details)Feb 16 2016, 4:49 AM

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

Yurik added a comment.Feb 16 2016, 6:30 AM

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:

Graphs / Graphoid use D3 library, which supports number formatting and time formatting

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.

Yurik added a comment.Feb 16 2016, 1:50 PM

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?

TheDJ added a subscriber: TheDJ.Jun 6 2016, 1:27 PM

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

Krinkle removed a subscriber: Krinkle.Jun 7 2016, 5:54 PM
Arbnos added a subscriber: Arbnos.Dec 6 2016, 3:55 PM
Pamputt added a subscriber: Pamputt.Jan 5 2018, 7:51 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. :)