(bug 41477) Add Language::isSupportedLanguage
authorNiklas Laxström <niklas.laxstrom@gmail.com>
Mon, 14 Jan 2013 07:21:10 +0000 (07:21 +0000)
committerNiklas Laxström <niklas.laxstrom@gmail.com>
Mon, 21 Jan 2013 08:47:53 +0000 (08:47 +0000)
Change-Id: If48c23fd580133bf78c19d4a0e8e00e74a639fa1

languages/Language.php
tests/phpunit/languages/LanguageTest.php

index 0a1cd37..7a62112 100644 (file)
@@ -245,6 +245,18 @@ class Language {
                throw new MWException( "Invalid fallback sequence for language '$code'" );
        }
 
+       /**
+        * Checks whether any localisation is available for that language tag
+        * in MediaWiki (MessagesXx.php exists).
+        *
+        * @param string $code Language tag (in lower case)
+        * @return bool Whether language is supported
+        * @since 1.21
+        */
+       public static function isSupportedLanguage( $code ) {
+               return is_readable( self::getMessagesFileName( $code ) );
+       }
+
        /**
         * Returns true if a language code string is of a valid form, whether or
         * not it exists. This includes codes which are used solely for
index 785c21c..5d32ff4 100644 (file)
@@ -1155,5 +1155,21 @@ class LanguageTest extends LanguageClassesTestCase {
                $this->assertEquals( "a{$c}b{$and}{$s}c", $lang->listToText( array( 'a', 'b', 'c' ) ) );
                $this->assertEquals( "a{$c}b{$c}c{$and}{$s}d", $lang->listToText( array( 'a', 'b', 'c', 'd' ) ) );
        }
+
+       /**
+        * @dataProvider provideIsSupportedLanguage
+        */
+       function testIsSupportedLanguage( $code, $expected, $comment ) {
+               $this->assertEquals( $expected, Language::isSupportedLanguage( $code ), $comment );
+       }
+
+       static function provideIsSupportedLanguage() {
+               return array(
+                       array( 'en', true, 'is supported language' ),
+                       array( 'fi', true, 'is supported language' ),
+                       array( 'bunny', false, 'is not supported language' ),
+                       array( 'FI', false, 'is not supported language, input should be in lower case' ),
+               );
+       }
 }