Poedit xgettext parser setup reminder

i18n Add comments

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.

8 Responses to “Poedit xgettext parser setup reminder”

  1. Shetil Says:

    Thank you for the tip!

  2. bfw Says:

    thank you, saved me some head ache.

  3. Simon Says:

    Thanks a lot, very handy tip

  4. Poedit ‘ctp’ is unknown; will try C. | Honk Blog Says:

    [...] G-ROC web applications Cake [...]

  5. Robert Olsson Says:

    Thanks you! This helped me out to parse those .js files containing PHP code. Was about to go crazy there for a while ;=)

  6. Colleen Dick Says:

    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?

  7. Christher Says:

    Thanks for this tips.

  8. Greece Says:

    Thanks! This save me again (re-installed POEdit…). I wonder why POEdit team does not have this setting by default.

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS