Making .po and .mo files

| No Comments | No TrackBacks
Using CGI::Application::Plugin::I18N

Making .po and .mo files.

Now the the module is released to CPAN I've added a i18n guide on how to make .po and .mo files. Here is a cut down version for my blog:-

Creating .po and .mo files

The .po files are the editable language packs. The .mo files are compiled versions that are a bit faster to use.

I've found a good little app for creating .po and .mo files:- It's cross platform and gives you a nice GUI to work from. Of course you can always edit the .po files direct and generate the .mo files yourself.

Getting the sample files

CGI::Application::Plugin::I18N includes some sample files you can use to test out your .po and .mo files. For this blog post I'll try and make things a bit more general.

Using Poedit

Download and install Poedit. When you open for the first time it'll ask for your name and email, don't worry this is just for stamping the .po files with your details.

Click the File menu, then Preferences and select the Parsers tab. You'll see that there is a Perl parser, select this and then click the Edit button.

You'll see that the list of file extensions only has *.pl, extend this so that is contains *.pl;*.pm;*.cgi and any other extensions you use for your applications Perl files. Click OK and OK again.

Now we are ready to create our first catalog. Click File->New catalog. The details I entered:- Project name: Demo Team: po testers Team email: Language: English Country: United States Charset: UTF-8 Source code charset: UTF-8

Then select the Paths tab, click the little square graphic for new item then input the path to your script files, I've done /tmp/potest

Then select the Keywords tab and add localtext the same way you added the path. If you aren't using my I18N module, then you'd input the name of the function or method that generals the local text, such as maketext, gettext, loc, etc.

Click OK to finish, a dialog will ask you where to save your .po file. I selected /tmp/potest/I18N/en-us.po.

At this point Poedit will search in the paths you selected for files that contain the keyword you input. For me it'll be searching for .pl, .cgi and .pm files and looking for localtext. It'll extract all the text it finds, and provide a list of strings that need translating. You should get a window titled Update summary appear with a list of all the strings. Click OK.
(If it doesn't find any you'll get an error)

If you change any of your files to include new localized strings then all you need do is click on the globe icon at the top and it'd parse the files again for new strings.

Enter in your translations. Now click the save icon. The .mo compiled version of this file is generated automatically on each save.


No TrackBacks

TrackBack URL:

Leave a comment

About this Entry

This page contains a single entry by Lyle published on January 16, 2009 2:37 PM.

Packaging CPAN modules from Windows in Linux Style was the previous entry in this blog.

Useful firefox search hack is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.