Question

I have to change the current language select system from a form submit to a selectbox ajax submit. So, when the language is changed, I have to return the login labels to change them with javascript (specifically, the username, password and login button labels).

The problem is that, although I change the language successfully, the .po file is already loaded, so it will return to me the previous language.

This is my code:

public function cambiar_idioma($idioma)
{
    $this->Session->write('login.language', $idioma);
    Configure::write('config.language', $idioma);
    $this->set(array(
        'UsuarioLogin' => __("Usuario"), 
        'UsuarioPassword' => __("Contraseña"), 
        'login-button' => __("Ingresar")
    ));
    $this->set('_serialize', array('UsuarioLogin', 'UsuarioPassword', 'login-button'));
}

So, when I change to 'spa', it will set it as the new language, but as the .po files are already loaded, the array will return it in english. And vice-versa. So I suppose I have to load .po files again before the returning array, but I don't know how to do it.

Is there a way to do this?

Was it helpful?

Solution 2

I got a solution, althought not the best one.

I had to use i18n::loadPo() to load the .po file into an array. Not the best solution but at least it worked for me.

OTHER TIPS

Try calling I18n::clear(), not sure if it will do the trick because it will clear the translation domains but you're using __() instead of __d(), give it a try.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top