From 0e08362b40164aafb3b30b43a65a584430d17d37 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Mon, 14 Jan 2013 07:21:10 +0000 Subject: [PATCH] (bug 41477) Add Language::isSupportedLanguage Change-Id: If48c23fd580133bf78c19d4a0e8e00e74a639fa1 --- languages/Language.php | 12 ++++++++++++ tests/phpunit/languages/LanguageTest.php | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/languages/Language.php b/languages/Language.php index 0a1cd37d97..7a62112635 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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 diff --git a/tests/phpunit/languages/LanguageTest.php b/tests/phpunit/languages/LanguageTest.php index 785c21c91e..5d32ff4ac2 100644 --- a/tests/phpunit/languages/LanguageTest.php +++ b/tests/phpunit/languages/LanguageTest.php @@ -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' ), + ); + } } -- 2.20.1