Owen Christian and myself have cooked up a nice little code igniter language file translator. This is a controller and series of views that you can drop in on your CI install and then use a nice front end to manage administration of the language files for your application.
This is meant for people to be able to edit the standard application language files in your CI install, which work with the CI Language Class. The basic idea is that you have a master language, and then this allows translators to translate into other languages.
Features
- UTF8 support
- Handles php in language strings
- Synchronises language keys with ‘master’ language
- Checks php for syntax errors
Download
Installation
- Unpack archive
tar -zxvf translator-0.5.tgz
- Copy files into appropriate location in your CI install (or just unpack archive over your install)
- If your language files are in an exotic location, edit config/translator.php
- set language files to be writable by your webserver
- that’s it!
Usage
- (If you haven’t already) Create your master language files and keys e.g.:
language/english/file1_lang.php$lang['file1_some_key'] = 'some key'; $lang['file2_another_key'] = 'another key';
etc. - Create corresponding ‘slave’ language files e.g.:
language/japanese/file1_lang.php
NB You don’t have to create the keys, just the empty writable files - Make sure language files are webserver writable
- Fire up your new controller i.e. index.php/translator and go!
Derek Allard says
Super Nice! I love the simplicity and effectiveness of this. Great work both!
matt says
Hey nice; hope you posted to the CI forums – they’ll love it!
Jan says
Heya,
really nice work and I love to use it, but I don’t want to clutter my app with the translator files, so I created a standalone CI app for the translator and used the config/translator.php file to point it to my actual app’s language dir, but it looks like the config params are never picked up. I started hacking the initialization of the translator controller with not much luck. Is it, and if, how ist it supposed to work?
Cheers
Jan
—
Mr Kirkland says
Looks like we broke the config reading bit with version 0.5.1. Will fix and update.
In the mean time, off the top of my head, around line 172 in the class constructor, this is the array you should change to the path for your language files:
$this->langDirs = array( BASEPATH . 'language', APPPATH . 'language' );
Marc says
great work guys! it’s really amazing.
take care,
marc
qhwa says
Nice work. I really love it!
If variables are wrapped in the language file, there will be some errors.
e.g. in freakauth language file:
[code]$lang[‘FAL_activation_email_body_message’] =
‘Thank you for your new member registration.
To activate your new account, please visit the following URL in the next 24 hours:’;[/code]
then in the tranlator interface, there will be an error message:
[code]Entry cannot be blank. Defaulted to master translation.
Mismatch – does not exist in master translation[/code]
If i submit the form without filling the input filed above the message, I will get none error message but the page refreshed (the same before I post). I checked the ‘translator’ controller and found why.
in the index function:
[code]elseif ( $this->validated && $this->input->post(‘SaveLang’) ) {
$this->data[‘page_content’] = ‘translator/saveLang’;
$this->data[‘page_title’] = ‘Confirm’;
}
else {
$this->data[‘page_content’] = ‘translator/translateLang’;
$this->data[‘page_title’] = ‘Translate ‘ . $this->langModule;
}[/code]
the logic is not exactly right, if I post but failed in validation.
hope these are helpful for you.