Making .po and .mo files


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:- http://www.poedit.org 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: not@now.com 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.

Lyle

Copy from http://perl.bristolbath.org/blog/lyle/2009/01/making-po-and-mo-files.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s