develooper Front page | perl.perl5.porters | Postings from October 2003

[PATCH] Update I18N::LangTags from 0.28 to 0.29

Thread Next
From:
Jan Dubois
Date:
October 22, 2003 20:47
Subject:
[PATCH] Update I18N::LangTags from 0.28 to 0.29
Message ID:
jgiepv0a8fp8ffq3lpc5ujl7j25hoo1rdt@4ax.com
Change 79869 by jand on 2003/10/17 16:58:58

	Update I18N::LangTags from 0.28 to 0.29

Affected files ...

... MANIFEST#53 edit
... lib/I18N/LangTags.pm#4 edit
... lib/I18N/LangTags/ChangeLog#3 edit
... lib/I18N/LangTags/List.pm#4 edit
... lib/I18N/LangTags/README#3 edit
... lib/I18N/LangTags/t/02decency.t#1 add

Differences ...

==== MANIFEST#53 (text) ====
Index: MANIFEST
--- MANIFEST.~1~	Wed Oct 22 20:23:59 2003
+++ MANIFEST	Wed Oct 22 20:23:59 2003
@@ -1256,6 +1256,7 @@
 lib/I18N/LangTags.pm		I18N::LangTags
 lib/I18N/LangTags/README	I18N::LangTags
 lib/I18N/LangTags/t/01test.t	See whether I18N::LangTags works
+lib/I18N/LangTags/t/02decency.t See if I18N::LangTags::List::is_decent works
 lib/if.pm			For "use if"
 lib/if.t			Tests for "use if"
 lib/importenv.pl		Perl routine to get environment into variables

==== lib/I18N/LangTags.pm#4 (text) ====
Index: lib/I18N/LangTags.pm
--- lib/I18N/LangTags.pm.~1~	Wed Oct 22 20:23:59 2003
+++ lib/I18N/LangTags.pm	Wed Oct 22 20:23:59 2003
@@ -1,5 +1,5 @@
 
-# Time-stamp: "2003-07-20 07:44:42 ADT"
+# Time-stamp: "2003-10-10 17:43:04 ADT"
 # Sean M. Burke <sburke@cpan.org>
 
 require 5.000;
@@ -17,7 +17,7 @@
                );
 %EXPORT_TAGS = ('ALL' => \@EXPORT_OK);
 
-$VERSION = "0.28";
+$VERSION = "0.29";
 
 =head1 NAME
 
@@ -333,7 +333,7 @@
 $lang1 are mutually intelligible with $lang1.  Consider this
 carefully.
 
-=cut 
+=cut
 
 sub super_languages {
   my $lang1 = $_[0];
@@ -388,7 +388,7 @@
 The output is untainted.  If you don't know what tainting is,
 don't worry about it.
 
-=cut 
+=cut
 
 sub locale2language_tag {
   my $lang =
@@ -771,7 +771,7 @@
 Value and Encoded Word Extensions: Character Sets, Languages, and
 Continuations".
 
-* RFC 2482, C<ftp://ftp.isi.edu/in-notes/rfc2482.txt>, 
+* RFC 2482, C<ftp://ftp.isi.edu/in-notes/rfc2482.txt>,
 "Language Tagging in Unicode Plain Text".
 
 * Locale::Codes, in

==== lib/I18N/LangTags/ChangeLog#3 (text) ====
Index: lib/I18N/LangTags/ChangeLog
--- lib/I18N/LangTags/ChangeLog.~1~	Wed Oct 22 20:23:59 2003
+++ lib/I18N/LangTags/ChangeLog	Wed Oct 22 20:23:59 2003
@@ -1,6 +1,27 @@
 Revision history for Perl module I18N::LangTags.
-                                        Time-stamp: "2002-02-02 20:45:47 MST"
+                                        Time-stamp: "2003-10-10 17:07:55 ADT"
+
+2003-10-10  Sean M. Burke  sburke@cpan.org
+	
+	* Release 0.29
+
+	Minor bugfix to I18N::LangTags::List code.  Addition of the
+	is_decent function, and the 02decency.t test for it.
+	
+	Better Makefile.  Thanks to everyone who told me about the
+	INSTALLDIRS trick.
+	
+	
+	
+2003-07-20  Sean M. Burke  sburke@cpan.org
 
+	* Release 0.28
+	Doc fixes in I18N::LangTags, plus a few added variances (jw/jv,
+	 cre/cr, etc.) 
+	Lots of updates to I18N::LangTags::List
+	Deleted rfc3066.txt from dist.
+	Moved test.pl to t/01test.t and added more tests.
+	
 2002-02-02  Sean M. Burke  sburke@cpan.org
 
 	* Release 0.27 -- minor mods to ::List:

==== lib/I18N/LangTags/List.pm#4 (text) ====
Index: lib/I18N/LangTags/List.pm
--- lib/I18N/LangTags/List.pm.~1~	Wed Oct 22 20:23:59 2003
+++ lib/I18N/LangTags/List.pm	Wed Oct 22 20:23:59 2003
@@ -1,10 +1,10 @@
 
 require 5;
 package I18N::LangTags::List;
-#  Time-stamp: "2003-07-20 07:31:08 ADT"
+#  Time-stamp: "2003-10-10 17:39:45 ADT"
 use strict;
-use vars qw(%Name $Debug $VERSION);
-$VERSION = '0.26';
+use vars qw(%Name %Is_Disrec $Debug $VERSION);
+$VERSION = '0.29';
 # POD at the end.
 
 #----------------------------------------------------------------------
@@ -12,21 +12,23 @@
 # read the table out of our own POD!
   my $seeking = 1;
   my $count = 0;
-  my($tag,$name);
+  my($disrec,$tag,$name);
   my $last_name = '';
   while(<I18N::LangTags::List::DATA>) {
     if($seeking) {
       $seeking = 0 if m/=for woohah/;
-    } elsif( ($tag, $name) =
-          m/\{([-0-9a-zA-Z]+)\}(?:\s*:)?\s*([^\[\]]+)/
+    } elsif( ($disrec, $tag, $name) =
+          m/(\[?)\{([-0-9a-zA-Z]+)\}(?:\s*:)?\s*([^\[\]]+)/
     ) {
       $name =~ s/\s*[;\.]*\s*$//g;
       next unless $name;
       ++$count;
       print "<$tag> <$name>\n" if $Debug;
       $last_name = $Name{$tag} = $name;
-    } elsif (m/Formerly \"([-a-z0-9]+)\"/) {
+      $Is_Disrec{$tag} = 1 if $disrec;
+    } elsif (m/[Ff]ormerly \"([-a-z0-9]+)\"/) {
       $Name{$1} = "$last_name (old tag)" if $last_name;
+      $Is_Disrec{$1} = 1;
     }
   }
   die "No tags read??" unless $count;
@@ -74,6 +76,42 @@
   return "$name (Subform \"$subform\")";
 }
 
+#--------------------------------------------------------------------------
+
+sub is_decent {
+  my $tag = lc($_[0] || return 0);
+  #require I18N::LangTags;
+
+  return 0 unless
+    $tag =~ 
+    /^(?:  # First subtag
+         [xi] | [a-z]{2,3}
+      )
+      (?:  # Subtags thereafter
+         -           # separator
+         [a-z0-9]{1,8}  # subtag  
+      )*
+    $/xs;
+
+  my @supers = ();
+  foreach my $bit (split('-', $tag)) {
+    push @supers, 
+      scalar(@supers) ? ($supers[-1] . '-' . $bit) : $bit;
+  }
+  return 0 unless @supers;
+  shift @supers if $supers[0] =~ m<^(i|x|sgn)$>s;
+  return 0 unless @supers;
+
+  foreach my $f ($tag, @supers) {
+    return 0 if $Is_Disrec{$f};
+    return 2 if $Name{$f};
+     # so that decent subforms of indecent tags are decent
+  }
+  return 2 if $Name{$tag}; # not only is it decent, it's known!
+  return 1;
+}
+
+#--------------------------------------------------------------------------
 1;
 
 __DATA__
@@ -98,7 +136,7 @@
 
 =head1 DESCRIPTION
 
-This module provides a function 
+This module provides a function
 C<I18N::LangTags::List::name( I<langtag> ) > that takes
 a language tag (see L<I18N::LangTags|I18N::LangTags>)
 and returns the best attempt at an English name for it, or
@@ -106,6 +144,13 @@
 
 The function I18N::LangTags::List::name(...) is not exported.
 
+This module also provides a function
+C<I18N::LangTags::List::is_decent( I<langtag> )> that returns true iff
+the language tag is syntactically valid and is for general use (like
+"fr" or "fr-ca", below).  That is, it returns false for tags that are
+syntactically invalid and for tags, like "aus", that are listed in
+brackets below.  This function is not exported.
+
 The map of tags-to-names that it uses is accessable as
 %I18N::LangTags::List::Name, and it's the same as the list
 that follows in this documentation, which should be useful
@@ -117,7 +162,7 @@
 for denoting human languages.  The two-letter ISO 639-1 language
 codes are well known (as "en" for English), as are their forms
 when qualified by a country code ("en-US").  Less well-known are the
-arbitrary-length non-ISO codes (like "i-mingo"), and the 
+arbitrary-length non-ISO codes (like "i-mingo"), and the
 recently (in 2001) introduced three-letter ISO-639-2 codes.
 
 Remember these important facts:

==== lib/I18N/LangTags/README#3 (text) ====
Index: lib/I18N/LangTags/README
--- lib/I18N/LangTags/README.~1~	Wed Oct 22 20:23:59 2003
+++ lib/I18N/LangTags/README	Wed Oct 22 20:23:59 2003
@@ -61,7 +61,7 @@
 
 The latest version of I18N::LangTags 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

==== lib/I18N/LangTags/t/02decency.t#1 (text) ====
Index: lib/I18N/LangTags/t/02decency.t
--- lib/I18N/LangTags/t/02decency.t.~1~	Wed Oct 22 20:23:59 2003
+++ lib/I18N/LangTags/t/02decency.t	Wed Oct 22 20:23:59 2003
@@ -0,0 +1,30 @@
+
+require 5;
+ # Time-stamp: "2003-10-10 17:37:34 ADT"
+use strict;
+use Test;
+BEGIN { plan tests => 17 };
+BEGIN { ok 1 }
+use I18N::LangTags::List;
+
+print "# Perl v$], I18N::LangTags::List v$I18N::LangTags::List::VERSION\n";
+
+ok  I18N::LangTags::List::name('fr'), 'French';
+ok  I18N::LangTags::List::name('fr-fr');
+ok !I18N::LangTags::List::name('El Zorcho');
+ok !I18N::LangTags::List::name();
+
+
+ok !I18N::LangTags::List::is_decent();
+ok  I18N::LangTags::List::is_decent('fr');
+ok  I18N::LangTags::List::is_decent('fr-blorch');
+ok !I18N::LangTags::List::is_decent('El Zorcho');
+ok !I18N::LangTags::List::is_decent('sgn');
+ok  I18N::LangTags::List::is_decent('sgn-us');
+ok !I18N::LangTags::List::is_decent('i');
+ok  I18N::LangTags::List::is_decent('i-mingo');
+ok  I18N::LangTags::List::is_decent('i-mingo-tom');
+ok !I18N::LangTags::List::is_decent('cel');
+ok  I18N::LangTags::List::is_decent('cel-gaulish');
+
+ok 1; # one for the road
End of Patch.


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About