From 49f9eff554185ffd7e66525ba89c3fb25b57dfa3 Mon Sep 17 00:00:00 2001 From: Nikos Gr Date: Wed, 11 Feb 2015 10:44:41 +0200 Subject: [PATCH 1/3] update README.md --- README.md | 90 +++++++++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 09d0ead..ba3aad3 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ It's recommended that you use Composer, however you can download and install fro Laravel Localization comes with a service provider for Laravel. You'll need to add it to your `composer.json` as mentioned in the above steps, then register the service provider with your application. -Open `app/config/app.php` and find the `providers` key. Add `LaravelLocalizationServiceProvider` to the array. +Open `config/app.php` and find the `providers` key. Add `LaravelLocalizationServiceProvider` to the array. ```php ... @@ -58,7 +58,7 @@ Open `app/config/app.php` and find the `providers` key. Add `LaravelLocalization ... ``` -You can also add an alias to the list of class aliases in the same app.php +You can also add an alias to the list of class aliases in the same file. ```php ... @@ -68,12 +68,12 @@ You can also add an alias to the list of class aliases in the same app.php ## Usage -Laravel Localization uses the URL given for the request. In order to achieve this purpose, a group should be added into the routes.php file. It will filter all pages that must be localized. +Laravel Localization uses the URL given for the request. In order to achieve this purpose, a route group should be added into the `routes.php` file. It will filter all pages that must be localized. ```php - // app/routes.php + // app/Http/routes.php - Route::group(array('prefix' => LaravelLocalization::setLocale()), function() + Route::group(['prefix' => LaravelLocalization::setLocale()), function() { /** ADD ALL LOCALIZED ROUTES INSIDE THIS GROUP **/ Route::get('/', function() @@ -84,13 +84,13 @@ Laravel Localization uses the URL given for the request. In order to achieve thi Route::get('test',function(){ return View::make('test'); }); - }); + }]; /** OTHER PAGES THAT SHOULD NOT BE LOCALIZED **/ ``` -Once this group is added to the routes file, a user can access all locales added into 'supportedLocales' ('en' and 'es' by default, look at the config section to change that option). For example, a user can now access to two different locales, using the following addresses: +Once this route group is added to the routes file, a user can access all locales added into `supportedLocales` ('en' and 'es' by default, look at the config section to change that option). For example, a user can now access two different locales, using the following addresses: ``` http://url-to-laravel/en @@ -98,19 +98,19 @@ Once this group is added to the routes file, a user can access all locales added http://url-to-laravel ``` -If the locale is not present in the url or it is not defined in 'supportedLocales', the system will use the application default locale or the user's browser default locale (if defined in config file). +If the locale is not present in the url or it is not defined in `supportedLocales`, the system will use the application default locale or the user's browser default locale (if defined in config file). Once the locale is defined, the locale variable will be stored in a session, so it is not necessary to write the /lang/ section in the url after defining it once, using the last known locale for the user. If the user accesses to a different locale this session value would be changed, translating any other page he visits with the last chosen locale. -Templates files and all locale files should follow the [Lang class](http://laravel.com/docs/localization). +Template files and all locale files should follow the [Lang class](http://laravel.com/docs/5.0/localization). ### Middleware -Moreover, this package includes a middleware obkect to redirect all "non-localized" routes to a "localized" one. +Moreover, this package includes a middleware object to redirect all "non-localized" routes to the corresponding "localized". -So, if a user accesses to http://url-to-laravel/test and the system have this middleware actived and 'en' as a current locale for this user, it would redirect (301) him automatically to http://url-to-laravel/en/test. This is mainly used to avoid duplicate content and improve SEO performance. +So, if a user navigates to http://url-to-laravel/test and the system has this middleware active and 'en' as the current locale for this user, it would redirect (301) him automatically to http://url-to-laravel/en/test. This is mainly used to avoid duplicate content and improve SEO performance. -To do so, you have to register the middleware on the app/Http/Kernel.php laravel file like this: +To do so, you have to register the middleware in the `app/Http/Kernel.php` file like this: ```php LaravelLocalization::setLocale(), 'middleware' => [ 'localizationRedirect' ] - ), + ], function() { /** ADD ALL LOCALIZED ROUTES INSIDE THIS GROUP **/ @@ -159,11 +159,11 @@ To do so, you have to register the middleware on the app/Http/Kernel.php laravel ``` -In order to active it, you just have to attach this middleware to the routes you want to be accessible localized. +In order to activate it, you just have to attach this middleware to the routes you want to be accessible localized. -If you want to hide the default locale but always show other locales in the url, switch the 'hideDefaultLocaleInURL' config value to true. Once it's true, if the default locale is en (english) all URLs containing /en/ would be redirected to the same url without this fragment '/' but maintaining the locale as en (English). +If you want to hide the default locale but always show other locales in the url, switch the `hideDefaultLocaleInURL` config value to true. Once it's true, if the default locale is en (english) all URLs containing /en/ would be redirected to the same url without this fragment '/' but maintaining the locale as en (English). -**IMPORTANT** - When hideDefaultLocaleInURL is set to true, the unlocalized root is treated as the applications default locale ```app.locale```. Because of this language negotiation using the Accept-Language header will **NEVER** occur when hideDefaultLocaleInURL is true. +**IMPORTANT** - When `hideDefaultLocaleInURL` is set to true, the unlocalized root is treated as the applications default locale `app.locale`. Because of this language negotiation using the Accept-Language header will **NEVER** occur when `hideDefaultLocaleInURL` is true. ## Helpers @@ -254,9 +254,9 @@ This function will return all supported locales and their properties as an array ```php /** * Returns supported languages language key - * + * * @return array keys of supported languages - */ + */ public function getSupportedLanguagesKeys() //Should be called like this: @@ -284,7 +284,7 @@ This function will return an array with all the keys for the supported locales. This function will change the application's current locale. If the locale is not passed, the locale will be determined via a cookie (if stored previously), the session (if stored previously), browser Accept-Language header or the default application locale (depending on your config file). -The function have to be called in the prefix of any route that should be translated (see Filters sections for further information). +The function has to be called in the prefix of any route that should be translated (see Filters sections for further information). ### Get Current Locale Name @@ -301,7 +301,7 @@ The function have to be called in the prefix of any route that should be transla {{ LaravelLocalization::getCurrentLocaleName() }} ``` -This function will return current locale name as string (English/Spanish/Arabic/ ..etc). +This function will return current locale's name as string (English/Spanish/Arabic/ ..etc). ### Get Current Locale Direction @@ -318,7 +318,7 @@ This function will return current locale name as string (English/Spanish/Arabic/ {{ LaravelLocalization::getCurrentLocaleDirection() }} ``` -This function will return current locale direction as string (ltr/rtl). +This function will return current locale's direction as string (ltr/rtl). ### Get Current Locale Script @@ -340,7 +340,7 @@ This function will return the [ISO 15924](http://www.unicode.org/iso15924) code ## Creating a language selector -If you're supporting multiple locales in your project your going to want to provide the users with a way to change language. Below is a simple example of blade template code you can use to create your own language selector. +If you're supporting multiple locales in your project you will probably want to provide the users with a way to change language. Below is a simple example of blade template code you can use to create your own language selector. ```