Using DooTranslator for translation
DooTranslator finnaly came out, it supports “Csv“, “Gettext“, “Array“, “Ini” for now, soon it will be implemented other “file types”. So for example you have your translation file with this contents:
en.svn
test;"This is just a test!"
Lets initialize DooTranslator class:
$translator = Doo::translator('Csv', $this->_basePath . 'languages/en/LC_MESSAGES/en.csv');
echo $translator->translate("test");
As you can see its very simple, first argument is file type for translation and second is path to the file, third argument can be options array. For Csv you can set options like: delimiter, enclosure and length. Default value for delimiter is “;” and for enclosure is “.
Now we will add some options to our call, lets say we want some other delimiter then “;” and we want to add some caching.
$translator = Doo::translator('Csv', $this->_basePath . 'languages/en/LC_MESSAGES/main.csv', array('cache' => 'apc', 'delimiter' => '|'));
So now we have added cache mechanism that is “apc” and we added delimiter that is “|”, now in our en.csv we must change delimiter:
test|"This is just a test!"
Supported cache mechanisms are “apc”, “php”, “xcache” and “eaccelerator”.
Now lets add placeholders for translate method:
$translator->translate("Hello [_1], wellcome to my website!", array("John"));
This will show translated string with: “Hello John, wellcome to my website!”.
Ok thats about it, if you have any questions please do ask, this is simple translation class its still in beta so it can be little bugy, try it out and please send me feedback if you find some bugs.


Leng
20 Oct, 2009
This is nice. is the file cache missing?
Milos Kovacki
20 Oct, 2009
Yep its missing I will add it
michael
22 Oct, 2009
is there any simple way to get the translate language?such as ${T’hello’}?
Milos Kovacki
22 Oct, 2009
Well I made function for translating in view files with translate(”something”), but you can make function t in template_tags and translate like t(”something”);
michael
28 Oct, 2009
That’s great!thx a lot!
Leng
5 Dec, 2009
Spanish translation added. Original version at http://eomblog.blogspot.com/2009/11/uso-dootranslator-para-la-traduccion.html
Milos Kovacki
5 Dec, 2009
Great, tnx for translation
Web dev Greece
22 Dec, 2010
Hello
I just downloaded 1.2 and I cannot find this class… Should we use the current SVN code on production sites?
Milos Kovacki
25 Jan, 2011
You must take svn version on https://code.google.com/p/doophp/