dereuromark 9 years ago
parent
commit
088a80223a
1 changed files with 16 additions and 5 deletions
  1. 16 5
      docs/I18n/I18n.md

+ 16 - 5
docs/I18n/I18n.md

@@ -12,10 +12,21 @@ Set up a default language in your configs:
 ```
 ```
 Any `Configure::read('Config.language')` or `I18n::locale()` call should return that default language.
 Any `Configure::read('Config.language')` or `I18n::locale()` call should return that default language.
 
 
-## Session based language switch
+
+## Detecting the user language
 To detect and switch based on language, you can leverage the Language class.
 To detect and switch based on language, you can leverage the Language class.
 Either you manually use `findMatches()` to sort through, or you use the convenience method `findFirstMatch()`:
 Either you manually use `findMatches()` to sort through, or you use the convenience method `findFirstMatch()`:
 ```php
 ```php
+use Tools\Utility\Language;
+
+$language = Language::findFirstMatch(['de', 'en']);
+```
+It will use the language with the highest weight supported by the user agent data provided.
+
+
+## Session based language switch
+In your AppController you can now do:
+```php
 	/**
 	/**
 	 * @return void
 	 * @return void
 	 */
 	 */
@@ -26,7 +37,7 @@ Either you manually use `findMatches()` to sort through, or you use the convenie
 		$language = $this->request->session()->read('Config.language');
 		$language = $this->request->session()->read('Config.language');
 		// Then check the browser preference for the whitelisted languages
 		// Then check the browser preference for the whitelisted languages
 		if (!$language) {
 		if (!$language) {
-			$language = Language::findFirstMatch(['de', 'en']);
+			$language = Language::findFirstMatch(Configure::read('Config.supportedLanguages'));
 		}
 		}
 		// Overwrite the system default
 		// Overwrite the system default
 		if ($language) {
 		if ($language) {
@@ -59,9 +70,7 @@ new `language` param.
  
  
 Switch out the above session check then with
 Switch out the above session check then with
 ```php
 ```php
-if (!$language) {
-	$language = $this->request->getParam('language');
-}
+$language = $this->request->getParam('language');
 ```
 ```
 (before CakePHP 3.4+ it would be `param()`)
 (before CakePHP 3.4+ it would be `param()`)
 
 
@@ -86,6 +95,8 @@ You can of course also make the regexp here `'language' => 'de|en'` for all lang
 Only the root `/` would then be allowed to fallback to the default one.
 Only the root `/` would then be allowed to fallback to the default one.
 In this case you should have a canonical (pointed to the root) on that action to avoid it being treated as duplicate content.
 In this case you should have a canonical (pointed to the root) on that action to avoid it being treated as duplicate content.
 
 
+Now you just have to overwrite `Controller::redirect()` for the controller redirects and `HtmlHelper::link()`/`UrlHelper::build()` etc for the view level URLs generated.
+
 
 
 ## Language vs Locale
 ## Language vs Locale
 A locale is a combination of language and region (usually a country).
 A locale is a combination of language and region (usually a country).