Skip to content

Commit

Permalink
[Translation] added a MessageCatalogue::hasStrict() method to check i…
Browse files Browse the repository at this point in the history
…f a string has a translation (but without taking into account the fallback mechanism)
  • Loading branch information
fabpot committed Sep 14, 2011
1 parent c50a3a1 commit 79710ed
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/Symfony/Component/Translation/MessageCatalogue.php
Expand Up @@ -92,6 +92,22 @@ public function set($id, $translation, $domain = 'messages')
* @api
*/
public function has($id, $domain = 'messages')
{
if (isset($this->messages[$domain][$id])) {
return true;
}

if (null !== $this->fallbackCatalogue) {
return $this->fallbackCatalogue->has($id, $domain);
}

return false;
}

/**
* {@inheritdoc}
*/
public function hasStrict($id, $domain = 'messages')
{
return isset($this->messages[$domain][$id]);
}
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/Translation/MessageCatalogueInterface.php
Expand Up @@ -76,6 +76,18 @@ function set($id, $translation, $domain = 'messages');
*/
function has($id, $domain = 'messages');

/**
* Checks if a message has a translation (it does not take into account the fallback mechanism).
*
* @param string $id The message id
* @param string $domain The domain name
*
* @return Boolean true if the message has a translation, false otherwise
*
* @api
*/
function hasStrict($id, $domain = 'messages');

/**
* Gets a message translation.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/Translator.php
Expand Up @@ -142,7 +142,7 @@ public function transChoice($id, $number, array $parameters = array(), $domain =
$this->loadCatalogue($locale);
}

if (!$this->catalogues[$locale]->has((string) $id, $domain)) {
if (!$this->catalogues[$locale]->hasStrict((string) $id, $domain)) {
// we will use the fallback
$locale = $this->computeFallbackLocale($locale);
}
Expand Down

0 comments on commit 79710ed

Please sign in to comment.