Page MenuHomePhabricator

JavaScript table sort does not observe local language with respect to digit groups, decimals and date formats
Closed, ResolvedPublic

Description

sort table sorts on . for decimal sign, dutch uses . als a number grouping
symbol and , as a decimal sign:
234 567.7865 (en) = 234.567,7865 or 234 567,7865(nl)

neither does it sort correct on dates:
nl uses dd-mm-yy


Version: 1.10.x
Severity: normal

Details

Reference
bz8063

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:31 PM
bzimport set Reference to bz8063.
bzimport added a subscriber: Unknown Object (MLST).

simon wrote:

This would be very much appreciated for Wikipedia in Swedish as well.

As an example, see the article "Lista över grundämnen"
http://sv.wikipedia.org/w/index.php?title=Lista_%C3%B6ver_grund%C3%A4mnen&oldid=3480541
and try sorting by "Atommassa" (atomic weight).

(In reply to comment #2)

There is currently a hack in place on svwp that fixes this:

http://sv.wikipedia.org/w/index.php?title=MediaWiki:Common.js&diff=3698408&oldid=3664899

If we used this function:

function ts_parseFloat(num) {

if (!num) return 0;
num = num.replace(/\./g, "");
num = num.replace(/,/g, ".");
num = parseFloat(num);
return (isNaN(num) ? 0 : num);

}

we need a distinction of cases based on $wgUserLanguage for a language specific
handling of . and , in numbers.

simon wrote:

(reply to comment #3 by Raimond Spekking)

I don't think we should use $wgUserLanguage, since this needs to be a per-wiki
setting, not a per-user setting. Maybe something like this:


ts_decimal_separator = ".";

function ts_parseFloat(num) {

if (!num) return 0;

num = num.replace(/\s/g, ""); remove whitespaces
num = num.replace(/'/g, "");
remove apostrophes; used in German-speaking
Switzerland as thousands separator
if (ts_decimal_separator == ",") {

		num = num.replace(/\./g, "");	
		num = num.replace(/,/, ".");

} else {

		// TODO: handle the "Momayyez" character, used in Arab countries and Iran
		num = num.replace(/,/g, "");

}

num = parseFloat(num);
return (isNaN(num) ? 0 : num);

}

This handles most cases. Then wikis can set "ts_decimal_separator" to "," in
their [[MediaWiki/common.js]] to get comma style. Maybe there is a better way to
do this..?

"Momayyez" should maybe be handled for Arab countries, but I don't know what the
code point for that is; [[en:Momayyez]] doesn't say.

(In reply to comment #4)

"Momayyez" should maybe be handled for Arab countries, but I don't know what thecode point for that is;
[[en:Momayyez]] doesn't say.

You mean "The Momayyez ("٫", Unicode U+066B) is a decimal separator used in the Arab world and Iran"? I would
assume that "U+066B" is what you are loking for?

mmehdi.g wrote:

A major problem for Arabic and Persian language is their Unicode digits:
I tried a code in my monobook:
http://fa.wikipedia.org/w/index.php?oldid=1266410

The numeric part of the report is fixed in r42715. For dates please see bug 8226.