Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on multiple languages website and selected language changed #717

Closed
elbakai opened this issue Nov 12, 2015 · 1 comment
Closed

Error on multiple languages website and selected language changed #717

elbakai opened this issue Nov 12, 2015 · 1 comment

Comments

@elbakai
Copy link
Contributor

elbakai commented Nov 12, 2015

I have a website with a multiple languages (eng, fra, ara), sometimes when i click on the link to switch for example from ara to eng, it dose not work !!! the website redirect to the source language and the current language become img - when i check Configure::read('Config.language') it show img . it work in some pages and not on others, after trying and checking, i found that the problem is caused by broken images, and it's not work just in the pages having a broken images, because broken images give errors like

2015-11-12 00:28:37 Error: [MissingControllerException] Controller class ClientsController could not be found.
Exception Attributes: array (
  'class' => 'ClientsController',
  'plugin' => NULL,
)
Request URL: /laboratory/img/clients/centre-city.jpg

and it take the img as a language's alias, that is why when i check Configure::read('Config.language') it contain img

also when i check beforeFilter at Croogo/Croogo/Controller/CroogoAppController, i found that Configure::read('Config.language') take img as a langague's alias, it can access even there is no locale on the url.

        if (isset($this->request->params['locale'])) {
            Configure::write('Config.language', $this->request->params['locale']);
        }

Solution

So that is why we should check if the current language was defined by the user or not,

        $allLanguges = array("fra", "eng", "ara"); // we should get all languages from the database
        if (isset($this->request->params['locale']) && in_array($this->request->params['locale'], $allLanguges))
        {
            Configure::write('Config.language', $this->request->params['locale']);
        }

and it work fine like that.

@rchavik rchavik added this to the 2.3.1 milestone Dec 6, 2017
@rchavik rchavik removed this from the 2.3.1 milestone Nov 26, 2019
@rchavik
Copy link
Member

rchavik commented Oct 5, 2020

Seems to be ok on 4.x.

@rchavik rchavik closed this as completed Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants