diff --git a/src/Symfony/Component/Translation/MessageCatalogue.php b/src/Symfony/Component/Translation/MessageCatalogue.php index e83e9f87f2ce..cefc6a18c893 100644 --- a/src/Symfony/Component/Translation/MessageCatalogue.php +++ b/src/Symfony/Component/Translation/MessageCatalogue.php @@ -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]); } diff --git a/src/Symfony/Component/Translation/MessageCatalogueInterface.php b/src/Symfony/Component/Translation/MessageCatalogueInterface.php index 8ade39aa2d62..1025d8d9c6b6 100644 --- a/src/Symfony/Component/Translation/MessageCatalogueInterface.php +++ b/src/Symfony/Component/Translation/MessageCatalogueInterface.php @@ -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. * diff --git a/src/Symfony/Component/Translation/Translator.php b/src/Symfony/Component/Translation/Translator.php index debacb3d2c3f..fb395dedf1eb 100644 --- a/src/Symfony/Component/Translation/Translator.php +++ b/src/Symfony/Component/Translation/Translator.php @@ -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); }