Kuncík Kuncík - 1 year ago 56
Perl Question

How to localize perl package (tar.gz)

Let's say I have

package generated by
h2xs -AX myscript
manualy edited so I'm able to install the package and run


use strict;
use warnings;
use MyPackage::MyModule;

my $generator = MyPackage::MyModule->new();
my $value = $generator->getValue();

#And the message to be translated/localized
print "Obtained value was $value";

How do I localize my package?

I read this: How can I add internationalization to my Perl script? and alike, but it's sort of outdated. I also tried example from libintrl-perl, but I'm not wise from it and couldn't make it work.


Thanks to @Håkon:

Solution: Dist:Zilla - instead of h2xs approach.

In case of using Debian these packages are neccessary: libdist-zilla-perl libdist-zilla-localetextdomain-perl libdist-zilla-plugin-localemsgfmt-perl

First start with dzil init

$ dzil setup

Next create a new package:

$ dzil new myscript

then basically follow Dist::Zilla::LocaleTextDomain and use this in a script/module to be translated:

use Locale::TextDomain "myscript";
#and format strings like this:
print __ "Obtaining value...";
print __x("Obtained value was {value}", value => $value);

add this to dist.ini:

textdomain = myscript

scan for messages/strings to be translated:

$ dzil msg-scan

initialize language translation files:

$ dzil msg-init en us ...

translate *.po files in po/ directory

possibly test:

$ dzil msg-compile po/en.po
$ LANGUAGE=en perl -Ilib -CAS -I. bin/myScript.pl

and remove language test dir after

$ rm LocaleData/ -r

now just create package:

$dzil release 

and enjoy the beautiful .tar.gz package. During the release process Dist::Zilla offers to upload the module to PAUSE, but defaults to not to upload (still figuring out how to prevent the offer).

It's actually more convenient - no MANIFEST to include files just throw them to lib/ and bin/- It's magic! :)

I hope someone else will find this usefull too.