This is more or less a reminder to myself. Since there do not seem to be many sources about this exact issue and I had to search for it a couple of times already I thought it might be nice to have it up on my own blog.
Working on many international project I’ve been using Poedit for a while now. Poedit is an editor for gettext catalogs (.po files). To gether with PHP and the gettext extension it’s a great tool to implement multilingual web applications.
The issue is that you can set up a parsers in Poedit, basically definitions of file types and command line parameters for xgettext, which is executed fo find the parts in a file that should be translated. So there is a parser for PHP in there, but often, for example in the CakePHP framework, you have to deal with files that are PHP files, but that have a different extension, in the CakePHP case views end with .thtml … Just adding “*.thtml” to the list of extensions in the PHP parser setup does not cut the mustard and you end up getting an error message like this:
xgettext: warning: file ‘[...].thtml’ extension ‘thtml’ is unknown; will try C.
To solve this, you need to tell xgettext that it has to deal with PHP files by adding “–language=PHP” to the list of commandline options. This is done by opening Poedit’s preferences and navigating to the parsers section there. In the PHP parser under “Parser command” (btw. this is the MAC version of Poedit) I have now the following line:
xgettext --language=PHP --force-po -o %o %C %K %F
Voila, .thtml files or any file specified in the PHP parser is now treated as PHP and my translation sections are found.
Thanks to Vaclav for his answer here.
June 27th, 2008 at 2:00 pm
Thank you for the tip!
August 25th, 2008 at 7:02 am
thank you, saved me some head ache.
October 10th, 2008 at 1:32 am
Thanks a lot, very handy tip
October 11th, 2008 at 8:05 am
[...] G-ROC web applications Cake [...]
December 10th, 2008 at 9:53 am
Thanks you! This helped me out to parse those .js files containing PHP code. Was about to go crazy there for a while ;=)
January 29th, 2009 at 12:41 pm
Thanks this was very helpful. Stumbled.
Now for my question its more of a workflow or best practices question. supposed you have a lot of exposition already written in the native tongue and stored in static html files.
for i18n the objective is to have
translate(_(‘About Us Para I’)); ?> in the presentation template where formerly a big paragraph was and move the big paragraph into the catalog.
What is the best practice to make it easy for the developer to do this. Here is my stab.
I’m inserting a line of code like the above in the templates, before each text item I want to translate. Then I update the catalog so it will extract and merge all the new keys. then using the source file to cut the original text out of the templates and paste it nto the catalog. When I give it to a translator I will have to give him the native language catalog and he will have 2 poedits open at once so he can see what the actual text is that he is suppose to translate. Does this make sense or is there an easier way?
March 14th, 2009 at 2:46 am
Thanks for this tips.
March 28th, 2010 at 12:00 pm
Thanks! This save me again (re-installed POEdit…). I wonder why POEdit team does not have this setting by default.