Add URL::to_language and HTML::link_to_language localization helpers
Signed-off-by: Anahkiasen <ehtnam6@gmail.com>
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user