r30038 - in /trunk/libtemplate-multilingual-perl: Changes META.yml README debian/changelog debian/compat debian/control debian/copyright debian/rules lib/Template/Multilingual.pm lib/Template/Multilingual/Parser.pm t/basic.t

rmayorga at users.alioth.debian.org rmayorga at users.alioth.debian.org
Sat Jan 24 03:39:34 UTC 2009


Author: rmayorga
Date: Sat Jan 24 03:39:31 2009
New Revision: 30038

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=30038
Log:
* New upstream release
* debian/control
  + remove libmodule-build-perl form B-D, dh7 prefer MakeMaker
  + add myself to uploaders
  + raise debhelper version to 7
  + mention module name on extended description
* debian/rules; convert to dh7 with the help of dh-make-perl
* debian/copyright:
  + convert to the new proposal format
  + separate debian/* copyright stanzas using debian/changelog as
    reference.

Modified:
    trunk/libtemplate-multilingual-perl/Changes
    trunk/libtemplate-multilingual-perl/META.yml
    trunk/libtemplate-multilingual-perl/README
    trunk/libtemplate-multilingual-perl/debian/changelog
    trunk/libtemplate-multilingual-perl/debian/compat
    trunk/libtemplate-multilingual-perl/debian/control
    trunk/libtemplate-multilingual-perl/debian/copyright
    trunk/libtemplate-multilingual-perl/debian/rules
    trunk/libtemplate-multilingual-perl/lib/Template/Multilingual.pm
    trunk/libtemplate-multilingual-perl/lib/Template/Multilingual/Parser.pm
    trunk/libtemplate-multilingual-perl/t/basic.t

Modified: trunk/libtemplate-multilingual-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtemplate-multilingual-perl/Changes?rev=30038&op=diff
==============================================================================
--- trunk/libtemplate-multilingual-perl/Changes (original)
+++ trunk/libtemplate-multilingual-perl/Changes Sat Jan 24 03:39:31 2009
@@ -1,4 +1,8 @@
 Revision history for Template-Multilingual
+
+1.00    2009-01-18
+        add support for language subtags, e.g. en_US or en-US
+        Language codes are now matched by [^<>]+ (previously \w+)
 
 0.09    2006-07-30
         remove Test::Pod and Test::Pod::Coverage tests

Modified: trunk/libtemplate-multilingual-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtemplate-multilingual-perl/META.yml?rev=30038&op=diff
==============================================================================
--- trunk/libtemplate-multilingual-perl/META.yml (original)
+++ trunk/libtemplate-multilingual-perl/META.yml Sat Jan 24 03:39:31 2009
@@ -1,6 +1,6 @@
 ---
 name: Template-Multilingual
-version: 0.09
+version: 1.00
 author:
   - 'Eric Cholet <cholet at logilune.com>'
 abstract: Multilingual templates for Template Toolkit
@@ -13,11 +13,11 @@
 provides:
   Template::Multilingual:
     file: lib/Template/Multilingual.pm
-    version: 0.09
+    version: 1.00
   Template::Multilingual::Parser:
     file: lib/Template/Multilingual/Parser.pm
-    version: 0.09
-generated_by: Module::Build version 0.2805
+    version: 1.00
+generated_by: Module::Build version 0.31012
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.2.html
   version: 1.2

Modified: trunk/libtemplate-multilingual-perl/README
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtemplate-multilingual-perl/README?rev=30038&op=diff
==============================================================================
--- trunk/libtemplate-multilingual-perl/README (original)
+++ trunk/libtemplate-multilingual-perl/README Sat Jan 24 03:39:31 2009
@@ -1,4 +1,4 @@
-$Id: README,v 1.2 2006/08/26 11:52:51 eric Exp $
+$Id: README,v 1.2 2006-08-26 11:52:51 eric Exp $
 
 --------
 Abstract

Modified: trunk/libtemplate-multilingual-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtemplate-multilingual-perl/debian/changelog?rev=30038&op=diff
==============================================================================
--- trunk/libtemplate-multilingual-perl/debian/changelog (original)
+++ trunk/libtemplate-multilingual-perl/debian/changelog Sat Jan 24 03:39:31 2009
@@ -1,5 +1,6 @@
-libtemplate-multilingual-perl (0.09-2) UNRELEASED; urgency=low
+libtemplate-multilingual-perl (1.00-1) unstable; urgency=low
 
+  [ gregor herrmann ]
   * debian/control: Added: Vcs-Svn field (source stanza); Vcs-Browser
     field (source stanza); Homepage field (source stanza). Removed:
     Homepage pseudo-field (Description); XS-Vcs-Svn fields.
@@ -12,7 +13,20 @@
   * debian/control: Changed: Switched Vcs-Browser field to ViewSVN
     (source stanza).
 
- -- gregor herrmann <gregor+debian at comodo.priv.at>  Tue, 09 Oct 2007 22:32:07 +0200
+  [ Rene Mayorg ]
+  * New upstream release
+  * debian/control
+    + remove libmodule-build-perl form B-D, dh7 prefer MakeMaker
+    + add myself to uploaders
+    + raise debhelper version to 7
+    + mention module name on extended description
+  * debian/rules; convert to dh7 with the help of dh-make-perl
+  * debian/copyright:
+    + convert to the new proposal format
+    + separate debian/* copyright stanzas using debian/changelog as
+      reference.
+
+ -- Rene Mayorga <rmayorga at debian.org>  Fri, 23 Jan 2009 21:13:53 -0600
 
 libtemplate-multilingual-perl (0.09-1) unstable; urgency=low
 

Modified: trunk/libtemplate-multilingual-perl/debian/compat
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtemplate-multilingual-perl/debian/compat?rev=30038&op=diff
==============================================================================
--- trunk/libtemplate-multilingual-perl/debian/compat (original)
+++ trunk/libtemplate-multilingual-perl/debian/compat Sat Jan 24 03:39:31 2009
@@ -1,1 +1,1 @@
-5
+7

Modified: trunk/libtemplate-multilingual-perl/debian/control
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtemplate-multilingual-perl/debian/control?rev=30038&op=diff
==============================================================================
--- trunk/libtemplate-multilingual-perl/debian/control (original)
+++ trunk/libtemplate-multilingual-perl/debian/control Sat Jan 24 03:39:31 2009
@@ -1,13 +1,13 @@
 Source: libtemplate-multilingual-perl
 Section: perl
 Priority: optional
-Build-Depends: debhelper (>= 5.0.0), libmodule-build-perl
+Build-Depends: debhelper (>= 7)
 Build-Depends-Indep: perl (>= 5.8.0-7), libtemplate-perl
 Maintainer: Debian Perl Group <pkg-perl-maintainers at lists.alioth.debian.org>
 Uploaders: gregor herrmann <gregoa at debian.org>,
  Carlo Segre <segre at debian.org>,
  Krzysztof Krzyzaniak (eloy) <eloy at debian.org>,
- Damyan Ivanov <dmn at debian.org>
+ Damyan Ivanov <dmn at debian.org>, Rene Mayorga <rmayorga at debian.org>
 Standards-Version: 3.8.0
 Homepage: http://search.cpan.org/dist/Template-Multilingual/
 Vcs-Svn: svn://svn.debian.org/pkg-perl/trunk/libtemplate-multilingual-perl/
@@ -17,5 +17,5 @@
 Architecture: all
 Depends: ${perl:Depends}, ${misc:Depends}, libtemplate-perl
 Description: Multilingual templates for Template Toolkit
- This subclass of Template Toolkit's Template class supports multilingual
- templates: templates that contain text in several languages.
+ Template::Multilingual class supports multilingual templates
+ that contain text in several languages.

Modified: trunk/libtemplate-multilingual-perl/debian/copyright
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtemplate-multilingual-perl/debian/copyright?rev=30038&op=diff
==============================================================================
--- trunk/libtemplate-multilingual-perl/debian/copyright (original)
+++ trunk/libtemplate-multilingual-perl/debian/copyright Sat Jan 24 03:39:31 2009
@@ -1,27 +1,30 @@
-This is the debian package for the Template-Multilingual module.
-It was created by gregor herrmann <gregor+debian at comodo.priv.at> using
-dh-make-perl. Curernt maintainer is Debian Perl Group, see
-http://pkg-perl/alioth.debian.org
+Format-Specification:
+    http://wiki.debian.org/Proposals/CopyrightFormat?action=recall&rev=196
+Upstream-Maintainer: Eric Cholet <cholet at logilune.com>
+Upstream-Source: http://search.cpan.org/dist/Template-Multilingual/
+Upstream-Name: Template-Multilingual
 
-It was downloaded from http://www.cpan.org/modules/by-module/Template/
+Files: *
+Copyright: 2009 Eric Cholet <cholet at logilune.com>
+License-Alias: Perl
+License: Artistic | GPL-1+
 
-Copyright:
-    Copyright (C) 2005, 2006 Eric Cholet
+Files: debian/*
+Copyright: 2006-2009 gregor herrmann <gregor+debian at comodo.priv.at>
+           2007 Krzysztof Krzyzaniak (eloy) <eloy at debian.org>
+	   2007 Damyan Ivanov <dmn at debian.org>
+License: Artistic | GPL-1+
 
-Licence:
-    This program is free software; you can redistribute it and/or modify it
-    under the same terms as Perl itself.
+License: Artistic
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the Artistic License, which comes with Perl.
+    On Debian GNU/Linux systems, the complete text of the Artistic License
+    can be found in `/usr/share/common-licenses/Artistic'
 
-Perl is distributed under either the Artistic licence or the GPL.
-
-The full text of the GPL is available on Debian systems in
-/usr/share/common-licenses/GPL
-
-The full text of the Artistic Licence is available on Debian systems in
-/usr/share/common-licenses/Artistic.
-
-Packaging copyright:
-    (c) 2006 Gergor Herrmann <gregor+debian at comodo.priv.at>
-    (c) 2007 Krzysztof Krzyzaniak <eloy at debian.org>
-    (c) 2007 Damyan Ivanov <dmn at debian.org>
-Packaging license: same as of the software itself, see above
+License: GPL-1+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 1, or (at your option)
+    any later version.
+    On Debian GNU/Linux systems, the complete text of the GNU General
+    Public License can be found in `/usr/share/common-licenses/GPL'

Modified: trunk/libtemplate-multilingual-perl/debian/rules
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtemplate-multilingual-perl/debian/rules?rev=30038&op=diff
==============================================================================
--- trunk/libtemplate-multilingual-perl/debian/rules (original)
+++ trunk/libtemplate-multilingual-perl/debian/rules Sat Jan 24 03:39:31 2009
@@ -1,60 +1,23 @@
 #!/usr/bin/make -f
-# This debian/rules file is provided as a template for normal perl
-# packages. It was created by Marc Brockschmidt <marc at dch-faq.de> for
-# the Debian Perl Group (http://pkg-perl.alioth.debian.org/) but may
-# be used freely wherever it is useful.
-#
-# It was later modified by Jason Kohles <email at jasonkohles.com>
-# http://www.jasonkohles.com/ to support Module::Build installed modules
-
-# Uncomment this to turn on verbose mode.
-#export DH_VERBOSE=1
-
-# If set to a true value then MakeMaker's prompt function will
-# always return the default without waiting for user input.
-export PERL_MM_USE_DEFAULT=1
-
-PERL   ?= /usr/bin/perl
-PACKAGE = $(shell dh_listpackages)
-TMP     = $(CURDIR)/debian/$(PACKAGE)
 
 build: build-stamp
 build-stamp:
-	dh_testdir
-	$(PERL) Build.PL installdirs=vendor
-	$(PERL) Build
-	$(PERL) Build test
+	dh build
 	touch $@
 
 clean:
-	dh_testdir
-	dh_testroot
-	dh_clean build-stamp install-stamp
-	[ ! -f Build ] || $(PERL) Build --allow_mb_mismatch 1 distclean
+	dh $@
 
 install: install-stamp
 install-stamp: build-stamp
-	dh_testdir
-	dh_testroot
-	dh_clean -k
-	$(PERL) Build install destdir=$(TMP) create_packlist=0
+	dh install
 	touch $@
 
 binary-arch:
-# We have nothing to do here for an architecture-independent package
 
-binary-indep: build install
-	dh_testdir
-	dh_testroot
-	dh_installdocs README
-	dh_installchangelogs Changes
-	dh_perl
-	dh_compress
-	dh_fixperms
-	dh_installdeb
-	dh_gencontrol
-	dh_md5sums
-	dh_builddeb
+binary-indep: install
+	dh $@
 
-binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary install
+binary: binary-arch binary-indep
+
+.PHONY: binary binary-arch binary-indep install clean build

Modified: trunk/libtemplate-multilingual-perl/lib/Template/Multilingual.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtemplate-multilingual-perl/lib/Template/Multilingual.pm?rev=30038&op=diff
==============================================================================
--- trunk/libtemplate-multilingual-perl/lib/Template/Multilingual.pm (original)
+++ trunk/libtemplate-multilingual-perl/lib/Template/Multilingual.pm Sat Jan 24 03:39:31 2009
@@ -4,7 +4,7 @@
 use base qw(Template);
 use Template::Multilingual::Parser;
 
-our $VERSION = '0.09';
+our $VERSION = '1.00';
 
 sub _init
 {
@@ -82,7 +82,7 @@
      LANGUAGE_VAR => 'global.language',
   });
 
-If this option is set, you code is responsible for setting the
+If this option is set, your code is responsible for setting the
 variable's value to the current language when processing the
 template. Calling C<language()> will have no effect.
 
@@ -100,6 +100,38 @@
 
 Used exactly as the original Template Toolkit C<process> method.
 Be sure to call C<language> before calling C<process>.
+
+=head1 LANGUAGE SUBTAG HANDLING
+
+This module supports language subtags to express variants, e.g. "en_US" or "en-US".
+Here are the rules used for language matching:
+
+=over
+
+=item *
+
+Exact match: the current language is found in the template
+
+  language    template                              output
+  fr          <fr>foo</fr><fr_CA>bar</fr_CA>        foo
+  fr_CA       <fr>foo</fr><fr_CA>bar</fr_CA>        bar
+
+=item *
+
+Fallback to the primary language
+
+  language    template                              output
+  fr_CA       <fr>foo</fr><fr_BE>bar</fr_BE>        foo
+
+=item *
+
+Fallback to first (in alphabetical order) other variant of the primary language
+
+  language    template                              output
+  fr          <fr_FR>foo</fr_FR><fr_BE>bar</fr_BE>  bar
+  fr_CA       <fr_FR>foo</fr_FR><fr_BE>bar</fr_BE>  bar
+
+=back
 
 =head1 AUTHOR
 
@@ -136,7 +168,7 @@
 
 =head1 COPYRIGHT & LICENSE
 
-Copyright 2005, 2006 Eric Cholet, All Rights Reserved.
+Copyright 2009 Eric Cholet, All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it
 under the same terms as Perl itself.

Modified: trunk/libtemplate-multilingual-perl/lib/Template/Multilingual/Parser.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtemplate-multilingual-perl/lib/Template/Multilingual/Parser.pm?rev=30038&op=diff
==============================================================================
--- trunk/libtemplate-multilingual-perl/lib/Template/Multilingual/Parser.pm (original)
+++ trunk/libtemplate-multilingual-perl/lib/Template/Multilingual/Parser.pm Sat Jan 24 03:39:31 2009
@@ -3,7 +3,7 @@
 use strict;
 use base qw(Template::Parser);
 
-our $VERSION = '0.09';
+our $VERSION = '1.00';
 
 sub new
 {
@@ -29,17 +29,45 @@
     $self->_tokenize($text);
 
     # replace multilingual sections with TT directives
-    $text = '';
+    my ($S, $E, $LANGVAR) = map $self->{$_}, qw(_start _end _langvar);
+
+    # if language is a variant (en_US), create a template variable holding the fallback value (en)
+    $text = "$S IF (tm_matches = $LANGVAR.match('^(\\w+)[-_].*\$')); tm_fb = tm_matches.0; END $E";
+
     for my $section (@{$self->{_sections}}) {
         if ($section->{nolang}) {
             $text .= $section->{nolang};
         }
         elsif (my $t = $section->{lang}) {
-            $text .= "$self->{_start} SWITCH $self->{_langvar} $self->{_end}";
-            for my $lang (keys %$t) {
-                $text .= "$self->{_start} CASE '$lang' $self->{_end}" . $t->{$lang};
-            }
-            $text .= "$self->{_start} END $self->{_end}";
+            my @languages = keys %$t;
+
+            # first loop through languages: look for exact match
+            $text .= "$S tm_f = 0; SWITCH $LANGVAR $E";
+            for my $lang (@languages) {
+                $text .= "$S CASE '$lang' $E" . $t->{$lang};
+            }
+            # add a default case to trigger fallback
+            $text .= "$S CASE; tm_f=1; END; $E";
+
+            # second loop: fallback to primary language (en_US matches en)
+            $text .= "$S IF tm_fb AND tm_f; tm_f=0; SWITCH tm_fb; $E";
+            for my $lang (@languages) {
+                $text .= "$S CASE '$lang' $E" . $t->{$lang};
+            }
+            # add a default case to trigger last resort fallback
+            #   LANG is fr_XX or fr but template has neither
+            #   we try to fallback to fr_YY is present
+            my %seen;
+            my @fallbacks = map { /^(\w+)[-_].*$/ && !$seen{$_}++ ? [ $1 => $_] : () } sort @languages;
+            if (@fallbacks) {
+                # third loop: fallback to first available variant
+                $text .= "$S CASE; tm_f=1; END; END; IF tm_f; SWITCH tm_fb || $LANGVAR; $E";
+                for my $ref (@fallbacks) {
+                    my ($lang, $variant) = @$ref;
+                    $text .= "$S CASE '$lang' $E" . $t->{$variant};
+                }
+            }
+            $text .= "$S END; END $E";
         }
     }
     return $self->SUPER::parse ($text);
@@ -56,7 +84,7 @@
     for my $t (@tokens) {
         if ($i) {             # <t>...</t> multilingual section
             my %section;
-            while ($t =~ m!<(\w+)>(.*?)</\1>!gs) {
+            while ($t =~ m!<([^<>]+)>(.*?)</\1>!gs) {
                 $section{$1} = $2;
             }
             push @{$self->{_sections}}, { lang => \%section }
@@ -78,7 +106,7 @@
 
     use Template;
     use Template::Multilingual::Parser;
-  
+    
     my $parser = Template::Multilingual::Parser->new();
     my $template = Template->new(PARSER => $parser);
     $template->process('example.ttml', { language => 'en'});
@@ -158,6 +186,42 @@
     {   lang => { fr => 'bonjour', en => 'hello' } },
     { nolang => ' bar' },
   ]
+
+=head1 LANGUAGE SUBTAG HANDLING
+
+This module supports language subtags to express variants, e.g. "en_US" or "en-US".
+Here are the rules used for language matching:
+
+=over
+
+=item *
+
+Exact match: the current language is found in the template
+
+  language    template                              output
+  fr          <fr>foo</fr><fr_CA>bar</fr_CA>        foo
+  fr_CA       <fr>foo</fr><fr_CA>bar</fr_CA>        bar
+
+=item *
+
+Fallback to the primary language
+
+  language    template                              output
+  fr_CA       <fr>foo</fr><fr_BE>bar</fr_BE>        foo
+
+=item *
+
+Fallback to first (in alphabetical order) other variant of the primary language
+
+  language    template                              output
+  fr          <fr_FR>foo</fr_FR><fr_BE>bar</fr_BE>  bar
+  fr_CA       <fr_FR>foo</fr_FR><fr_BE>bar</fr_BE>  bar
+
+=back
+
+=head1 AUTHOR
+
+Eric Cholet, C<< <cholet at logilune.com> >>
 
 =head1 BUGS
 
@@ -189,7 +253,7 @@
 
 =head1 COPYRIGHT & LICENSE
 
-Copyright 2005, 2006 Eric Cholet, All Rights Reserved.
+Copyright 2009 Eric Cholet, All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it
 under the same terms as Perl itself.

Modified: trunk/libtemplate-multilingual-perl/t/basic.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtemplate-multilingual-perl/t/basic.t?rev=30038&op=diff
==============================================================================
--- trunk/libtemplate-multilingual-perl/t/basic.t (original)
+++ trunk/libtemplate-multilingual-perl/t/basic.t Sat Jan 24 03:39:31 2009
@@ -3,52 +3,51 @@
 use strict;
 
 my @templates = (
-    { in  => '',
-      out => '',
-      sections => [ ],
-    },
-    { in  => 'foo',
-      out => 'foo',
-      sections => [ { nolang => 'foo' } ],
-    },
-    { in  => '<t></t>',
+    {
+      name => 'empty',
+      in  => '',
       out => '',
       sections => [ ],
     },
     {
+      name => 'nolang section',
+      in  => 'foo',
+      out => 'foo',
+      sections => [ { nolang => 'foo' } ],
+    },
+    {
+      name => 'empty lang section',
+      in  => '<t></t>',
+      out => '',
+      sections => [ ],
+    },
+    {
+      name => 'simple lang section',
       in  => '<t><fr>foo</fr></t>',
       out => 'foo',
       sections => [ { lang => { fr => 'foo' } } ],
     },
     {
+      name => 'other lang section',
       in  => '<t><en>foo</en></t>',
       out => '',
       sections => [ { lang => { en => 'foo' } } ],
     },
     {
+      name => 'multi lang section',
       in  => "<t><fr>foo</fr>\n<en>bar</en></t>",
       out => "foo",
       sections => [ { lang => { fr => 'foo', en => 'bar' } } ],
     },
     {
-      lang =>'en',
-      in  => '<t><fr>foo</fr></t>',
-      out => '',
-      sections => [ { lang => { fr => 'foo' } } ],
+      name => 'arbitrary lang names',
+      lang => ';',
+      in => '<t><;>foo</;></t>',
+      out => 'foo',
+      sections => [ { lang => { ';' => 'foo' } } ],
     },
     {
-      lang => 'en',
-      in  => '<t><en>foo</en></t>',
-      out => 'foo',
-      sections => [ { lang => { en => 'foo' } } ],
-    },
-    {
-      lang => 'eng',
-      in  => "<t><fra>foo</fra>\n<eng>bar</eng></t>",
-      out => 'bar',
-      sections => [ { lang => { fra => 'foo', eng => 'bar' } } ],
-    },
-    { # sections
+      name => 'multiple sections',
       in  => "A<t><fr>foo</fr></t>B<t><en>bar</en></t>C",
       out => 'AfooBC',
       sections => [ { nolang => 'A' },
@@ -57,6 +56,48 @@
                     {   lang => { en => 'bar' } },
                     { nolang => 'C' },
                   ],
+    },
+    {
+      name => 'fr_CA exact match',
+      lang => 'fr_CA',
+      in  => "<t><fr>foo</fr><fr_CA>bar</fr_CA></t>",
+      out => 'bar',
+      sections => [ { lang => { fr => 'foo', fr_CA => 'bar' } } ],
+    },
+    {
+      name => 'fr exact match',
+      lang => 'fr',
+      in  => "<t><fr>foo</fr><fr_CA>bar</fr_CA></t>",
+      out => 'foo',
+      sections => [ { lang => { fr => 'foo', fr_CA => 'bar' } } ],
+    },
+    {
+      name => 'fr_CA fallback to fr',
+      lang => 'fr_CA',
+      in  => "<t><fr>foo</fr><fr_BE>bar</fr_BE></t>",
+      out => 'foo',
+      sections => [ { lang => { fr => 'foo', fr_BE => 'bar' } } ],
+    },
+    {
+      name => 'fr-CA fallback to fr',
+      lang => 'fr-CA',
+      in  => "<t><fr>foo</fr><fr_BE>bar</fr_BE></t>",
+      out => 'foo',
+      sections => [ { lang => { fr => 'foo', fr_BE => 'bar' } } ],
+    },
+    {
+      name => 'fr_CA fallback to fr_BE',
+      lang => 'fr_CA',
+      in  => "<t><fr_FR>foo</fr_FR><fr_BE>bar</fr_BE><fr_CH>baz</fr_CH></t>",
+      out => 'bar',
+      sections => [ { lang => { fr_FR => 'foo', fr_BE => 'bar', fr_CH => 'baz' } } ],
+    },
+    {
+      name => 'fr fallback to fr_BE',
+      lang => 'fr',
+      in  => "<t><fr_FR>foo</fr_FR><fr_BE>bar</fr_BE><fr_CH>baz</fr_CH></t>",
+      out => 'bar',
+      sections => [ { lang => { fr_FR => 'foo', fr_BE => 'bar', fr_CH => 'baz' } } ],
     },
 );
 use Test::More;
@@ -69,22 +110,23 @@
 for my $t (@templates) {
     my $lang = $t->{lang} || 'fr';
     $template->language($lang);
-    is($template->language, $lang, "get/set language");
+    is($template->language, $lang, "$t->{name}: get/set language");
     my $output;
-    ok($template->process(\$t->{in}, {}, \$output), 'process');
-    is($output, $t->{out}, 'output');
-    is_deeply($template->{PARSER}->sections, $t->{sections}, 'sections');
+    ok($template->process(\$t->{in}, {}, \$output), "$t->{name}: process");
+    is($output, $t->{out}, "$t->{name}: output");
+    is_deeply($template->{PARSER}->sections, $t->{sections}, "$t->{name}: sections");
 }
 
+# 2nd pass with overridden LANGUAGE_VAR
 $template = Template::Multilingual->new(LANGUAGE_VAR => 'global.language');
 ok($template);
 
 for my $t (@templates) {
     my $lang = $t->{lang} || 'fr';
     my $output;
-    ok($template->process(\$t->{in}, { global => { language => $lang }}, \$output), 'process');
-    is($output, $t->{out}, 'output');
-    is_deeply($template->{PARSER}->sections, $t->{sections}, 'sections');
+    ok($template->process(\$t->{in}, { global => { language => $lang }}, \$output), "$t->{name}: process (overridden LANGUAGE_VAR)");
+    is($output, $t->{out}, "$t->{name}: output (overridden LANGUAGE_VAR)");
+    is_deeply($template->{PARSER}->sections, $t->{sections}, "$t->{name}: sections (overridden LANGUAGE_VAR)");
 }
 
 __END__




More information about the Pkg-perl-cvs-commits mailing list