r96502 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96501‎ | r96502 | r96503 >
Date:21:28, 7 September 2011
Author:happy-melon
Status:ok
Tags:
Comment:
Follow up r81074: implement a language map per Tim's suggestion (no more American linguistic imperialism, yay! :D). This is not a perfect solution because languages without translations still fall back to 'en' rather than 'en-gb' and so use the American units there, but this cures most of the issue.
Modified paths:
  • /trunk/extensions/ParserFunctions/Convert.php (modified) (history)
  • /trunk/extensions/ParserFunctions/ParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ParserFunctions/Convert.php
@@ -182,6 +182,19 @@
183183 );
184184 }
185185
 186+ # If the Language hasn't been deliberately specified, get it from the wiki's
 187+ # content language, but run it through a configurable map first
 188+ if( $this->language === true ){
 189+ global $wgContLang, $wgPFUnitLanguageVariants;
 190+ $code = $wgContLang->getCode();
 191+ if( isset( $wgPFUnitLanguageVariants[$code] ) ){
 192+ $this->language = Language::factory( $wgPFUnitLanguageVariants[$code] );
 193+ } else {
 194+ # Ok, actually *do* use $wgContLang
 195+ $this->language = true;
 196+ }
 197+ }
 198+
186199 return $this->processString( $string );
187200 }
188201
Index: trunk/extensions/ParserFunctions/ParserFunctions.php
@@ -34,6 +34,18 @@
3535 */
3636 $wgPFEnableConvert = false;
3737
 38+/**
 39+ * The language for 'en' is actually 'en-us', which insists on using non-canonical translations
 40+ * of the SI base units ("meter" rather than "metre" and "liter" rather than "litre"). We
 41+ * can avoid contaminatng dialects by internally mapping languages by default; this is
 42+ * configurable so you can remove it if you like, or add other maps if that's useful.
 43+ * Essentially, if your wiki's $wgContLang appears as a key in this array, the value is
 44+ * what is used as the default language for {{#convert}} output.
 45+ */
 46+$wgPFUnitLanguageVariants = array(
 47+ 'en' => 'en-gb'
 48+);
 49+
3850 /** REGISTRATION */
3951 $wgExtensionCredits['parserhook'][] = array(
4052 'path' => __FILE__,

Follow-up revisions

RevisionCommit summaryAuthorDate
r96933REL1_18: MFT r96499, r96502, r96505reedy00:36, 13 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r81074(bug 235) parser function for conversion of units of measurement....happy-melon00:13, 27 January 2011

Status & tagging log