Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use multiple languages in one view in CodeIgniter?

E.g. I will load the languages like (btw. I think only the first of these two, English will be loaded other ignored):

$this->lang->load('module_messages', 'english');
$this->lang->load('module_messages', 'czech');

But I can use only something like this:

echo $this->lang->line('language_key');

THis is not working:

echo $this->lang->line('language_key', 'english');

Any idea how to echo both language translations at the same time in the same view like:

echo $this->lang->line('language_key', 'english');
echo $this->lang->line('language_key', 'czech');

How to achieve such thing?

like image 252
Derfder Avatar asked Mar 26 '13 20:03

Derfder


1 Answers

Unfortunately there is currently no way to do such a thing as the keys are loaded for one language file. It's just not typical to load multiple files.

However, there is a way around it and that is to use a prefix like so:

$this->lang->load('en_module_messages', 'english');
$this->lang->load('cs_module_messages', 'czech');

echo $this->lang->line('en_language_key');
echo $this->lang->line('cs_language_key');

If you name the language files and keys the same they will course conflict. So we add an ISO language prefix to the language files and to the line keys. So that both languages are kept separated allowing you to use them both at the same time.

like image 111
cryptic ツ Avatar answered Sep 28 '22 05:09

cryptic ツ