Commit graph

9 commits

Author SHA1 Message Date
Platonides 86c86a3766 Add the position of the text to the messages so that
the position can be changed depending on the plural, as requested by Amir in
http://lists.wikimedia.org/pipermail/mediawiki-i18n/2011-August/000338.html

Placing the text after the unit could get funny in cases where there is
more text than just the number and the unit, but it's not a problem for the 
parserfunction to fix.

The transformations for ParserFunctions.i18n.php were
On pfunc-convert-unit messages: s/$2/$3/, s/$1/$2/
s/'pfunc-convert-unit-.*' *=> '/\0$1/
2011-09-01 18:45:53 +00:00
Happy-melon 45b53a4eb8 Follow-up r81074: fix typos in some unit names and messages ("mili" instead of "milli"). 2011-08-25 21:22:28 +00:00
Happy-melon fd1620e14b Follow-up r81074, r81517: implement SI prefixes as a separate structure. You can now specify which units should take SI, and then they accept *all* SI prefixes centrally. Some care is still needed to avoid unit conflicts, but this substantially reduces the number of messages required.
The translations of prefixed units in some languages may be a little tricky if the prefix is inflected etc, but you know what?  You can always use ParserFunctions!!  :-D
2011-02-16 10:27:42 +00:00
Happy-melon b3d240bdba Follow-up r81074: turns out {{convert}} is (mostly) case-sensitive after all, so reclaim case-sensitivity here. Will work on abstracting out SI prefixes later. 2011-02-04 14:28:37 +00:00
Happy-melon d316c140e9 Follow-up r81074: better handling of whitespace, or lack thereof, between the digit and unit. 2011-01-29 15:59:17 +00:00
Happy-melon c65d2f8bbc Follow-up r81074: succumb, though it breaks my heart to do so (:P), to American linguistic imperialism... 2011-01-29 15:45:07 +00:00
Happy-melon f274e42be1 Follow-up r81074:
* subclass ConvertError and ExprError from MWException
* invoking the parser for error messages clears state and exposes strip markers, and the error messages should be in the content language anyway
* clean up the magic word list
2011-01-29 13:54:02 +00:00
Happy-melon 7ec54c6cfc Follow-up r81074 CR:
* Use autoloader for ConvertParser, and ExprParser which the code was cloned from
* Fix PHP 5.1 compatibility, while there's no requirement for us to keep it, there's also no need to break it unnecessarily, and it's a really trivial fix in this case.
* Tidy whitespace
* Use ConvertDimension::getLocalisedName() for the dimensionmismatch error, as intended
2011-01-27 17:34:37 +00:00
Happy-melon 65e9e69202 (bug 235) parser function for conversion of units of measurement.
[[Template:Convert]] on enwiki is a behemoth of a construction that just about manages to do this sort of conversion, taking {{convert|5|mi|km}} and outputting "5 miles (8 km)", etc.  To port this to another wiki requires copying over three and a half thousand subtemplates.  The additional load produced by including numerous copies of this template is measurable on large pages on enwiki, and it eats voraciously into the template limits.

This revision introduces {{#convert: 5 mi | km }}, outputting "8 km" or thereabouts.  See http://www.mediawiki.org/wiki/User:Happy-melon/Convert for more details, or look at the examples in the parser tests.  

In a very rough profile, comparing 50 calls to {{convert}} verses the same 50 calls to the wrapper template shown at the link above, the parser function implementation reduces page load time by 72%, preprocessor node count by 83%, post-expand include size by 86% and template argument size by 97%.  More detailed profiling would probably reveal places where extra caching could improve performance further.

The primary reason for putting it in ParserFunctions instead of its own extension is availability: PFs are already available across the cluster, and it's accepted as an essential extension for any wiki wishing to emulate or mirror WMF content.  One less separate extension installed on the cluster is one less extension which has to be matched by reusers.  

It's still missing a lot of units, which I ran out of patience to copy from {{convert}}; I thought I'd get some feedback on the infrastructure first.
2011-01-27 00:13:10 +00:00