Jarry1250 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/156130
Change subject: Create TranslateSvgUtils::langCodeToOs() and osTolangCode()
......................................................................
Create TranslateSvgUtils::langCodeToOs() and osTolangCode()
Although not particularly complicated at the moment, could easily
become so in future as more quirks are discovered in the way
systemLanguage is interpreted.
Change-Id: I1599c25c8756e96b5da4b036289b6b5c882b154c
---
M SVGFile.php
M TranslateSvgUtils.php
2 files changed, 30 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TranslateSvg
refs/changes/30/156130/1
diff --git a/SVGFile.php b/SVGFile.php
index 0c29083..e43e92f 100644
--- a/SVGFile.php
+++ b/SVGFile.php
@@ -1,7 +1,7 @@
<?php
/**
- * This file contains classes for manipulating the contents on an SVG file.
- * Intended to include all references to PHP's DOM manipulation system.
+ * This file contains classes for manipulating the contents of an SVG file.
+ * Intended to centralise references to PHP's byzantine DOM manipulation
system.
*
* @file
* @author Harry Burt
@@ -288,8 +288,7 @@
$numChildren = $text->childNodes->length;
$hasActualTextContent =
TranslateSvgUtils::hasActualTextContent( $text );
$lang = $text->hasAttribute( 'systemLanguage' )
? $text->getAttribute( 'systemLanguage' ) : 'fallback';
- $lang = str_replace( '_', '-', strtolower(
$lang ) );
- $realLangs = preg_split( '/, */', $lang );
+ $langCode = TranslateSvgUtils::osToLangCode(
$lang );
$counter = 1;
for ( $k = 0; $k < $numChildren; $k++ ) {
@@ -428,11 +427,7 @@
foreach ( $translations[$textId] as $language =>
$translation ) {
// Sort out systemLanguage attribute
if ( $language !== 'fallback' ) {
- if ( strpos( $language, '-' ) !== false
) {
- list( $before, $after ) =
explode( '-', $language );
- $language = $before . '_' .
strtoupper( $after );
- }
- $translation['systemLanguage'] =
$language;
+ $translation['systemLanguage'] =
TranslateSvgUtils::langCodeToOs( $language );
}
// Prepare an array of "children" (sub-messages)
diff --git a/TranslateSvgUtils.php b/TranslateSvgUtils.php
index f1557a4..f9e1f87 100644
--- a/TranslateSvgUtils.php
+++ b/TranslateSvgUtils.php
@@ -343,6 +343,32 @@
}
/**
+ * Convert an OS locale (en_GB) to an internal language code (en-gb).
+ *
+ * @param string $os
+ * @return mixed
+ */
+ public static function osToLangCode( $os ){
+ return str_replace( '_', '-', strtolower( $os ) );
+ }
+
+ /**
+ * Convert an internal language code (en-gb) to an OS locale (en_GB)
+ *
+ * @seealso self::osToLangCode
+ * @param string $langCode
+ * @return string
+ */
+ public static function langCodeToOs( $langCode ){
+ if ( strpos( $langCode, '-' ) === false ) {
+ // No territory specified, so no change to make (fr =>
fr)
+ return $langCode;
+ }
+ list( $prefix, $suffix ) = explode( '-', $langCode, 2 );
+ return $prefix . '_' . strtoupper( $suffix );
+ }
+
+ /**
* Recursively replaces $1, $2, etc. with text tags, if required. Text
content
* is formalised as actual text nodes
*
--
To view, visit https://gerrit.wikimedia.org/r/156130
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1599c25c8756e96b5da4b036289b6b5c882b154c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TranslateSvg
Gerrit-Branch: master
Gerrit-Owner: Jarry1250 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits