Skip to content

Commit

Permalink
Added setUntranslated method.
Browse files Browse the repository at this point in the history
Updated tests.
  • Loading branch information
Zemistr committed Mar 29, 2015
1 parent c13e5bc commit 8545d3c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/l10n/Translator/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
34 changes: 33 additions & 1 deletion tests/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 8545d3c

Please sign in to comment.