Skip to content

Commit

Permalink
Add fallback fparameter to language has function so we can truly chec…
Browse files Browse the repository at this point in the history
…k if the translation exists
  • Loading branch information
bobbybouwmann committed Oct 30, 2015
1 parent 36d05ec commit 59fe9de
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Translator.php
Expand Up @@ -56,11 +56,12 @@ public function __construct(LoaderInterface $loader, $locale)
*
* @param string $key
* @param string $locale
* @param bool $fallback
* @return bool
*/
public function has($key, $locale = null)
public function has($key, $locale = null, $fallback = true)
{
return $this->get($key, [], $locale) !== $key;
return $this->get($key, [], $locale, $fallback) !== $key;
}

/**
Expand All @@ -69,16 +70,19 @@ public function has($key, $locale = null)
* @param string $key
* @param array $replace
* @param string $locale
* @param bool $fallback
* @return string
*/
public function get($key, array $replace = [], $locale = null)
public function get($key, array $replace = [], $locale = null, $fallback = true)
{
list($namespace, $group, $item) = $this->parseKey($key);

// Here we will get the locale that should be used for the language line. If one
// was not passed, we will use the default locales which was given to us when
// the translator was instantiated. Then, we can load the lines and return.
foreach ($this->parseLocale($locale) as $locale) {
$locales = $fallback ? $this->parseLocale($locale) : [$locale];

foreach ($locales as $locale) {
$this->load($namespace, $group, $locale);

$line = $this->getLine(
Expand Down

0 comments on commit 59fe9de

Please sign in to comment.