From 8545d3c1dfcea722ed0b34a0b6d55bc3022c9cda Mon Sep 17 00:00:00 2001 From: Zemistr Date: Sun, 29 Mar 2015 14:41:14 +0200 Subject: [PATCH] Added setUntranslated method. Updated tests. --- src/l10n/Translator/Translator.php | 11 +++++++++- tests/TranslatorTest.php | 34 +++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/l10n/Translator/Translator.php b/src/l10n/Translator/Translator.php index a6afee3..1eb2131 100644 --- a/src/l10n/Translator/Translator.php +++ b/src/l10n/Translator/Translator.php @@ -103,6 +103,15 @@ public function removeText($key, $plural = 0) { } } + /** + * @param string $key + * @param int $plural + */ + public function setUntranslated($key, $plural = 0) { + $this->checkPlural($plural); + $this->untranslated[$key][$plural] = true; + } + /** * @param string $key * @param int $plural Nothing for all plurals @@ -136,7 +145,7 @@ public function translate($key, $n = 1, array $parameters = array()) { $translated = $this->getText($key, $plural); if ($translated === null) { - $this->untranslated[$key][$plural] = true; + $this->setUntranslated($key, $plural); return $key; } diff --git a/tests/TranslatorTest.php b/tests/TranslatorTest.php index eb3dddb..ca1c3df 100644 --- a/tests/TranslatorTest.php +++ b/tests/TranslatorTest.php @@ -167,7 +167,7 @@ public function testGetUntranslated() { $this->assertSame($expected, $translator->getUntranslated()); } - public function testRemoveUntranslated() { + public function testSetAndRemoveUntranslated() { $plural = $this->createPluralMock(); $translator = new Translator($plural); @@ -200,5 +200,37 @@ public function testRemoveUntranslated() { $translator->removeUntranslated('key'); $translator->removeUntranslated('key_2'); $this->assertSame(array(), $translator->getUntranslated()); + + $translator = new Translator($plural); + $translator->setUntranslated('key'); + $translator->setUntranslated('key_2'); + $expected = array( + "key" => array(true), + "key_2" => array(true) + ); + + $this->assertSame($expected, $translator->getUntranslated()); + + $translator->setUntranslated('key', 1); + $translator->setUntranslated('key_2', 1); + $expected = array( + "key" => array(true, true), + "key_2" => array(true, true) + ); + + $this->assertSame($expected, $translator->getUntranslated()); + + $translator->removeUntranslated('key', 0); + $translator->removeUntranslated('key_2', 1); + $expected = array( + "key" => array(1 => true), + "key_2" => array(true) + ); + + $this->assertSame($expected, $translator->getUntranslated()); + + $translator->removeUntranslated('key'); + $translator->removeUntranslated('key_2'); + $this->assertSame(array(), $translator->getUntranslated()); } }