There is some pod buried deep in Locale::Maketext::Lexicon::Gettext. You have 
to use different syntax in the .po file. If anybody’s interested, the following 
simple example does work:

{ package Lexicon;

  use base 'Locale::Maketext';
  use Locale::Maketext::Lexicon {
      fr => ['Gettext' => "hello_fr2.po" ],
  };

  sub xxx { print "Hello!"; return "hello"; }

  1;

}

my $l = Lexicon->get_handle( 'fr' );

print $l->maketext( "Hello" ) . "\n";

print $l->maketext( "Nuts" ) . "\n";

The .po file:

msgid "Hello"
msgstr "Bonjour"

msgid "Goodbye"
msgstr "Au revoir"

msgid "Nuts"
msgstr "Bolts %xxx()"

Output:

Bonjour
Hello!Bolts hello

Regards

Duncan
From: Duncan Garland [mailto:duncan.garl...@motortrak.com]
Sent: 06 October 2011 16:09
To: The elegant MVC web framework
Subject: RE: [Catalyst] Localisation

Hi Chakkit,

Thanks for your reply.

We do have a medium sized Catalyst application which we may well want to 
internationalise at some point, but at the moment I’m looking for a solution 
which can be applied to some other non-Catalyst applications.

I posted my question here because I got the idea of using Locale::Maketext and 
Locale::Maketext::Lexicon from the articles referenced on the Catalyst 
localisation man page. Specifically, there is an article by Audrey Tang which 
gives an example which seems to do exactly what we want. (Multiple .po files 
per language which are searched in order and the ability to include some 
functions.) I also got the impression that these modules are commonly used 
within the Catalyst community.

Unfortunately, I can’t make the example code work and I can’t find a better 
example.

I’ve had the debugger on the code for a while since I made my first post.

The problems are:


1)      The square brackets are escaped with a tilde to become ~[ or ~] when 
they are read in. That applies to both the msgid and the msgstr.

2)      The code which compiles the subroutine does recognise ~ but treats it 
as escaping the bracket. Thus the in_group flag is never set and it never 
constructs or executes the function. If I use the debugger to remove the 
tildes, the function is built and executed.

3)      The article implies that you declare a function as fr::xxx and call it 
as xxx. In fact, if it is declared as fr::xxx it must be called as fr::xxx.

I’ve run out of ideas.

All the best.

Duncan
From: Chakkit Ngamsom [mailto:chak...@ibiz.co.th]
Sent: 06 October 2011 15:06
To: The elegant MVC web framework
Subject: Re: [Catalyst] Localisation

Hi Duncan,

You should use Plugin here:
http://search.cpan.org/dist/Catalyst-Plugin-I18N/lib/Catalyst/Plugin/I18N.pm

Check at configuration section if you want to specify directory for .po files 
or elsr.

Regards,
Chakkit

On Oct 6, 2011, at 7:39 PM, Duncan Garland 
<duncan.garl...@motortrak.com<mailto:duncan.garl...@motortrak.com>> wrote:
Hi,

Has any anybody got a working example of the use of Locale::Maketext with 
Locale::Maketext::Lexicon? I think I’ve missed something simple. My example 
code is:

{ package Lexicon;

  use base 'Locale::Maketext';
  use Locale::Maketext::Lexicon {
      fr => ['Gettext' => "hello_fr2.po" ],
  };

  sub fr::xxx { print "Hello!"; return "hello"; }

  1;

}

my $l = Lexicon->get_handle( 'fr' );

print $l->maketext( "Hello" ) . "\n";

print $l->maketext( "Nuts ~[xxx~]" ) . "\n";

The hello_fr2.po contains:

msgid "Hello"
msgstr "Bonjour"

msgid "Goodbye"
msgstr "Au revoir"

msgid "Your search matched [quant,_1,book]"
msgstr "Vous trouvez [ quant, _1, livre ]"

msgid "You are my [ord,_1] something."

msgid "[numf,_1]"
msgstr "[numf,_1]"

msgid "Nuts [xxx]"
msgstr "Bolts [xxx]"

The output is:

Bonjour
Bolts [xxx]

So the simple substitutions work but I can’t get it to call the function. 
Furthermore, it puts tilde before each bracket, so I can’t get a match for 
anything with a function unless I put tildes in there. I’ve missed something 
simple. Any ideas?

Thanks

Duncan


_______________________________________________
List: Catalyst@lists.scsys.co.uk<mailto:Catalyst@lists.scsys.co.uk>
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Reply via email to