Jarry1250 has submitted this change and it was merged.
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, 31 insertions(+), 9 deletions(-)
Approvals:
Jarry1250: Verified; Looks good to me, approved
diff --git a/SVGFile.php b/SVGFile.php
index 1e9e4f8..9f6df91 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,8 @@
$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 );
+ $realLangs = array_map(
'TranslateSvgUtils::osToLangCode', $realLangs );
$counter = 1;
for ( $k = 0; $k < $numChildren; $k++ ) {
@@ -430,11 +430,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)
@@ -547,4 +543,4 @@
return new SVGFile( $file->getLocalRefPath(),
$group->getSourceLanguage() );
}
-}
\ No newline at end of file
+}
diff --git a/TranslateSvgUtils.php b/TranslateSvgUtils.php
index f1557a4..7856126 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)
+ *
+ * @see 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: merged
Gerrit-Change-Id: I1599c25c8756e96b5da4b036289b6b5c882b154c
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/TranslateSvg
Gerrit-Branch: master
Gerrit-Owner: Jarry1250 <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Jarry1250 <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits