Skip Menu |

This queue is for tickets about the Locale-Maketext-Simple CPAN distribution.

Report information
The Basics
Id: 47609
Status: new
Priority: 0/
Queue: Locale-Maketext-Simple

People
Owner: Nobody in particular
Requestors: TONVOON [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)

Attachments
locale_maketext_simple_fallback_to_i_default.patch
locale_maketext_simple_tests.tar



Subject: Fallback to i_default if no values found for key
This overcomes a limitation in Locale::Maketext::Simple. If you want to have a fallback language, this is defined in IANA as i-default (http://www.iana.org/assignments/lang-tags/i-default). This is especially useful if you use an arbitrary message key (such as "system.message.hostNameIsInvalid") rather than an English phrase ("Host name is invalid"). However, i_default is not inherited into the base class for Maketext. Currently, L::M::S sets the base class with %LEXICON = (_AUTO => 1 ) and also creates an i_default language subclass with the _AUTO flag. This patch leaves the i_default to be created and then links the base class' %LEXICON with i_default's %LEXICON thus making i_default the default strings for all untranslated strings in further subclasses. The patch includes this change, some documentation, a possible enhancement where get_handle is called twice and tests in a separate tar file. Is this a useful patch to include to L::M::S? Please can you credit "Ton Voon, from Opsera Limited" for this patch if you include in a future version. Thank you.
Subject: locale_maketext_simple_tests.tar

Message body not shown because it is not plain text.

Subject: locale_maketext_simple_fallback_to_i_default.patch
diff -ur Locale-Maketext-Simple-0.18.original/lib/Locale/Maketext/Simple.pm Locale-Maketext-Simple-0.18/lib/Locale/Maketext/Simple.pm --- Locale-Maketext-Simple-0.18.original/lib/Locale/Maketext/Simple.pm 2006-09-08 14:28:01.000000000 +0000 +++ Locale-Maketext-Simple-0.18/lib/Locale/Maketext/Simple.pm 2009-07-05 07:57:26.569687333 +0000 @@ -46,6 +46,10 @@ designed to alleviate the need of creating I<Language Classes> for module authors. +The language used is chosen from the loc_lang call. If a lookup is not +possible, the i-default language will be used. If the lookup is not in the +i-default language, then the key will be returned. + If B<Locale::Maketext::Lexicon> is not present, it implements a minimal localization function by simply interpolating C<[_1]> with the first argument, C<[_2]> with the second, etc. Interpolated @@ -146,13 +150,13 @@ eval " package $pkg; use base 'Locale::Maketext'; - %${pkg}::Lexicon = ( '_AUTO' => 1 ); Locale::Maketext::Lexicon->import({ 'i-default' => [ 'Auto' ], '*' => [ Gettext => \$pattern ], _decode => \$decode, _encoding => \$encoding, }); + *${pkg}::Lexicon = \\%${pkg}::i_default::Lexicon; *tense = sub { \$_[1] . ((\$_[2] eq 'present') ? 'ing' : 'ed') } unless defined &tense; @@ -193,7 +197,7 @@ return $Loc{$pkg}, sub { $lh = $pkg->get_handle(@_); - $lh = $pkg->get_handle(@_); + #$lh = $pkg->get_handle(@_); # Is this necessary? }; }