Page MenuHomePhabricator

Make {{#expr: ... }} work with localized separators
Open, LowPublicFeature

Description

As reported on
https://www.mediawiki.org/wiki/Thread:Extension_talk:ParserFunctions/Use_comma_as_decimal_separator
and
https://pt.wikipedia.org/w/index.php?oldid=36562067&uselang=en#Re:_Casas_decimais_no_ParserFunctions
a code such as {{#expr: 1,5 * 3 }} doesn't work on ptwiki:
https://pt.wikipedia.org/w/index.php?oldid=36571994&uselang=en
(Expression error: Unrecognized punctuation character ",".)

Currently, we have the following on languages/messages/MessagesPt.php:

$separatorTransformTable = array( ',' => "\xc2\xa0", '.' => ',' );

so, the character "," should be treated as the decimal separator, and the result should be 4.5, as if the user had used {{#expr: 1.5 * 3 }} on enwiki.

A user suggested at
https://www.mediawiki.org/wiki/Thread:Extension_talk:ParserFunctions/Use_comma_as_decimal_separator/reply_(3)
the following change:
Add

$expr = str_replace( ',', '.', $expr );

to the begin of ExprParser::doExpression() and replaced line 82 in ExtParserFunctions::expr() with

$result = self::getExprParser()->doExpression( $expr );
$result = $parser->mOptions->mUserLang->formatNum( $result );
return $result;

The first replaces all commas in a given expression with dots and the second formats the output in the user language.

Could something like this be changed in the extension's code, for use on Portuguese Wikipedia?


Version: unspecified
Severity: enhancement

Details

Reference
bz52426

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 1:45 AM
bzimport set Reference to bz52426.
bzimport added a subscriber: Unknown Object (MLST).
Aklapper changed the subtype of this task from "Task" to "Feature Request".Feb 4 2022, 11:13 AM
Aklapper removed a subscriber: wikibugs-l-list.