Question

In my CakePHP 2.4 application, Inside my controller files I set different languages like this:

$this->Session->write('Config.language', "eng");
Configure::write('Config.language', "eng");

I use this in my view files:

echo __("Hello");

But sometimes I need gettext for different languages.

for example I need an output like this inside my ctp file:

Hola    
Bonjour   
Алло    

How can I get this output ?

Only possibility I can think of is:
- Setting Config.language in session
- Making a gettext like this: __("Hello")
- Changing Config.language again
- Making a gettext like this: __("Hello")
- Changing Config.language again
- Making a gettext like this: __("Hello")

But inside view files it is not possible to use SessionHelper's set methods. Only get methods can be used. I don't prefer to use raw PHP session variable like $_SESSION. But I need to get different translations for a string inside my view file.

How can I obtain this ?

Was it helpful?

Solution

__() is only wrapper for I18n::translate.

Use "plain" I18n::translate (language param)

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