3

I get these warning messages when I start my program:

Name "AAT::Translation::I18N::en_us::Lexicon" used only once: possible typo at /usr/share/perl/5.12/Locale/Maketext.pm line 404.
Name "Win32::Locale::Lexicon" used only once: possible typo at /usr/share/perl/5.12/I18N/LangTags/Detect.pm line 140.

My program uses a module with Locale::Maketext::Simple:

use Locale::Maketext::Simple(
  Path => '/usr/share/aat/Translations/'
);

This directory contains my *.po files (en.po, fr.po ...)

I didn't get any warnings before using Perl 5.12/Locale::Maketext::Simple 0.21...

Any ideas how can I fix that ?

Edit 1: The full code

package AAT::Translation;

use strict;
use warnings;
use Readonly;

use AAT::Utils qw( NULL );

my %AAT_Translation = ();

use Locale::Maketext::Simple(
  Path => '/usr/share/aat/Translations/'
);

sub Init
{
  my $lang = shift;

  loc_lang($lang);
  $AAT_Translation{$lang}{'_USER'} = loc("_USER");

  return (1);
}

sub Get
{
  my ($lang, $str) = @_;

  return (undef) if (NULL($str));
  Init($lang) if (!defined $AAT_Translation{$lang}{'_USER'});
  $AAT_Translation{$lang}{$str} = (loc($str) || $str)
    if (!defined $AAT_Translation{$lang}{$str});

  return ($AAT_Translation{$lang}{$str});
}

Edit 2: Of course, if I create a link en_us.po -> en.po, I don't get "AAT::Translation::I18N::en_us::Lexicon" error messages anymore, only the "Win32::Locale::Lexicon" error messages, but that's not an option...

sebthebert
  • 12,196
  • 2
  • 26
  • 37

3 Answers3

2

The warning messages that you are seeing are generated when a variable is used only once. For example:

perl -w -e '$var = "value";'
Name "main::var" used only once: possible typo at -e line 1.

See perldiag for more information.

Locale::Maketext and I18N::LangTags::Detect use the same bit of code as a wrapper around require Modulename, and it is this code that generates the warning. The core Locale::Maketext and I18N::LangTags::Detect modules were fixed with patch v5.13.9-153-g364c63c - see the no warnings 'once' lines:

Summary of changes:
 dist/I18N-LangTags/lib/I18N/LangTags/Detect.pm |    1 +
 dist/Locale-Maketext/lib/Locale/Maketext.pm    |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/dist/I18N-LangTags/lib/I18N/LangTags/Detect.pm b/dist/I18N-LangTags/lib/I18N/LangTags/Detect.pm
index 87280b7..e767aac 100644
--- a/dist/I18N-LangTags/lib/I18N/LangTags/Detect.pm
+++ b/dist/I18N-LangTags/lib/I18N/LangTags/Detect.pm
@@ -136,6 +136,7 @@ sub _try_use {   # Basically a wrapper around "require Modulename"

   my $module = $_[0];   # ASSUME sane module name!
   { no strict 'refs';
+    no warnings 'once';
     return($tried{$module} = 1)
      if %{$module . "::Lexicon"} or @{$module . "::ISA"};
     # weird case: we never use'd it, but there it is!
diff --git a/dist/Locale-Maketext/lib/Locale/Maketext.pm b/dist/Locale-Maketext/lib/Locale/Maketext.pm
index 042ecf7..b429778 100644
--- a/dist/Locale-Maketext/lib/Locale/Maketext.pm
+++ b/dist/Locale-Maketext/lib/Locale/Maketext.pm
@@ -439,6 +439,7 @@ sub _try_use {   # Basically a wrapper around "require Modulename"

     my $module = $_[0];   # ASSUME sane module name!
     { no strict 'refs';
+        no warnings 'once';
         return($tried{$module} = 1)
         if %{$module . '::Lexicon'} or @{$module . '::ISA'};
         # weird case: we never use'd it, but there it is!

--

The standalone version of Locale::Maketext 1.19 includes this patch. However, the standalone version of I18N::LangTags::Detect does not appear to include the patch. I think that this means that you need to need to upgrade your copy of Perl to get the latest core I18N::LangTags::Detect. It may be possible to update a single core module, but I don't know enough about it to say for sure - these questions might help:

How can I safely compile a Perl 5.12 module for Perl 5.8.9?
How can I install a CPAN module that is in the latest perl, without installing the new perl?

Community
  • 1
  • 1
Mike
  • 21,301
  • 2
  • 42
  • 65
1

From your description and Mike's answer, it sounds like you are dealing with some new warnings that came about from some changes to what constitutes a 'used only once' warning in Perl.

Short of upgrading to a version of the module that does not warn (if it exists for your version of perl), you can silence the particular problem warnings. Just replace the use Locale::... line in your code with the following:

BEGIN {
    local $SIG{__WARN__} = sub {
        warn @_ unless "@_" =~ /used only once/;
    };
    require Locale::Maketext::Simple;
    Locale::Maketext::Simple->import(
        Path => '/usr/share/aat/Translations/'
    );
}
Eric Strom
  • 39,821
  • 2
  • 80
  • 152
  • It was a good idea and kind of answer I was looking for, but it doesn't work ! :( – sebthebert Aug 23 '11 at 22:37
  • Hmm, that would mean that the warning is being thrown at runtime rather than at compile time as I had hoped. Setting the warning handler without localizing it is not the best practice, as now it will silence all `used only once` warnings, and not just the ones from Locale::Maketext::Simple. But if adequately documented as to why it is in place, and removed once no longer needed, it could solve your problem. – Eric Strom Aug 24 '11 at 22:03
0

Well, from the information your giving, it is hard to give you an answer.

I would recommend using Locale::Maketext over Locale::Maketext::Simple any day if I had the choice. But, of course, I'm not sure if you do have the choice. Could you please edit your post with your full code? Or most of your code? It would help a lot when answering this question.

Dynamic
  • 921
  • 1
  • 12
  • 31
  • @sebthebert: I am sorry to say I cannot tell you what is wrong. Y our best bet would be posting this on http://www.perlmonks.org/. – Dynamic Aug 23 '11 at 02:33