Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7817569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:16:10+00:00 2026-06-02T06:16:10+00:00

I finally have my multilingual CakePHP 2.1 app almost working. First, I define the

  • 0

I finally have my multilingual CakePHP 2.1 app almost working.

First, I define the default language at the end of core.php:

/* Define default language */
Configure::write('Config.language', 'eng');

Here is my code in AppControler.php:

public function beforeFilter() {
parent::beforeFilter();
    $this->_setLanguage();
    //Configure::write('Config.language', 'fre'); //Manually change the language to test .po file
    $this->Auth->allow('index','view','home','display','logout');
}

function _setLanguage() {

    if ($this->Cookie->read('lang') && !$this->Session->check('Config.language')) {
        $this->Session->write('Config.language', $this->Cookie->read('lang'));
    }
    else if (isset($this->params['language']) && ($this->params['language']
             !=  $this->Session->read('Config.language'))) {

        $this->Session->write('Config.language', $this->params['language']);
        $this->Cookie->write('lang', $this->params['language'], false, '20 days');
    }
}

If I uncomment Configure::write('Config.language', 'fre'); in AppController.php, the whole site is in French (except database driven content, for which I plan to use TranslateBehavior). However, I want to use URL-based language switching on a button click, and that’s where the app breaks down. Here is my route, based on this nuts-and-bolts tutorial:

Router::connect('/:language/:controller/:action/*', array(), array('language' => '[a-z]{2}'));

Here is my button code:

<?php echo $this->Html->link($this->Html->image('../img/PUZ013-US-Flag.png', array('border' => '0')),array('language'=>'eng'),array('target' => '_parent', 'escape' => false));;?>&nbsp <?php echo $this->Html->link($this->Html->image('../img/PUZ013-FR-Flag.png', array('border' => '0')),array('language'=>'fre'),array('target' => '_parent', 'escape' => false));?>

I have this in AppHelper to handle the URL switching, but it’s not working. The URL should be example.com/fre/controller/action, but instead it is example.com/controller/action/language:fre, and the cookie is not changing.

class AppHelper extends Helper {

  public function url($url = null, $full = false) {
        if(!isset($url['language']) && isset($this->params['language'])) {
          $url['language'] = $this->params['language'];
        }

        return parent::url($url, $full);
   }

}

If you click on the flags, nothing happens. What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:16:12+00:00Added an answer on June 2, 2026 at 6:16 am

    I ended up adding a function to my AppController and calling it in my beforeFilter():

    My beforeFilter() looks like this:

    public function beforeFilter() {
        parent::beforeFilter();
        $this->_checkRoute();
        $this->Auth->allow('index','view','home','display','logout');
    }
    

    Here is the _checkRoute() function:

    function _checkRoute() {
            $params = $this->params['pass'];
            $url = $this->here;
    
            if (strpos($url, 'language:fre')) {
                $this->Session->write('Config.language', 'fre'); 
                Configure::write('Config.language', 'fre');
            }
    
            elseif (strpos($url, 'language:eng')) {
                Configure::write('Config.language', 'eng');
                $this->Session->write('Config.language', 'eng');
            }
    
    }
    

    When a user clicks the language icon button, the individual page is translated. The only remaining issue is that the session unsets when the user clicks on a menu link, as the URL parameter is not maintained. Another puzzle for another day.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I FINALLY have the map and points(arrays) working for my app. Quick question: I
I have a third party library which I finally have working within my MonoTouch
I am testing my app on a rooted Nexus S phone. I finally have
I finally have this working now but would like to know how I can
I have finally quit the idea of learning Zend and instead i find CakePHP
Have finally got a responsive site working (of a fashion). What I want to
After a week of coding finally have my site working across all browsers and
I have finally tracked down a bug that I've been working on for the
I have finally managed to drop working with VFW after several problems I have
I finally have a hardware guy that is insterested in controlling the firmware. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.