diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2003-04-05 20:44:25 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2003-04-05 20:44:25 +0000 |
commit | f918d67792522c30e735f8e174d716ee850902e6 (patch) | |
tree | 3cd1cae5d8cd21314b2f174a552fd0f71811a49a /lib/Locale/Maketext | |
parent | d0551e7362dcfdf0d37c8900b7c6372851ee7f19 (diff) | |
download | perl-f918d67792522c30e735f8e174d716ee850902e6.tar.gz |
Upgrade to Locale::Maketext 1.04.
p4raw-id: //depot/perl@19149
Diffstat (limited to 'lib/Locale/Maketext')
-rw-r--r-- | lib/Locale/Maketext/ChangeLog | 14 | ||||
-rw-r--r-- | lib/Locale/Maketext/README | 9 | ||||
-rw-r--r-- | lib/Locale/Maketext/t/00about.t | 29 | ||||
-rw-r--r-- | lib/Locale/Maketext/t/01make.t | 34 | ||||
-rw-r--r-- | lib/Locale/Maketext/t/02get.t | 69 | ||||
-rw-r--r-- | lib/Locale/Maketext/t/03http.t | 102 | ||||
-rw-r--r-- | lib/Locale/Maketext/test.pl | 61 |
7 files changed, 252 insertions, 66 deletions
diff --git a/lib/Locale/Maketext/ChangeLog b/lib/Locale/Maketext/ChangeLog index f50e5b97f6..8cf00f4f00 100644 --- a/lib/Locale/Maketext/ChangeLog +++ b/lib/Locale/Maketext/ChangeLog @@ -1,6 +1,18 @@ Revision history for Perl suite Locale::Maketext - Time-stamp: "2001-06-21 23:18:31 MDT" + Time-stamp: "2003-04-02 10:37:42 AHST" +2003-04-02 Sean M. Burke sburke@cpan.org + * Release 1.04: Implementing proper HTTP "tag;q=rank" parsing for + get_handle. This should make all the difference for users/victims + of the current version of Safari, which uses that syntax as well + as inserts random languages with low q numbers. + Thanks to Jesse Vincent and the whole RT junta for finding this. + + * Added more tests, now in t/ + + * Lots of typo fixes to Maketext.pm. Thanks to Evan A. Zacks for + patient help in finding them all. + 2001-06-21 Sean M. Burke sburke@cpan.org * Release 1.03: basically cosmetic tweaks to the docs and the test.pl. diff --git a/lib/Locale/Maketext/README b/lib/Locale/Maketext/README index 72c3bf3b4c..5fdcae40c7 100644 --- a/lib/Locale/Maketext/README +++ b/lib/Locale/Maketext/README @@ -1,5 +1,5 @@ README for Locale::Maketext - Time-stamp: "2001-05-25 08:15:55 MDT" + Time-stamp: "2003-04-02 11:06:17 AHST" Locale::Maketext @@ -17,7 +17,8 @@ PREREQUISITES This suite requires Perl 5. It also requires a recent version of I18N::LangTags. MSWin users should also get Win32::Locale. -File::Findgrep is also useful example code. +File::Findgrep is also useful example code, as is the rather +larger Apache::MP3 source (even if you don't run Apache). INSTALLATION @@ -55,12 +56,12 @@ AVAILABILITY The latest version of Locale::Maketext is available from the Comprehensive Perl Archive Network (CPAN). Visit -<http://www.cpan.org/> to find a CPAN site near you. +<http://www.perl.com/CPAN/> to find a CPAN site near you. COPYRIGHT -Copyright 1999-2001, Sean M. Burke <sburke@cpan.org>, all rights +Copyright 1999-2003, Sean M. Burke <sburke@cpan.org>, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/lib/Locale/Maketext/t/00about.t b/lib/Locale/Maketext/t/00about.t new file mode 100644 index 0000000000..9b2fc85999 --- /dev/null +++ b/lib/Locale/Maketext/t/00about.t @@ -0,0 +1,29 @@ + +require 5; +use Test; +BEGIN { plan tests => 1; } +use Locale::Maketext 1.01; + +print "#\n#\n", + "# Locale::Maketext v$Locale::Maketext::VERSION\n", + "# I18N::LangTags v", $I18N::LangTags::VERSION || "?", "\n", + "#\n#\n", +; + +print "# Running under perl version $] for $^O", + (chr(65) eq 'A') ? "\n" : " in a non-ASCII world\n"; + +print "# Win32::BuildNumber ", &Win32::BuildNumber(), "\n" + if defined(&Win32::BuildNumber) and defined &Win32::BuildNumber(); + +print "# MacPerl verison $MacPerl::Version\n" + if defined $MacPerl::Version; + +printf + "# Current time local: %s\n# Current time GMT: %s\n", + scalar( gmtime($^T)), scalar(localtime($^T)); + +print "# Using Test.pm v", $Test::VERSION || "?", "\n"; + +ok 1; + diff --git a/lib/Locale/Maketext/t/01make.t b/lib/Locale/Maketext/t/01make.t new file mode 100644 index 0000000000..d9352d0340 --- /dev/null +++ b/lib/Locale/Maketext/t/01make.t @@ -0,0 +1,34 @@ + +require 5; +use Test; +BEGIN { plan tests => 6; } +use Locale::Maketext 1.01; +print "# Hi there...\n"; +ok 1; + +# declare some classes... +{ + package Woozle; + @ISA = ('Locale::Maketext'); + sub dubbil { return $_[1] * 2 } + sub numerate { return $_[2] . 'en' } +} +{ + package Woozle::elx; + @ISA = ('Woozle'); + %Lexicon = ( + 'd2' => 'hum [dubbil,_1]', + 'd3' => 'hoo [quant,_1,zaz]', + 'd4' => 'hoo [*,_1,zaz]', + ); + keys %Lexicon; # dodges the 'used only once' warning +} + +ok defined( $lh = Woozle->get_handle('elx') ) && ref($lh); +ok $lh && $lh->maketext('d2', 7), "hum 14" ; +ok $lh && $lh->maketext('d3', 7), "hoo 7 zazen" ; +ok $lh && $lh->maketext('d4', 7), "hoo 7 zazen" ; + +print "# Byebye!\n"; +ok 1; + diff --git a/lib/Locale/Maketext/t/02get.t b/lib/Locale/Maketext/t/02get.t new file mode 100644 index 0000000000..86fd4b20af --- /dev/null +++ b/lib/Locale/Maketext/t/02get.t @@ -0,0 +1,69 @@ + +require 5; +use Test; +BEGIN { plan tests => 11; } +use Locale::Maketext 1.01; +print "# Hi there...\n"; +ok 1; + +print "# --- Making sure that get_handle works ---\n"; + +# declare some classes... +{ + package Woozle; + @ISA = ('Locale::Maketext'); + sub dubbil { return $_[1] * 2 } + sub numerate { return $_[2] . 'en' } +} +{ + package Woozle::eu_mt; + @ISA = ('Woozle'); + %Lexicon = ( + 'd2' => 'hum [dubbil,_1]', + 'd3' => 'hoo [quant,_1,zaz]', + 'd4' => 'hoo [*,_1,zaz]', + ); + keys %Lexicon; # dodges the 'used only once' warning +} + +my $lh; +print "# Basic sanity:\n"; +ok defined( $lh = Woozle->get_handle('eu-mt') ) && ref($lh); +ok $lh && $lh->maketext('d2', 7), "hum 14" ; + + + +print "# Make sure we can assign to ENV entries\n", + "# (Otherwise we can't run the subsequent tests)...\n"; +$ENV{'MYORP'} = 'Zing'; +ok $ENV{'MYORP'}, 'Zing'; +$ENV{'SWUZ'} = 'KLORTHO HOOBOY'; +ok $ENV{'SWUZ'}, 'KLORTHO HOOBOY'; + +delete $ENV{'MYORP'}; +delete $ENV{'SWUZ'}; + +print "# Test LANG...\n"; +$ENV{'REQUEST_METHOD'} = ''; +$ENV{'LANG'} = 'Eu_MT'; +$ENV{'LANGUAGE'} = ''; +ok defined( $lh = Woozle->get_handle() ) && ref($lh); + +print "# Test LANGUAGE...\n"; +$ENV{'LANG'} = ''; +$ENV{'LANGUAGE'} = 'Eu-MT'; +ok defined( $lh = Woozle->get_handle() ) && ref($lh); + +print "# Test HTTP_ACCEPT_LANGUAGE...\n"; +$ENV{'REQUEST_METHOD'} = 'GET'; +$ENV{'HTTP_ACCEPT_LANGUAGE'} = 'eu-MT'; +ok defined( $lh = Woozle->get_handle() ) && ref($lh); +$ENV{'HTTP_ACCEPT_LANGUAGE'} = 'x-plorp, zaz, eu-MT, i-klung'; +ok defined( $lh = Woozle->get_handle() ) && ref($lh); +$ENV{'HTTP_ACCEPT_LANGUAGE'} = 'x-plorp, zaz, eU-Mt, i-klung'; +ok defined( $lh = Woozle->get_handle() ) && ref($lh); + + +print "# Byebye!\n"; +ok 1; + diff --git a/lib/Locale/Maketext/t/03http.t b/lib/Locale/Maketext/t/03http.t new file mode 100644 index 0000000000..98e7207a60 --- /dev/null +++ b/lib/Locale/Maketext/t/03http.t @@ -0,0 +1,102 @@ + +use Locale::Maketext; + +use Test; +BEGIN { plan tests => 87 }; + +my @in = grep m/\S/, split /\n/, q{ + +[ sv ] sv +[ en ] en +[ en fi ] en, fi +[ en-us ] en-us +[ en-us ] en-US +[ en-us ] EN-US + +[ en-au en i-klingon en-gb en-us mt-mt mt ja ] EN-au, JA;q=0.14, i-klingon;q=0.83, en-gb;q=0.71, en-us;q=0.57, mt-mt;q=0.43, mt;q=0.29, en;q=0.86 +[ en-au en i-klingon en-gb en-us mt-mt mt tli ja ] EN-au, tli;q=0.201, JA;q=0.14, i-klingon;q=0.83, en-gb;q=0.71, en-us;q=0.57, mt-mt;q=0.43, mt;q=0.29, en;q=0.86 +[ en-au en en-gb en-us ja ] en-au, ja;q=0.20, en-gb;q=0.60, en-us;q=0.40, en;q=0.80 + +[ en-au en en-gb en-us mt-mt mt ja ] EN-au, JA;q=0.14, en-gb;q=0.71, en-us;q=0.57, mt-mt;q=0.43, mt;q=0.29, en;q=0.86 +[ en-au en en-gb en-us ja ] en-au, ja;q=0.20, en-gb;q=0.60, en-us;q=0.40, en;q=0.80 +[ en fr ] en;q=1,fr;q=.5 +[ en fr ] en;q=1,fr;q=.99 +[ en ru ko ] en, ru;q=0.7, ko;q=0.3 +[ en ru ko ] en, ru;q=0.7, KO;q=0.3 +[ en-us en ] en-us, en;q=0.50 +[ en fr ] fr ; q = 0.9, en +[ en fr ] en,fr;q=.90 +[ ru en-uk en fr ] ru, en-UK;q=0.5, en;q=0.3, fr;q=0.1 +[ en-us fr es-mx ] en-us,fr;q=0.7,es-mx;q=0.3 +[ en-us en ] en-us, en;q=0.50 + +[ da en-gb en ] da, en-gb;q=0.8, en;q=0.7 +[ da en-gb en ] da, en;q=0.7, en-gb;q=0.8 +[ da en-gb en ] da, en-gb;q=0.8, en;q=0.7 +[ da en-gb en ] da,en;q=0.7,en-gb;q=0.8 +[ da en-gb en ] da, en-gb ; q=0.8, en ; q=0.7 +[ da en-gb en ] da , en-gb ; q = 0.8 , en ; q =0.7 +[ da en-gb en ] da (yup, Danish) , en-gb ; q = 0.8 , en ; q =0.7 + +[ no dk en-uk en-us ] en-UK;q=0.7, en-US;q=0.6, no;q=1.0, dk;q=0.8 +[ no dk en-uk en-us ] en-US;q=0.6, en-UK;q=0.7, no;q=1.0, dk;q=0.8 +[ no dk en-uk en-us ] en-UK;q=0.7, no;q=1.0, en-US;q=0.6, dk;q=0.8 +[ no dk en-uk en-us ] en-UK;q=0.7, no;q=1.0, dk;q=0.8, en-US;q=0.6 + +[ fi en ] fi;q=1, en;q=0.2 +[ de-de de en en-us en-gb ] de-DE, de;q=0.80, en;q=0.60, en-US;q=0.40, en-GB;q=0.20 +[ ru ] ru; q=1, *; q=0.1 +[ ru en ] ru, en; q=0.1 +[ ja en ] ja,en;q=0.5 +[ en ] en; q=1.0 +[ ja ] ja; q=1.0 +[ ja ] ja; q=1.0 +[ en ja ] en; q=0.5, ja; q=0.5 +[ fr-ca fr en ] fr-ca, fr;q=0.8, en;q=0.7 +[ NIX ] NIX +}; + +foreach my $in (@in) { + $in =~ s/^\s*\[([^\]]+)\]\s*//s or die "Bad input: $in"; + my @should = do { my $x = $1; $x =~ m/(\S+)/g }; + + if($in eq 'NIX') { $in = ''; @should = (); } + + local $ENV{'HTTP_ACCEPT_LANGUAGE'}; + + foreach my $modus ( + sub { + print "# Testing with arg...\n"; + $ENV{'HTTP_ACCEPT_LANGUAGE'} = 'PLORK'; + return $_[0]; + }, + sub { + print "# Testing wath HTTP_ACCEPT_LANGUAGE...\n"; + $ENV{'HTTP_ACCEPT_LANGUAGE'} = $_[0]; + return(); + }, + ) { + my @args = &$modus($in); + + # //////////////////////////////////////////////////// + my @out = Locale::Maketext->_http_accept_langs(@args); + # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ + + if( + @out == @should + and lc( join "\e", @out ) eq lc( join "\e", @should ) + ) { + print "# Happily got [@out] from [$in]\n"; + ok 1; + } else { + ok 0; + print "#Got: [@out]\n", + "# but wanted: [@should]\n", + "# < \"$in\"\n#\n"; + } + } +} + +print "#\n#\n# Bye-bye!\n"; +ok 1; + diff --git a/lib/Locale/Maketext/test.pl b/lib/Locale/Maketext/test.pl deleted file mode 100644 index 1a29da359b..0000000000 --- a/lib/Locale/Maketext/test.pl +++ /dev/null @@ -1,61 +0,0 @@ -# Before `make install' is performed this script should be runnable with -# `make test'. After `make install' it should work as `perl test.pl' -# Time-stamp: "2001-06-20 02:12:53 MDT" -######################### We start with some black magic to print on failure. - -# (It may become useful if the test is moved to ./t subdirectory.) - -BEGIN { $| = 1; print "1..5\n"; } -END {print "fail 1\n" unless $loaded;} -use Locale::Maketext 1.01; -print "# Perl v$], Locale::Maketext v$Locale::Maketext::VERSION\n"; -$loaded = 1; -print "ok 1\n"; -{ - package Woozle; - @ISA = ('Locale::Maketext'); - sub dubbil { return $_[1] * 2 } - sub numerate { return $_[2] . 'en' } -} -{ - package Woozle::elx; - @ISA = ('Woozle'); - %Lexicon = ( - 'd2' => 'hum [dubbil,_1]', - 'd3' => 'hoo [quant,_1,zaz]', - 'd4' => 'hoo [*,_1,zaz]', - ); -} - -$lh = Woozle->get_handle('elx'); -if($lh) { - print "ok 2\n"; - - my $x; - - $x = $lh->maketext('d2', 7); - if($x eq "hum 14") { - print "ok 3\n"; - } else { - print "fail 3 # (got \"$x\")\n"; - } - - $x = $lh->maketext('d3', 7); - if($x eq "hoo 7 zazen") { - print "ok 4\n"; - } else { - print "fail 4 # (got \"$x\")\n"; - } - - $x = $lh->maketext('d4', 7); - if($x eq "hoo 7 zazen") { - print "ok 5\n"; - } else { - print "fail 5 # (got \"$x\")\n"; - } - - -} else { - print "fail 2\n"; -} -#Shazam! |