dereuromark 9 年之前
父节点
当前提交
c064ae13d6
共有 3 个文件被更改,包括 21 次插入2 次删除
  1. 1 0
      README.md
  2. 17 2
      docs/I18n/I18n.md
  3. 3 0
      docs/README.md

+ 1 - 0
README.md

@@ -32,6 +32,7 @@ This master branch only works for **CakePHP3.x** - please use the 2.x branch for
 - QrCode, Gravatar and other useful small helpers
 - Timeline, Typography, etc provide additional helper functionality.
 - Email as a wrapper for core's Email adding some more usefulness and making debugging/testing easier.
+- I18n language detection and switching
 
 ### Providing 2.x shims
 This plugin for CakePHP 3 also contains some 2.x shims to ease migration of existing applications from 2.x to 3.x:

+ 17 - 2
docs/I18n/I18n.md

@@ -3,6 +3,15 @@
 Internationalization is always tricky as it involves several layers,
 from routing to controller logic and view outputs to URL building and redirecting.
 
+## Basics
+Set up a default language in your configs:
+```php
+	'Config' => [
+		'language' => 'de',
+	],
+```
+Any `Configure::read('Config.language')` or `I18n::locale()` call should return that default language.
+
 ## Session based language switch
 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()`:
@@ -54,16 +63,22 @@ if (!$language) {
 ```
 
 And make sure your routes are all adjusted to accept and parse the language param:
-```php 
+```php
 Router::scope('/', function (RouteBuilder $routes) {
 	$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
 
 	$routes->connect(
 		'/:language/:controller/:action/*',
 		[],
-		['language' => 'en']
+		['language' => 'de']
 	);
 	
 	...
 }
 ```
+
+In this case only `/de/...` is a language param, since `/...` (without any) would continue to use the default language (English).
+
+You can of course also make the regexp here `'language' => 'de|en'` for all languages to be a param in the URL. 
+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.

+ 3 - 0
docs/README.md

@@ -16,6 +16,9 @@ This cake3 branch only works for **CakePHP3.x** - please use the master branch f
 Routing:
 * [Url](Url/Url.md)
 
+I18n:
+* [I18n](I18n/I18n.md) for language detection and switching
+
 ErrorHandler
 * [ErrorHandler](Error/ErrorHandler.md)