Jarry1250 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/156131
Change subject: Create TranslateSvgUtils::fetchLanguageName()
......................................................................
Create TranslateSvgUtils::fetchLanguageName()
Wrapper function providing a more sensible fallback chain than
Language::fetchlanguageName and integrating our own interpretation of
the "fallback" language code.
Change-Id: Ib1db640b46912fab7e417d98f429846a5e456e87
---
M SVGFile.php
M TranslateSvgUtils.php
2 files changed, 26 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TranslateSvg
refs/changes/31/156131/1
diff --git a/SVGFile.php b/SVGFile.php
index e43e92f..a0b15f6 100644
--- a/SVGFile.php
+++ b/SVGFile.php
@@ -465,9 +465,9 @@
$switch->appendChild( $newTextTag );
}
- $langName = ( $language === 'fallback' ) ?
- 'fallback' :
Language::fetchLanguageName( $language );
- if ( in_array( $language, $currentLanguages ) )
{
+ // To have got this far, we must have either
updated or started a new language
+ $langName =
TranslateSvgUtils::fetchLanguageName( $language, $this->fallbackLanguage );
+ if ( in_array( $language, $currentLanguages )
|| $language == 'fallback' ) {
$expanded[] = $langName;
} else {
$started[] = $langName;
diff --git a/TranslateSvgUtils.php b/TranslateSvgUtils.php
index f9e1f87..3dabc7d 100644
--- a/TranslateSvgUtils.php
+++ b/TranslateSvgUtils.php
@@ -369,6 +369,29 @@
}
/**
+ * Implement our own wrapper around Language::fetchLanguageName,
providing a more sensible
+ * fallback chain and our own interpretation of the "fallback" language
code.
+ *
+ * @param string $langCode Language code (e.g. en-gb, fr)
+ * @param string $fallbackLanguage Code of the language for which the
"fallback" magic word is equivalent
+ * @return string The autonym of the language with that code (English,
français, Nederlands)
+ */
+ public static function fetchLanguageName( $langCode, $fallbackLanguage
) {
+ $langCode = ( $langCode === 'fallback' ) ? $fallbackLanguage :
$langCode;
+ $langName = Language::fetchLanguageName( $langCode );
+ if ( $langName == '' ) {
+ // Try searching for prefix only instead
+ preg_match( '/^([a-z]+)/', $langCode, $matches );
+ $langName = Language::fetchLanguageName( $matches[0] );
+ }
+ if ( $langName == '' ) {
+ // Okay, seems the best we can do is return the
language code
+ $langName = $langCode;
+ }
+ return $langName;
+ }
+
+ /**
* 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/156131
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib1db640b46912fab7e417d98f429846a5e456e87
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