[Bps-public-commit] r10810 - in Locale-Maketext-Lexicon: . inc/Test lib/Locale/Maketext lib/Locale/Maketext/Lexicon t

audreyt at bestpractical.com audreyt at bestpractical.com
Tue Feb 12 07:58:05 EST 2008


Author: audreyt
Date: Tue Feb 12 07:58:04 2008
New Revision: 10810

Modified:
   Locale-Maketext-Lexicon/Changes
   Locale-Maketext-Lexicon/README
   Locale-Maketext-Lexicon/inc/Test/Builder.pm
   Locale-Maketext-Lexicon/inc/Test/Builder/Module.pm
   Locale-Maketext-Lexicon/inc/Test/More.pm
   Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract.pm
   Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon.pm
   Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon/Auto.pm
   Locale-Maketext-Lexicon/t/5-extract.t

Log:
[Changes for 0.66 - 2008-02-12]

* Locale::Maketext::Extract: Support in Extract.pm->extract for 
  HTML::FormFu config files.
  Contributed by: Andreas Marienborg


Modified: Locale-Maketext-Lexicon/Changes
==============================================================================
--- Locale-Maketext-Lexicon/Changes	(original)
+++ Locale-Maketext-Lexicon/Changes	Tue Feb 12 07:58:04 2008
@@ -1,3 +1,9 @@
+[Changes for 0.66 - 2008-02-12]
+
+* Locale::Maketext::Extract: Support in Extract.pm->extract for 
+  HTML::FormFu config files.
+  Contributed by: Andreas Marienborg
+
 [Changes for 0.65 - 2007-12-22]
 
 * Perl 5.9.5+ is pickier about what "being used only once" means,

Modified: Locale-Maketext-Lexicon/README
==============================================================================
--- Locale-Maketext-Lexicon/README	(original)
+++ Locale-Maketext-Lexicon/README	Tue Feb 12 07:58:04 2008
@@ -1,50 +1,203 @@
-This is the README file for Locale::Maketext::Lexicon, a module providing
-lexicon-handling backends, for "Locale::Maketext" to read from other
-localization formats, such as PO files, MO files, or from databases via
-the "Tie" interface.
-
-For extracting translatable strings from source files, a "xgettext.pl"
-utility is also installed by default.
-
-You can also read my presentation "Web Localization in Perl" in the docs/
-directory.  It gives an overview for the localization process, features
-a comparison between Gettext, Msgcat and Maketext, and talks about my
-experiences at localizing web applications based on HTML::Mason and the
-Template Toolkit.
-
-* Installation
-
-Locale::Maketext::Lexicon uses the standard perl module install process:
-
-    cpansign -v         # optional; see the SIGNATURE file for details
-    perl Makefile.PL
-    make                # or 'nmake' on Win32
-    make test
-    make install
-
-* Copyright
-
-Copyright 2002, 2003, 2004, 2005, 2006, 2007 by Audrey Tang <cpan at audreyt.org>.
-
-This software is released under the MIT license cited below.
-
-* The "MIT" License
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
+NAME
+    Locale::Maketext::Lexicon - Use other catalog formats in Maketext
+
+VERSION
+    This document describes version 0.66 of Locale::Maketext::Lexicon,
+    released February 12, 2008.
+
+SYNOPSIS
+    As part of a localization class, automatically glob for available
+    lexicons:
+
+        package Hello::I18N;
+        use base 'Locale::Maketext';
+        use Locale::Maketext::Lexicon {
+            '*' => [Gettext => '/usr/local/share/locale/*/LC_MESSAGES/hello.mo'],
+            ### Uncomment to decode lexicon entries into Unicode strings
+            # _decode => 1,
+            ### Uncomment to fallback when a key is missing from lexicons
+            # _auto   => 1,
+            ### Uncomment to use %1 / %quant(%1) instead of [_1] / [quant, _1]
+            # _style  => 'gettext',
+        };
+
+    Explicitly specify languages, during compile- or run-time:
+
+        package Hello::I18N;
+        use base 'Locale::Maketext';
+        use Locale::Maketext::Lexicon {
+            de => [Gettext => 'hello_de.po'],
+            fr => [
+                Gettext => 'hello_fr.po',
+                Gettext => 'local/hello/fr.po',
+            ],
+        };
+        # ... incrementally add new lexicons
+        Locale::Maketext::Lexicon->import({
+            de => [Gettext => 'local/hello/de.po'],
+        })
+
+    Alternatively, as part of a localization subclass:
+
+        package Hello::I18N::de;
+        use base 'Hello::I18N';
+        use Locale::Maketext::Lexicon (Gettext => \*DATA);
+        __DATA__
+        # Some sample data
+        msgid ""
+        msgstr ""
+        "Project-Id-Version: Hello 1.3.22.1\n"
+        "MIME-Version: 1.0\n"
+        "Content-Type: text/plain; charset=iso8859-1\n"
+        "Content-Transfer-Encoding: 8bit\n"
+
+        #: Hello.pm:10
+        msgid "Hello, World!"
+        msgstr "Hallo, Welt!"
+
+        #: Hello.pm:11
+        msgid "You have %quant(%1,piece) of mail."
+        msgstr "Sie haben %quant(%1,Poststueck,Poststuecken)."
+
+DESCRIPTION
+    This module provides lexicon-handling modules to read from other
+    localization formats, such as *Gettext*, *Msgcat*, and so on.
+
+    If you are unfamiliar with the concept of lexicon modules, please
+    consult Locale::Maketext and <http://www.autrijus.org/webl10n/> first.
+
+    A command-line utility xgettext.pl is also installed with this module,
+    for extracting translatable strings from source files.
+
+  The "import" function
+    The "import()" function accepts two forms of arguments:
+
+    (*format* => *source* ... )
+        This form takes any number of argument pairs (usually one); *source*
+        may be a file name, a filehandle, or an array reference.
+
+        For each such pair, it pass the contents specified by the second
+        argument to Locale::Maketext::Lexicon::*format*->parse as a plain
+        list, and export its return value as the %Lexicon hash in the
+        calling package.
+
+        In the case that there are multiple such pairs, the lexicon defined
+        by latter ones overrides earlier ones.
+
+    { *language* => [ *format*, *source* ... ] ... }
+        This form accepts a hash reference. It will export a %Lexicon into
+        the subclasses specified by each *language*, using the process
+        described above. It is designed to alleviate the need to set up a
+        separate subclass for each localized language, and just use the
+        catalog files.
+
+        This module will convert the *language* arguments into lowercase,
+        and replace all "-" with "_", so "zh_TW" and "zh-tw" will both map
+        to the "zh_tw" subclass.
+
+        If *language* begins with "_", it is taken as an option that
+        controls how lexicons are parsed. See "Options" for a list of
+        available options.
+
+        The "*" is a special *language*; it must be used in conjunction with
+        a filename that also contains "*"; all matched files with a valid
+        language code in the place of "*" will be automatically prepared as
+        a lexicon subclass. If there is multiple "*" in the filename, the
+        last one is used as the language name.
+
+  Options
+    "_auto"
+        If set to a true value, missing lookups on lexicons are handled
+        silently, as if an "Auto" lexicon has been appended on all language
+        lexicons.
+
+    "_decode"
+        If set to a true value, source entries will be converted into
+        utf8-strings (available in Perl 5.6.1 or later). This feature needs
+        the Encode or Encode::compat module.
+
+        Currently, only the "Gettext" backend supports this option.
+
+    "_encoding"
+        This option only has effect when "_decode" is set to true. It
+        specifies an encoding to store lexicon entries, instead of
+        utf8-strings.
+
+        If "_encoding" is set to "locale", the encoding from the current
+        locale setting is used.
+
+  Subclassing format handlers
+    If you wish to override how sources specified in different data types
+    are handled, please use a subclass that overrides "lexicon_get_*TYPE*".
+
+    XXX: not documented well enough yet. Patches welcome.
+
+NOTES
+    When you attempt to localize an entry missing in the lexicon, Maketext
+    will throw an exception by default. To inhibit this behaviour, override
+    the "_AUTO" key in your language subclasses, for example:
+
+        $Hello::I18N::en::Lexicon{_AUTO} = 1; # autocreate missing keys
+
+    If you want to implement a new "Lexicon::*" backend module, please note
+    that "parse()" takes an array containing the source strings from the
+    specified filehandle or filename, which are *not* "chomp"ed. Although if
+    the source is an array reference, its elements will probably not contain
+    any newline characters anyway.
+
+    The "parse()" function should return a hash reference, which will be
+    assigned to the *typeglob* (*Lexicon) of the language module. All it
+    amounts to is that if the returned reference points to a tied hash, the
+    %Lexicon will be aliased to the same tied hash if it was not initialized
+    previously.
+
+ACKNOWLEDGMENTS
+    Thanks to Jesse Vincent for suggesting this module to be written.
+
+    Thanks also to Sean M. Burke for coming up with Locale::Maketext in the
+    first place, and encouraging me to experiment with alternative Lexicon
+    syntaxes.
+
+    Thanks also to Yi Ma Mao for providing the MO file parsing subroutine,
+    as well as inspiring me to implement file globbing and transcoding
+    support.
+
+    See the AUTHORS file in the distribution for a list of people who have
+    sent helpful patches, ideas or comments.
+
+SEE ALSO
+    xgettext.pl for extracting translatable strings from common template
+    systems and perl source files.
+
+    Locale::Maketext, Locale::Maketext::Lexicon::Auto,
+    Locale::Maketext::Lexicon::Gettext, Locale::Maketext::Lexicon::Msgcat,
+    Locale::Maketext::Lexicon::Tie
+
+AUTHORS
+    Audrey Tang <cpan at audreyt.org>
+
+COPYRIGHT
+    Copyright 2002-2008 by Audrey Tang <cpan at audreyt.org>.
+
+    This software is released under the MIT license cited below.
+
+  The "MIT" License
+    Permission is hereby granted, free of charge, to any person obtaining a
+    copy of this software and associated documentation files (the
+    "Software"), to deal in the Software without restriction, including
+    without limitation the rights to use, copy, modify, merge, publish,
+    distribute, sublicense, and/or sell copies of the Software, and to
+    permit persons to whom the Software is furnished to do so, subject to
+    the following conditions:
+
+    The above copyright notice and this permission notice shall be included
+    in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 

Modified: Locale-Maketext-Lexicon/inc/Test/Builder.pm
==============================================================================
--- Locale-Maketext-Lexicon/inc/Test/Builder.pm	(original)
+++ Locale-Maketext-Lexicon/inc/Test/Builder.pm	Tue Feb 12 07:58:04 2008
@@ -9,7 +9,7 @@
 
 use strict;
 use vars qw($VERSION);
-$VERSION = '0.72';
+$VERSION = '0.74';
 $VERSION = eval $VERSION;    # make the alpha version come out as a number
 
 # Make Test::Builder thread-safe for ithreads.

Modified: Locale-Maketext-Lexicon/inc/Test/Builder/Module.pm
==============================================================================
--- Locale-Maketext-Lexicon/inc/Test/Builder/Module.pm	(original)
+++ Locale-Maketext-Lexicon/inc/Test/Builder/Module.pm	Tue Feb 12 07:58:04 2008
@@ -6,7 +6,7 @@
 require Exporter;
 @ISA = qw(Exporter);
 
-$VERSION = '0.72';
+$VERSION = '0.74';
 
 use strict;
 

Modified: Locale-Maketext-Lexicon/inc/Test/More.pm
==============================================================================
--- Locale-Maketext-Lexicon/inc/Test/More.pm	(original)
+++ Locale-Maketext-Lexicon/inc/Test/More.pm	Tue Feb 12 07:58:04 2008
@@ -17,7 +17,7 @@
 
 
 use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS $TODO);
-$VERSION = '0.72';
+$VERSION = '0.74';
 $VERSION = eval $VERSION;    # make the alpha version come out as a number
 
 use Test::Builder::Module;
@@ -233,32 +233,37 @@
 
     my($pack,$filename,$line) = caller;
 
-    local($@,$!,$SIG{__DIE__});   # isolate eval
+    # Work around a glitch in $@ and eval
+    my $eval_error;
+    {
+        local($@,$!,$SIG{__DIE__});   # isolate eval
 
-    if( @imports == 1 and $imports[0] =~ /^\d+(?:\.\d+)?$/ ) {
-        # probably a version check.  Perl needs to see the bare number
-        # for it to work with non-Exporter based modules.
-        eval <<USE;
+        if( @imports == 1 and $imports[0] =~ /^\d+(?:\.\d+)?$/ ) {
+            # probably a version check.  Perl needs to see the bare number
+            # for it to work with non-Exporter based modules.
+            eval <<USE;
 package $pack;
 use $module $imports[0];
 USE
-    }
-    else {
-        eval <<USE;
+        }
+        else {
+            eval <<USE;
 package $pack;
 use $module \@imports;
 USE
+        }
+        $eval_error = $@;
     }
 
-    my $ok = $tb->ok( !$@, "use $module;" );
+    my $ok = $tb->ok( !$eval_error, "use $module;" );
 
     unless( $ok ) {
-        chomp $@;
+        chomp $eval_error;
         $@ =~ s{^BEGIN failed--compilation aborted at .*$}
                 {BEGIN failed--compilation aborted at $filename line $line.}m;
         $tb->diag(<<DIAGNOSTIC);
     Tried to use '$module'.
-    Error:  $@
+    Error:  $eval_error
 DIAGNOSTIC
 
     }
@@ -266,7 +271,7 @@
     return $ok;
 }
 
-#line 702
+#line 707
 
 sub require_ok ($) {
     my($module) = shift;
@@ -310,7 +315,7 @@
     $module =~ /^[a-zA-Z]\w*$/;
 }
 
-#line 779
+#line 784
 
 use vars qw(@Data_Stack %Refs_Seen);
 my $DNE = bless [], 'Does::Not::Exist';
@@ -417,7 +422,7 @@
     return '';
 }
 
-#line 925
+#line 930
 
 sub diag {
     my $tb = Test::More->builder;
@@ -426,7 +431,7 @@
 }
 
 
-#line 994
+#line 999
 
 #'#
 sub skip {
@@ -454,7 +459,7 @@
 }
 
 
-#line 1081
+#line 1086
 
 sub todo_skip {
     my($why, $how_many) = @_;
@@ -475,7 +480,7 @@
     last TODO;
 }
 
-#line 1134
+#line 1139
 
 sub BAIL_OUT {
     my $reason = shift;
@@ -484,7 +489,7 @@
     $tb->BAIL_OUT($reason);
 }
 
-#line 1173
+#line 1178
 
 #'#
 sub eq_array {
@@ -608,7 +613,7 @@
 }
 
 
-#line 1304
+#line 1309
 
 sub eq_hash {
     local @Data_Stack;
@@ -641,7 +646,7 @@
     return $ok;
 }
 
-#line 1361
+#line 1366
 
 sub eq_set  {
     my($a1, $a2) = @_;
@@ -667,6 +672,6 @@
     );
 }
 
-#line 1551
+#line 1556
 
 1;

Modified: Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract.pm
==============================================================================
--- Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract.pm	(original)
+++ Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract.pm	Tue Feb 12 07:58:04 2008
@@ -1,5 +1,5 @@
 package Locale::Maketext::Extract;
-$Locale::Maketext::Extract::VERSION = '0.22';
+$Locale::Maketext::Extract::VERSION = '0.23';
 
 use strict;
 
@@ -51,6 +51,14 @@
 
 Sentences between C<STARTxxx> and C<ENDxxx> are extracted individually.
 
+=item HTML::FormFu
+
+HTML::FormFu uses a config-file to generate forms, with built in 
+support for localizing errors, labels etc.
+
+We extract the text after C<_loc: >:
+    content_loc: this is the string
+
 =item Generic Template
 
 Strings inside {{...}} are extracted.
@@ -234,6 +242,14 @@
         $self->add_entry($str, [ $file, $line, $vars ]);
     }
 
+    # HTML::FormFu config-files
+    $line = 1; pos($_) = 0;
+    while (m/\G(.*?_loc:\s+(.*))/sg) {
+        my ($str) = $2;
+        $line += ( () = ($1 =~ /\n/g) ); # cryptocontext!
+        $self->add_entry($str, [ $file, $line ]);
+    }    
+
     # Generic Template:
     $line = 1; pos($_) = 0;
     while (m/\G(.*?(?<!\{)\{\{(?!\{)(.*?)\}\})/sg) {
@@ -528,7 +544,7 @@
 
 =head1 COPYRIGHT
 
-Copyright 2003, 2004, 2005, 2006, 2007 by Audrey Tang E<lt>cpan at audreyt.orgE<gt>.
+Copyright 2003-2008 by Audrey Tang E<lt>cpan at audreyt.orgE<gt>.
 
 This software is released under the MIT license cited below.
 

Modified: Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon.pm
==============================================================================
--- Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon.pm	(original)
+++ Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon.pm	Tue Feb 12 07:58:04 2008
@@ -1,5 +1,5 @@
 package Locale::Maketext::Lexicon;
-$Locale::Maketext::Lexicon::VERSION = '0.65';
+$Locale::Maketext::Lexicon::VERSION = '0.66';
 
 use 5.004;
 use strict;
@@ -10,8 +10,8 @@
 
 =head1 VERSION
 
-This document describes version 0.65 of Locale::Maketext::Lexicon,
-released December 22, 2007.
+This document describes version 0.66 of Locale::Maketext::Lexicon,
+released February 12, 2008.
 
 =head1 SYNOPSIS
 
@@ -535,7 +535,7 @@
 
 =head1 COPYRIGHT
 
-Copyright 2002, 2003, 2004, 2005, 2006, 2007 by Audrey Tang E<lt>cpan at audreyt.orgE<gt>.
+Copyright 2002-2008 by Audrey Tang E<lt>cpan at audreyt.orgE<gt>.
 
 This software is released under the MIT license cited below.
 

Modified: Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon/Auto.pm
==============================================================================
--- Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon/Auto.pm	(original)
+++ Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon/Auto.pm	Tue Feb 12 07:58:04 2008
@@ -1,5 +1,5 @@
 package Locale::Maketext::Lexicon::Auto;
-$Locale::Maketext::Lexicon::Auto::VERSION = '0.04';
+$Locale::Maketext::Lexicon::Auto::VERSION = '0.10';
 
 use strict;
 
@@ -34,7 +34,7 @@
 =cut
 
 sub parse {
-    return { _AUTO => 1 };
+    +{ _AUTO => 1 };
 }
 
 1;

Modified: Locale-Maketext-Lexicon/t/5-extract.t
==============================================================================
--- Locale-Maketext-Lexicon/t/5-extract.t	(original)
+++ Locale-Maketext-Lexicon/t/5-extract.t	Tue Feb 12 07:58:04 2008
@@ -1,7 +1,7 @@
 #! /usr/bin/perl -w
 use lib '../lib';
 use strict;
-use Test::More tests => 28;
+use Test::More tests => 29;
 
 use_ok('Locale::Maketext::Extract');
 my $Ext = Locale::Maketext::Extract->new;
@@ -44,6 +44,8 @@
 extract_ok(q(_(q{foo\\\\bar}))             => 'foo\\bar',    'Normalized \\\\ in q');
 extract_ok(q(_(qq{foo\bar}))               => "foo\bar",          'Interpolated \b in qq');
 
+# HTML::FormFu test
+extract_ok('    content_loc: foo bar'          => "foo bar",    "html-formfu extraction");
 
 extract_ok(
     q(my $x = loc('I "think" you\'re a cow.') . "\n";) => 'I "think" you\'re a cow.', 



More information about the Bps-public-commit mailing list