Last active
December 16, 2015 10:49
-
-
Save chrisvogt/5423043 to your computer and use it in GitHub Desktop.
A stab at user language localization by `User.user_lang`, a passed query param, or a stored session variable. This belongs in your AppController and should be called from the beforeFilter() method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Language Handler. | |
| * | |
| * Sets the app's configured language based on passed parameter or language | |
| * configuration stored in session variable. | |
| * | |
| * @author C1V0 | |
| */ | |
| protected function _langHandler() { | |
| if (!$this->Auth->User('user_lang')) { // If user language preference not set... | |
| if (isset($this->request->query['lang'])) { // Set session variable by query param | |
| $this->Session->write('Config.language', $this->request->query['lang']); | |
| } | |
| } else { // Use the user's language preference | |
| $this->Session->write('Config.language', $this->Auth->User('user_lang')); | |
| } | |
| // Set the language! | |
| if ($this->Session->check('Config.language')) { // Localize based on session variable | |
| Configure::write('Config.language', $this->Session->read('Config.language')); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment