mla12 has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to localize a module. I'm using Locale::TextDomain and Dist::Zilla::LocalTextDomain to manage it.

The module is available at https://github.com/mla/time-ago

I've added a French translation but I can't seem to trigger the translation.

I'm following this tutorial: http://perladvent.org/2013/2013-12-09.html

Compiling of the .po files seems to work fine:

$ dzil msg-compile po/fr.po [LocaleTextDomain] po/fr.po: 9 translated messages, 2 untranslated mes +sages.

But then I try to test it using the example from the tutorial, and I get English:

$ LANGUAGE=fr perl -Ilib -CAS -I. ./try about 3 hours

Here's the script:

#!/usr/bin/env perl use strict; use Time::Ago; print Time::Ago->in_words(3600 * 3.2), "\n";

Here's the .po translation that should apply there:

#: lib/Time/Ago.pm:47 #, perl-brace-format msgid "about {count} hour" msgid_plural "about {count} hours" msgstr[0] "environ une heure" msgstr[1] "environ {count} heures"

What am I missing?

Replies are listed 'Best First'.
Re: getting Locale::TextDomain working
by Anonymous Monk on Jul 08, 2015 at 08:53 UTC
      Also "LANGUAGE=fr" seems like ... where did you come up with that? I don't see "LANGUAGE=" in the main docs, but I do see it here (among other steps to try) https://metacpan.org/pod/distribution/libintl-perl/lib/Locale/libintlFAQ.pod#How-do-I-switch-languages-or-force-a-certain-language-independently-from-user-settings-read-from-the-environment

      I got that from the Dist::Zilla::LocaleTextDomain tutorial: http://perladvent.org/2013/2013-12-09.html

      In the "Lost in Translation" section, it says:

      One more thing, a note for translators. They can, of course, also use msg-scan and msg-merge to update the catalogs they're working on. But how do they test their translations? Easy: use the msg-compile command to compile a single catalog:
      % dzil msg-compile po/fr.po [LocaleTextDomain] po/fr.po: 195 translated messages.
      The resulting compiled catalog will be saved to the LocaleData subdirectory of the current directory, so it's easily available to your app for testing. Just be sure to tell Perl to include the current directory in the search path, and set the $LANGUAGE environment variable for your language. For example, here's how I test the Sqitch French catalog:
      % dzil msg-compile po/fr.po [LocaleTextDomain] po/fr.po: 148 translated messages, 36 fuzzy tra +nslations, 27 untranslated messages. % LANGUAGE=fr perl -Ilib -CAS -I. bin/sqitch foo "foo" n'est pas une commande valide

      I did try some of the other FAQ techniques without luck. I'll go through it again tonight and look for any internal debugging support.

        It turned out to be a missing directive from the dist.ini

        You must have share_dir = lib in order for the last examples to work.

        [LocaleTextDomain] share_dir = lib