From 63c24c19e08e9bc633998f0cddfca14e96ff46b3 Mon Sep 17 00:00:00 2001 From: Zemistr Date: Mon, 20 Apr 2015 11:18:04 +0200 Subject: [PATCH] Added method Translator::hasLanguageAndPluralByCode($code) --- src/l10nNetteTranslator/Translator.php | 8 ++++++++ tests/TranslatorTest.php | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/l10nNetteTranslator/Translator.php b/src/l10nNetteTranslator/Translator.php index f1f9abe..96b26ca 100644 --- a/src/l10nNetteTranslator/Translator.php +++ b/src/l10nNetteTranslator/Translator.php @@ -69,6 +69,14 @@ public function getLanguageAndPluralByCode($code) { return $this->languages_and_plurals[$code]; } + /** + * @param string $code + * @return bool + */ + public function hasLanguageAndPluralByCode($code) { + return isset($this->languages_and_plurals[$code]); + } + /** * @return \l10nNetteTranslator\LanguageAndPlural * @throws InvalidStateException diff --git a/tests/TranslatorTest.php b/tests/TranslatorTest.php index 616745d..95c4886 100644 --- a/tests/TranslatorTest.php +++ b/tests/TranslatorTest.php @@ -215,4 +215,14 @@ public function testTranslate() { $this->assertSame('foo', $translator->translate('foo', 0)); $this->assertSame('foo', $translator->translate('foo', 0, [])); } + + public function testHasLanguageAndPluralByCode() { + $translator = new Translator(); + $language_and_plural = new LanguageAndPlural(); + + $this->setProperty($translator, 'languages_and_plurals', ['cs' => $language_and_plural]); + + $this->assertTrue($translator->hasLanguageAndPluralByCode('cs')); + $this->assertFalse($translator->hasLanguageAndPluralByCode('sk')); + } }