Thoughts on translations.
================
When I had to create a new multi-linguage site in Expression Engine I hacked some code I had previously written to replace the translation system in EE, similar to Code Igniter. There are advantages and disadvantages to doing this which I outline below in case my approach is useful to anyone.
There are two elements to developing multi-lingual sites. First is the fixed translations, ie. the labels and text that appears in templates that does not change. Second, there is the dynamic content, in a blog, the blog entries and comments. In a recent blog site I did that currently an english and german version, the templates for both sites are the same, but the content is different - ie. the user does the translation. Using the method below I can view the german site in english or the english site in german by using google to (badly) translate the blog entries.
My translation system:
Translations are held in a database table:
+-------------+---------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------------------+------+-----+---------+----------------+
| phrase_id | int(11) | | PRI | NULL | auto_increment |
| phrase | varchar(25) | | MUL | | |
| lang_id | varchar(6) | | | en_gb | |
| say_text | mediumtext | YES | | NULL | |
| status | enum('OK','auto','Check') | YES | | auto | |
| userlevel | int(1) | | | 0 | |
| usedin | mediumtext | | | | |
| screen_name | varchar(50) | YES | | NULL | |
| last_update | datetime | YES | | NULL | |
+-------------+---------------------------+------+-----+---------+----------------+
and output using a class, eg:
$say->it("DataEntryForm");
or
{lang:DataEntryForm}
The class will first look to see what language to use. The site will have a default language that can be overriden by the users language preference.
It then checks to see if the phrase DataEntryForm exists in the database in the required language. If it doesn’t and the required language is english, then the entry is added with the text “Data Entry Form” (similarly Data_Entry_Form) can be used for the phrase). If the language is not english, it gets a translation from google and puts that in. This is great for development because you can do all your programming work and only then go back and update the translations.
The other advantage is that there is a control panel that can be used by the clients to modify some of the text in the system. This is not intended as a CMS, but for example, I can put a $say->it(“Headlines”) at the top of the index page which allows the client to go and change their headline news that appears on the page.
This database works across the whole system, so there is no need to create separate files for each module or language.
The disadvantage of course is speed because of the hits to the database. I could go one of two ways in improving this. One would be to record the pages where a phrase is used during the development phase so that there is only one call per page to load all the translations. The other is to create a language file as expected by Expression Engine or Code Igniter.
If these thoughts interest anyone am happy to share code…