Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Internationalization of cakephp site

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 201
    Comment on it

    Internationalization of cakephp site:

    STEP 1) Write the following code in cakePhp routes.php file

                       array('language' => '[a-z]{3}'));

    STEP 2) Write the following configuration ie for setting default language in config/bootstrap.php file

     Configure::write('Config.language', 'eng');

    STEP 3) Now set the language on page load or click on links- WRITE THE CODE IN controller/appController.php

    STEP 3.1) Use the components

     public $components = array('Cookie','Session');

    STEP 3.2)

     public function beforeFilter() {
            private function _setLanguage() {
                        if ($this->Cookie->read('lang') && !$this->Session->check('Config.language')) { //if cookies and session already set
                            $this->Session->write('Config.language', $this->Cookie->read('lang'));
                        } //if the user clicked the language URL 
                        else if (   isset($this->params['language']) && ($this->params['language'] !=  $this->Session->read('Config.language'))) {
                                    //then update the value in Session and the one in Cookie
                            $this->Session->write('Config.language', $this->params['language']);
                            $this->Cookie->write('lang', $this->params['language'], false, '20 days');

    STEP 4) Create a folder 'eng' in app/locale/eng Create a .po file there by any domain name for ex- if it is for signup page name the file signup.po if for registration the name it registration.po if you wants to make a common file for all the constants you can name it default.php

    lets say it is default.po:

    msgid "hello"
    msgstr "Buna ziua"
    msgid "hello DINESH"
    msgstr "Buna ziua dinesh SINGH RAWAT"

    STEP 5) Write the following code in yo .ctp file

      echo $this->Html->link('English', array('language'=>'eng')); 
      echo $this->Html->link('Franais', array('language'=>'fre')); 
      echo '******';
         echo _&#95;('hello DINESH');

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: