Show
Ignore:
Timestamp:
06/18/08 02:03:47 (18 months ago)
Author:
fumiakiy
Message:

Updating I18N::LangTags to version 0.35 and Locale::MakeText to version 1.13 for better support of Perl 5.10. BugId:80126

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-40/extlib/I18N/LangTags.pm

    r1098 r2594  
    11 
    2 # Time-stamp: "2002-02-02 20:43:03 MST" 
     2# Time-stamp: "2004-10-06 23:26:33 ADT" 
    33# Sean M. Burke <sburke@cpan.org> 
    44 
     
    1515                locale2language_tag alternate_language_tags 
    1616                encode_language_tag panic_languages 
     17                implicate_supers 
     18                implicate_supers_strictly 
    1719               ); 
    1820%EXPORT_TAGS = ('ALL' => \@EXPORT_OK); 
    1921 
    20 $VERSION = "0.27"; 
     22$VERSION = "0.35"; 
     23 
     24sub uniq { my %seen; return grep(!($seen{$_}++), @_); } # a util function 
     25 
    2126 
    2227=head1 NAME 
     
    2631=head1 SYNOPSIS 
    2732 
    28     use I18N::LangTags qw(is_language_tag same_language_tag 
    29                           extract_language_tags super_languages 
    30                           similarity_language_tag is_dialect_of 
    31                           locale2language_tag alternate_language_tags 
    32                           encode_language_tag panic_languages 
    33                          ); 
    34  
    35 ...or whatever of those functions you want to import.  Those are 
    36 all the exportable functions -- you're free to import only some, 
    37 or none at all.  By default, none are imported.  If you say: 
     33  use I18N::LangTags(); 
     34 
     35...or specify whichever of those functions you want to import, like so: 
     36 
     37  use I18N::LangTags qw(implicate_supers similarity_language_tag); 
     38 
     39All the exportable functions are listed below -- you're free to import 
     40only some, or none at all.  By default, none are imported.  If you 
     41say: 
    3842 
    3943    use I18N::LangTags qw(:ALL) 
     
    400404 
    401405  $lang =~ tr<_><->;  # "en_US" -> en-US 
    402   $lang =~ s<\.[-_a-zA-Z0-9\.]*><>s;  # "en_US.ISO8859-1" -> en-US 
     406  $lang =~ s<(?:[\.\@][-_a-zA-Z0-9]+)+$><>s;  # "en_US.ISO8859-1" -> en-US 
     407   # it_IT.utf8@euro => it-IT 
    403408 
    404409  return $lang if &is_language_tag($lang); 
     
    530535  $tag =~ s/^iw\b/he/i; # Hebrew 
    531536  $tag =~ s/^in\b/id/i; # Indonesian 
     537  $tag =~ s/^cre\b/cr/i; # Cree 
     538  $tag =~ s/^jw\b/jv/i; # Javanese 
    532539  $tag =~ s/^[ix]-lux\b/lb/i;  # Luxemburger 
    533540  $tag =~ s/^[ix]-navajo\b/nv/i;  # Navajo 
    534541  $tag =~ s/^ji\b/yi/i;  # Yiddish 
     542  # SMB 2003 -- Hm.  There's a bunch of new XXX->YY variances now, 
     543  #  but maybe they're all so obscure I can ignore them.   "Obscure" 
     544  #  meaning either that the language is obscure, and/or that the 
     545  #  XXX form was extant so briefly that it's unlikely it was ever 
     546  #  used.  I hope. 
    535547  # 
    536548  # These go FROM the simplex to complex form, to get 
     
    731743} 
    732744 
     745#--------------------------------------------------------------------------- 
     746#--------------------------------------------------------------------------- 
     747 
     748=item * the function implicate_supers( ...languages... ) 
     749 
     750This takes a list of strings (which are presumed to be language-tags; 
     751strings that aren't, are ignored); and after each one, this function 
     752inserts super-ordinate forms that don't already appear in the list. 
     753The original list, plus these insertions, is returned. 
     754 
     755In other words, it takes this: 
     756 
     757  pt-br de-DE en-US fr pt-br-janeiro 
     758 
     759and returns this: 
     760 
     761  pt-br pt de-DE de en-US en fr pt-br-janeiro 
     762 
     763This function is most useful in the idiom 
     764 
     765  implicate_supers( I18N::LangTags::Detect::detect() ); 
     766 
     767(See L<I18N::LangTags::Detect>.) 
     768 
     769 
     770=item * the function implicate_supers_strictly( ...languages... ) 
     771 
     772This works like C<implicate_supers> except that the implicated 
     773forms are added to the end of the return list. 
     774 
     775In other words, implicate_supers_strictly takes a list of strings 
     776(which are presumed to be language-tags; strings that aren't, are 
     777ignored) and after the whole given list, it inserts the super-ordinate forms  
     778of all given tags, minus any tags that already appear in the input list. 
     779 
     780In other words, it takes this: 
     781 
     782  pt-br de-DE en-US fr pt-br-janeiro 
     783 
     784and returns this: 
     785 
     786  pt-br de-DE en-US fr pt-br-janeiro pt de en 
     787 
     788The reason this function has "_strictly" in its name is that when 
     789you're processing an Accept-Language list according to the RFCs, if 
     790you interpret the RFCs quite strictly, then you would use 
     791implicate_supers_strictly, but for normal use (i.e., common-sense use, 
     792as far as I'm concerned) you'd use implicate_supers. 
     793 
     794=cut 
     795 
     796sub implicate_supers { 
     797  my @languages = grep is_language_tag($_), @_; 
     798  my %seen_encoded; 
     799  foreach my $lang (@languages) { 
     800    $seen_encoded{ I18N::LangTags::encode_language_tag($lang) } = 1 
     801  } 
     802 
     803  my(@output_languages); 
     804  foreach my $lang (@languages) { 
     805    push @output_languages, $lang; 
     806    foreach my $s ( I18N::LangTags::super_languages($lang) ) { 
     807      # Note that super_languages returns the longest first. 
     808      last if $seen_encoded{ I18N::LangTags::encode_language_tag($s) }; 
     809      push @output_languages, $s; 
     810    } 
     811  } 
     812  return uniq( @output_languages ); 
     813 
     814} 
     815 
     816sub implicate_supers_strictly { 
     817  my @tags = grep is_language_tag($_), @_; 
     818  return uniq( @_,   map super_languages($_), @_ ); 
     819} 
     820 
     821 
     822 
    733823########################################################################### 
    7348241; 
     
    771861C<http://www.perl.com/CPAN/modules/by-module/Locale/> 
    772862 
    773 * ISO 639, "Code for the representation of names of languages", 
    774 C<http://www.indigo.ie/egt/standards/iso639/iso639-1-en.html> 
    775  
    776863* ISO 639-2, "Codes for the representation of names of languages", 
    777 including three-letter codes, 
    778 C<http://lcweb.loc.gov/standards/iso639-2/bibcodes.html> 
     864including two-letter and three-letter codes, 
     865C<http://www.loc.gov/standards/iso639-2/langcodes.html> 
    779866 
    780867* The IANA list of registered languages (hopefully up-to-date), 
    781 C<ftp://ftp.isi.edu/in-notes/iana/assignments/languages/> 
     868C<http://www.iana.org/assignments/language-tags> 
    782869 
    783870=head1 COPYRIGHT 
    784871 
    785 Copyright (c) 1998-2001 Sean M. Burke. All rights reserved. 
     872Copyright (c) 1998+ Sean M. Burke. All rights reserved. 
    786873 
    787874This library is free software; you can redistribute it and/or