Skip to content

Commit

Permalink
Fixing RouteTranslator
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Sep 22, 2015
1 parent 9a86937 commit 24e2387
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions src/Utilities/RouteTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function getTranslatedRoute(
public function getRouteNameFromPath($uri, $locale)
{
$attributes = Url::extractAttributes($uri);
$uri = str_replace([url(), "/$locale/"], ['', ''], $uri);
$uri = str_replace([url(), "/$locale/"], '', $uri);
$uri = trim($uri, '/');

foreach ($this->translatedRoutes as $route) {
Expand Down Expand Up @@ -245,9 +245,16 @@ private function translate($key, $locale = null)
}

$translation = $this->translator->trans($key, [], '', $locale);
$this->checkTranslation($key, $locale, $translation);

return $translation;
// @codeCoverageIgnoreStart
if ( ! is_string($translation)) {
throw new InvalidTranslationException(
"The translation key [$key] for locale [$locale] should return a string value."
);
}
// @codeCoverageIgnoreEnd

return (string) $translation;
}

/* ------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -276,24 +283,4 @@ public function hasTranslation($key, $locale = null)
{
return $this->translator->has($key, $locale);
}

/**
* Check the translation.
*
* @param string $key
* @param string $locale
* @param mixed $translation
*
* @throws InvalidTranslationException
*/
private function checkTranslation($key, $locale, $translation)
{
// @codeCoverageIgnoreStart
if ( ! is_string($translation)) {
throw new InvalidTranslationException(
"The translation key [$key] for locale [$locale] should return a string value."
);
}
// @codeCoverageIgnoreEnd
}
}

0 comments on commit 24e2387

Please sign in to comment.