|
|
@@ -10,7 +10,7 @@ Set up a default language in your configs:
|
|
|
'language' => 'de',
|
|
|
],
|
|
|
```
|
|
|
-Any `Configure::read('Config.language')` or `I18n::locale()` call should return that default language.
|
|
|
+Any `Configure::read('Config.language')` or `I18n::getLocale()` call should return that default language.
|
|
|
|
|
|
|
|
|
## Detecting the user language
|
|
|
@@ -36,7 +36,7 @@ In your AppController you can now do:
|
|
|
parent::initialize();
|
|
|
|
|
|
// First check the session
|
|
|
- $language = $this->request->session()->read('Config.language');
|
|
|
+ $language = $this->request->getSession()->read('Config.language');
|
|
|
// Then check the browser preference for the whitelisted languages
|
|
|
if (!$language) {
|
|
|
$language = Language::findFirstMatch(Configure::read('Config.supportedLanguages'));
|
|
|
@@ -44,18 +44,18 @@ In your AppController you can now do:
|
|
|
// Overwrite the system default
|
|
|
if ($language) {
|
|
|
Configure::write('Config.language', substr($language, 0, 2));
|
|
|
- I18n::locale($language);
|
|
|
+ I18n::setLocale($language);
|
|
|
}
|
|
|
```
|
|
|
|
|
|
You then just need a switch on the website that allows the other to change the language (by writing it into the session):
|
|
|
```php
|
|
|
-<?php if (Configure::read('Config.language') === 'de') {
|
|
|
+<?php if ($this->Configure->read('Config.language') === 'de') {
|
|
|
echo $this->Html->image('flag_de.png', ['title' => __('German')]);
|
|
|
} else {
|
|
|
echo $this->Form->postLink($this->Html->image('flag_de.png'), ['prefix' => false, 'plugin' => 'Tools', 'controller' => 'ShuntRequest', 'action' => 'language', 'de'], ['block' => true, 'escape' => false, 'title' => __('German')]);
|
|
|
} ?>
|
|
|
-<?php if (Configure::read('Config.language') === 'en') {
|
|
|
+<?php if ($this->Configure->read('Config.language') === 'en') {
|
|
|
echo $this->Html->image('flag_en.png', ['title' => __('English')]);
|
|
|
} else {
|
|
|
echo $this->Form->postLink($this->Html->image('flag_en.png'), ['prefix' => false, 'plugin' => 'Tools', 'controller' => 'ShuntRequest', 'action' => 'language', 'en'], ['block' => true, 'escape' => false, 'title' => __('English')]);
|
|
|
@@ -63,6 +63,7 @@ You then just need a switch on the website that allows the other to change the l
|
|
|
```
|
|
|
|
|
|
Make sure you included the routes for the Tools plugin for this to work or set them up manually in the `src/Config/routes.php` file.
|
|
|
+This example also uses [Shim.Configure helper](https://github.com/dereuromark/cakephp-shim) to avoid use statements.
|
|
|
|
|
|
|
|
|
## Using language in URLs
|