1

Let's say I have myscript.tar.gz package generated by h2xs -AX myscript containing bin/myScript.pl and lib/MyPackage/MyModule.pm. Makefile.PL and MANIFEST manualy edited so I'm able to install the package and run myScript.pl.

myscript.pl:

#!/usr/bin/perl
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.

Community
  • 1
  • 1
Kuncík
  • 53
  • 7
  • 1
    I have not used localization, but after a google search I found [`Dist::Zilla::LocaleTextDomain`](https://metacpan.org/pod/Dist::Zilla::LocaleTextDomain). Is this something that you could use? – Håkon Hægland Jun 01 '16 at 16:43
  • 1
    I had no experience with Dist::Zilla so when I tried it the first time before posting the question I failed. But it seems it work thanks. – Kuncík Jun 13 '16 at 10:56
  • Great to hear! Please consider [answering your own question](http://stackoverflow.com/help/self-answer). (Click the blue button `"Answer your question"` below) – Håkon Hægland Jun 13 '16 at 11:09

1 Answers1

1

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:

[LocaleTextDomain]
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.

Kuncík
  • 53
  • 7