Add URL::to_language and HTML::link_to_language localization helpers

Signed-off-by: Anahkiasen <ehtnam6@gmail.com>
This commit is contained in:
Anahkiasen
2012-10-26 22:32:52 +01:00
parent 205cc4869d
commit 89e3bf1fbd
5 changed files with 84 additions and 4 deletions

View File

@@ -294,6 +294,31 @@ class URL {
return static::to($uri, $https);
}
/**
* Get the URL to switch language, keeping the current page or not
*
* @param string $language The new language
* @param boolean $reset Whether navigation should be reset
* @return string An URL
*/
public static function to_language($language, $reset = false)
{
// Get the url to use as base
$url = $reset ? URL::home() : URL::to(URI::current());
// Validate the language
if (!in_array($language, Config::get('application.languages')))
{
return $url;
}
// Get the language we're switching from and the one we're going to
$from = '/'.Config::get('application.language').'/';
$to = '/'.$language.'/';
return str_replace($from, $to, $url);
}
/**
* Substitute the parameters in a given URI.
*