home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeJava and XSLTSearch this book

8.122. I18N::LangTags

Implements language tags per RFC 3066. Language tags let you specify a certain language that you'll use in a segment of text or code. I18N::LangTags lets you perform a number of common tasks with language tasks that you might come across when dealing with different protocols and applications.

I18N::LangTags is shipped with the Perl 5.8 source kit. It implements the following methods.

alternate_language_tags

alternate_language_tags(language)

Returns all language tags that are alternate forms of language:

alternate_language_tags('en'); # Returns ()
alternate_language_tags('he'); # Returns ('iw')
alternate_language_tags('iw'); # Returns ('he')
encode_language_tag

encode_language_tag(language)

Returns the encoding of a language tag. Returns undef if language is invalid.

extract_language_tags

extract_language_tags(source)

Returns a list of what is perceived as valid language tags from source. For example:

my $chewbacca_dialect = 'growl, growl, fr, growl, growl!';
extract_language_tags($chewbacca_dialect);
# Returns 'fr'  Chewbacca is French?!  Say it isn't so!
is_dialect_of

is_dialect_of(lang1, lang2) 

Returns true if lang1 represents a form of lang2. It doesn't go both ways, so make sure that lang1 comes first.

is_dialect_of('en-US', 'en'); # true
is_dialect_of('en', 'en-US'); # false
is_language_tag

is_language_tag(language)

Returns true if language is a valid language tag. For example:

my $gutteral = 'Chewbacca';
is_language_tag($gutteral);  # false
 
my $pourquois = 'fr';
is_language_tag($pourquois); # true
locale2language_tag

locale2language_tag(locale)

Takes a locale name and maps it to a language tag. Certain tags aren't mappable, such as C or POSIX, in which case local2language_tag will return an empty list.

locale2language_tag('en');    # Returns 'en' 
locale2language_tag('POSIX'); # Returns undef or ()
same_language_tag

same_language_tag(lang1, lang2)

Returns true if lang1 and lang2 both represent the same language form. For example:

same_language_tag('en', 'en-US'); # Returns false 
en != en-US
similarity_language_tag

similarity_language_tag(lang1, lang2)

Returns an integer that represents the degree of similarity between lang1 and lang2:

similarity_language_tag('fr', 'fr-ca'); # 1
similarity_language_tag('fr', 'en-US'); # 0
super_languages

super_languages(language)

Returns a list of language tags that are superordinate to language:

super_languages('en-US'); # Gets 'en'
super_languages('en');    # Gets an empty list


Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.