CodeIgniter Forums

Full Version: Language in CI
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]xerosis[/eluser]
I think the language Class and Helper documentation in CI are not as clear as the other sections for example it says and I quote:

"Loading A Language File

In order to fetch a line from a particular file you must load the file first. Loading a language file is done with the following code: $this->lang->load('filename', 'language');"

What is that file supposed to me? XML? CSV? ... How are items supposed to be placed in that file.

Does anyone know where we can see best practice tutorial or examples, none are given in the documentations.

El Forum

[eluser]Aken[/eluser]
There are default language files in the system directory that you can use as reference for creating your own.

El Forum

[eluser]xerosis[/eluser]
Yes. Those are system messages.
But I need a quicker way of doing localization of the whole website.

For example an excel file that shows all the sentences (on my website) in English and in Arabic.

Sentences such as:
"World class distribution of items"
"Welcome to the offical website of ABC company"
...

Non System sentences. All in an excel file that loads and based on language is used.

El Forum

[eluser]Aken[/eluser]
The language library is built to accept config files just like the ones in the system directory. If you want to use CI's out of the box functionality, that's the type of language files you'll need to generate -- PHP files for each language containing a $lang array with key => value assignments.

If you want to use another file format to specify your translations, you should either extend and adjust the Language library adding your own functionality, or create your own completely separate library from scratch.

El Forum

[eluser]xerosis[/eluser]
Is there not an easier way rather than having to write something like this for every single item:
$lang['db_unable_to_select'] = 'Unable to select the specified database: %s';

There needs to be a way to do it through XML or CSV.

El Forum

[eluser]PhilTem[/eluser]
There's no CI built-in way of doing it with XML or CSV.

And what would be the difference? Only the markup language would change, but you would be writing similar lines of code for XML. Just CSV might be faster, but can be a pain in the you-know-where reading it properly if there's just one typo or misplaced comma Wink

By the way: There's copy-paste, so you can copy $lang[''] = ''; and past it into the next line Wink

El Forum

[eluser]xerosis[/eluser]
"By the way: There’s copy-paste, so you can copy $lang[’‘] = ‘’; and past it into the next line"

LOL! How could I forget Big Grin

Thanks for the help though.

El Forum

[eluser]Aken[/eluser]
[quote author="xerosis" date="1359015899"]Is there not an easier way rather than having to write something like this for every single item:
$lang['db_unable_to_select'] = 'Unable to select the specified database: %s';

There needs to be a way to do it through XML or CSV.[/quote]
Not using default CI functionality, no. You'll need to write your own code for that. It shouldn't take much work if you just want to pull info from a file and create the $lang array with it.

El Forum

[eluser]Unknown[/eluser]
xerosis,

I did not understand what did you do to solve your problem...

Did you create your own file, like "mywebsite.php" and added your lines of translate, like

$lang['add_new_product'] = "Your product %s was sucessfull added.";


Am I right?