Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@monsat
Created October 5, 2011 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monsat/1265854 to your computer and use it in GitHub Desktop.
Save monsat/1265854 to your computer and use it in GitHub Desktop.
CakePHP2.0 i18n sample
public function beforeFilter() {
parent::beforeFilter();
$this->_setLocale();
}
protected function _setLocale() {
if (isset($this->request->query['hl'])) {
CakeSession::write('App.lang', $this->request->query['hl']); // you can use any key instead of 'App.lang'
}
if (CakeSession::read('App.lang')) {
Configure::write('Config.language', CakeSession::read('App.lang'));
}
}
@monsat
Copy link
Author

monsat commented Oct 5, 2011

You can access like this.
/any/page?hl=ja // use japanese
/any/page?hl=en // use english
/any/page?hl // use default language (delete session)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment