diff --git a/laravel/documentation/urls.md b/laravel/documentation/urls.md index 4263712f..8c03f9b1 100644 --- a/laravel/documentation/urls.md +++ b/laravel/documentation/urls.md @@ -59,6 +59,17 @@ Sometimes you may need to generate a URL to a named route, but also need to spec $url = URL::to_action('user@profile', array($username)); + +## URLs To A Different Language + +#### Generating a URL to the same page in another language: + + $url = URL::to_language('fr'); + +#### Generating a URL to your home page in another language: + + $url = URL::to_language('fr', true); + ## URLs To Assets diff --git a/laravel/documentation/views/html.md b/laravel/documentation/views/html.md index aabe244d..dcdb253f 100644 --- a/laravel/documentation/views/html.md +++ b/laravel/documentation/views/html.md @@ -87,6 +87,17 @@ For example, the < symbol should be converted to its entity representation. Conv echo HTML::link_to_action('user@profile', 'User Profile', array($username)); + +## Links To A Different Language + +#### Generating a link to the same page in another language: + + echo HTML::link_to_language('fr'); + +#### Generating a link to your home page another language + + echo HTML::link_to_language('fr', true); + ## Mail-To Links @@ -119,7 +130,7 @@ The "mailto" method on the HTML class obfuscates the given e-mail address so it echo HTML::ol(array('Get Peanut Butter', 'Get Chocolate', 'Feast')); echo HTML::ul(array('Ubuntu', 'Snow Leopard', 'Windows')); - + echo HTML::dl(array('Ubuntu' => 'An operating system by Canonical', 'Windows' => 'An operating system by Microsoft')); diff --git a/laravel/html.php b/laravel/html.php index 211e4022..c53db632 100644 --- a/laravel/html.php +++ b/laravel/html.php @@ -238,6 +238,19 @@ class HTML { return static::link(URL::to_action($action, $parameters), $title, $attributes); } + /** + * Generate an HTML link to a different language + * + * @param string $language + * @param string $title + * @param array $attributes + * @return string + */ + public static function link_to_language($language, $title = null, $attributes = array()) + { + return static::link(URL::to_language($language), $title, $attributes); + } + /** * Generate an HTML mailto link. * @@ -347,7 +360,7 @@ class HTML { return '<'.$type.static::attributes($attributes).'>'.$html.''.$type.'>'; } - + /** * Generate a definition list. * @@ -360,13 +373,13 @@ class HTML { $html = ''; if (count($list) == 0) return $html; - + foreach ($list as $term => $description) { $html .= '