Welcome Guest, Not a member yet? Register   Sign In
Two languages at once
#1

[eluser]Loquela[/eluser]
Hi there,

I think this question is different from all the other language-reated questions...

I'm currently working on a multilanguage website that displays all the content on a page in two languages simultaneously.

Basically its a communication tool which allows pairs of users to select their respective languages and the text is displayed at once in both languages (language A and Language B).

The content is a finite list of around 600 unique strings, mainly questions and responses.

Is there a way to use the CI Language class to load TWO languages at once and display the text in both languages? We cannot make any assumptions about the language pair combinations, these would be completely random.

cheers,

L.
#2

[eluser]n0xie[/eluser]
Would be easier to just store the 'translations' into a database with an ID for what language it belongs to. From there it's rather easy to display both languages at once.
#3

[eluser]Jelmer[/eluser]
I took a quick look and I don't see any reason why one couldn't just instantiate a second instance of the language class and load the second language in there.

Try something like this:
Code:
$this->lang_2 = new CI_Language();
// ...becomes CI_Lang for CI2, MY_Lang/MY_Language if you extended it, or MX_Lang when using Modular Seperation
$this->lang->load('questions', 'english');
$this->lang_2->load('questions', 'dutch');

$text_english = $this->lang->line('test');
$text_dutch = $this->lang_2->line('test');

Just remember that if you're using anything that automaticly displays a language line (like the lang() helper function) it'll only work for the first language.

EDIT, Just a thought: a simpler but bit more messier way would be to use prefixes in you language keys so you can load them both into a single language class instance and use lines like this:
Code:
$this->lang->load('questions', 'english');
$this->lang->load('questions', 'dutch');
$prefix_1 = 'en_';
$prefix_2 = 'nl_';
$text_english = $this->lang->line($prefix_1.'test');
$text_dutch = $this->lang->line($prefix_2.'test');
And your language files would look like this:
Code:
$lang['en_question1'] = 'something';
$lang['en_question2'] = 'something else';
#4

[eluser]Loquela[/eluser]
Thanks both,

I think creating the additional language class instance was what I was looking for with my question (thanks Jelma).

But I am also battling with the dilema of the database/resource file option. n0xie, would the database option be your recommendation?

Cheers.
#5

[eluser]n0xie[/eluser]
You could save the output of your database to a language file. It's basically up to you what you find is easier...




Theme © iAndrew 2016 - Forum software by © MyBB