NAME
Locale::CLDR - Main Class for CLDR Locals
VERSION
Version 0.0.1
SYNOPSIS
This module handles Locale Data from the CLDR.
USAGE
my $locale = Locale::CLDR->new('en_GB');
or
my $locale = Locale::CLDR->new(language_id => 'en', territory_id => 'gb');
ATTRIBUTES
These can be passed into the constructor and all are optional.
- language_id
-
A valid language or language alias id, such as
en
- script_id
-
A valid script id, such as
latn
orCtcl
. The code will pick a likely script depending on the given language if non is provided. - territory_id
-
A valid territory id or territory alias such as
GB
- variant_id
-
A valid variant id. The code currently ignores this
- extensions
-
A Hashref of extension names and values. This is currently ignored but future releases will use it to override various assumptions such as calendar type and number type
Methods
The following methods can be called on the locale object
- id()
-
The local identifier. This is what you get if you attempt to stringify a locale object.
- likely_language()
-
Given a locale with no language passed in or with the explicit language code of
und
, this method attempts to use the script and territory data to guess the locales language. - likely_script()
-
Given a locale with no script passed in this method attempts to use the language and territory data to guess the locales script.
- likely_territory()
-
Given a locale with no territory passed in this method attempts to use the language and script data to guess the locales territory.
Meta Data
The following methods return, in English, the names if the various id's passed into the locales constructor. I.e. if you passed language =
'fr'> to the constructor you would get back French
for the language.
- name
-
The locales name. This is usually built up out of the language, script, territory and variant of the locale
- language
-
The name of the locales language
- script
-
The name of the locales script
- territory
-
The name of the locales territory
- variant
-
The name of the locales variant
Native Meta Data
Like Meta Data above this provides the names of the various id's passed into the locales constructor. However in this case the names are formatted to match the locale. I.e. if you passed language =
'fr'> to the constructor you would get back français
for the language.
- native_name
-
The locales name. This is usually built up out of the language, script, territory and variant of the locale. Returned in the locales language and script
- native_language
-
The name of the locales language in the locales language and script.
- native_script
-
The name of the locales script in the locales language and script.
- native_territory
-
The name of the locales territory in the locales language and script.
- native_variant
-
The name of the locales variant in the locales language and script.
Calenders
The Calendar data is built to hook into DateTime::Locale so that all Locale::CLDR objects can be used as replacements for DateTime::Locale's locale data
- month_format_wide
- month_format_abbreviated
- month_format_narrow
- month_stand_alone_wide
- month_stand_alone_abbreviated
- month_stand_alone_narrow
-
All the above return an arrayref of month names in the requested style.
- day_format_wide
- day_format_abbreviated
- day_format_narrow
- day_stand_alone_wide
- day_stand_alone_abbreviated
- day_stand_alone_narrow
-
All the above return an array ref of day names in the requested style.
- quarter_format_wide
- quarter_format_abbreviated
- quarter_format_narrow
- quarter_stand_alone_wide
- quarter_stand_alone_abbreviated
- quarter_stand_alone_narrow
-
All the above return an arrayref of quarter names in the requested style.
- am_pm_wide
- am_pm_abbreviated
- am_pm_narrow
-
All the above return the date period name for AM and PM in the requested style
- era_wide
- era_abbreviated
- era_narrow
-
All the above return an array ref of era names. Note that these return the first two eras which is what you normally want for BC and AD etc. but won't work correctly for Japanese calendars.
The next set of methods are not used by DateTime::Locale but CLDR provide the data and you might want it
- am_pm_format_wide
- am_pm_format_abbreviated
- am_pm_format_narrow
- am_pm_stand_alone_wide
- am_pm_stand_alone_abbreviated
- am_pm_stand_alone_narrow
-
All the above return a hashref keyed on date period with the value being the value for that date period
- era_format_wide
- era_format_abbreviated
- era_format_narrow
- era_stand_alone_wide
- era_stand_alone_abbreviated
- era_stand_alone_narrow
-
All the above return an array ref with all the era data for the locale formatted to the requested width
- date_format_full
- date_format_long
- date_format_medium
- date_format_short
- time_format_full
- time_format_long
- time_format_medium
- time_format_short
- datetime_format_full
- datetime_format_long
- datetime_format_medium
- datetime_format_short
-
All the above return the CLDR date format pattern for the given element and width
- prefers_24_hour_time()
-
Returns a boolean value, true if the locale has a preference for 24 hour time over 12 hour
- first_day_of_week()
-
Returns the numeric representation of the first day of the week With 0 = Saturday
- locale_name($name)
-
Returns the given locale name in the current locales format. The name can be a locale id or a locale object or non existent. If a name is not passed in then the name of the current locale is returned.
- language_name($language)
-
Returns the language name in the current locales format. The name can be a locale language id or a locale object or non existent. If a name is not passed in then the language name of the current locale is returned.
- all_languages()
-
Returns a hash ref keyed on language id of all the languages the system knows about. The values are the language names for the corresponding id's
- script_name($script)
-
Returns the script name in the current locales format. The script can be a locale script id or a locale object or non existent. If a script is not passed in then the script name of the current locale is returned.
- all_scripts()
-
Returns a hash ref keyed on script id of all the scripts the system knows about. The values are the script names for the corresponding id's
- territory_name($territory)
-
Returns the territory name in the current locales format. The territory can be a locale territory id or a locale object or non existent. If a territory is not passed in then the territory name of the current locale is returned.
- all_territories
-
Returns a hash ref keyed on territory id of all the territory the system knows about. The values are the territory names for the corresponding id's
- variant_name($variant)
-
Returns the variant name in the current locales format. The variant can be a locale variant id or a locale object or non existent. If a variant is not passed in then the variant name of the current locale is returned.
- key_name($key)
-
Returns the key name in the current locales format. The key must be a locale key id as a string
- type_name($key, $type)
-
Returns the type name in the current locales format. The key and type must be a locale key id and type id as a string
- measurement_system_name($measurement_system)
-
Returns the measurement system name in the current locales format. The measurement system must be a measurement system id as a string
- transform_name($name)
-
Returns the transform (transliteration) name in the current locales format. The transform must be a transform id as a string
- code_pattern($type, $locale)
-
This method formats a language, script or territory name, given as $type from $locale in a way expected by the current locale. If $locale is not passed in or is undef() the method uses the current locale.
- text_orientation($type)
-
Gets the text orientation for the locale. Type must be one of
lines
orcharacters
- split_grapheme_clusters($string)
-
Splits a string on grapheme clusters using the locals segmentation rules. Returns a list of grapheme clusters.
- split_words($string)
-
Splits a string on word boundaries using the locals segmentation rules. Returns a list of words.
- split_sentences($string)
-
Splits a string on on all points where a sentence could end using the locals segmentation rules. Returns a list the end of each list element is the point where a sentence could end.
- split_lines($string)
-
Splits a string on on all points where a line could end using the locals segmentation rules. Returns a list the end of each list element is the point where a line could end.
- is_exemplar_character( $type, $character)
- is_exemplar_character($character)
-
Tests if the given character is used in the locale. There are three possible types; c<main>,
auxiliary
and c<punctuation>. If no type is givenmain
is assumed. - index_characters()
-
Returns an array ref of characters normally used when creating an index.
- truncated_beginning($string)
-
Adds the locale specific marking to show that the string has been truncated at the beginning.
- truncated_between($string, $string)
-
Adds the locale specific marking to show that something has been truncated between the two strings. Returns a string comprising of the concatenation of the first string, the mark and the second string
- truncated_end($string)
-
Adds the locale specific marking to show that the string has been truncated at the end.
- truncated_word_beginning($string)
-
Adds the locale specific marking to show that the string has been truncated at the beginning. This should be used in preference to
truncated_beginning
when the truncation occurs on a word boundary. - truncated_word_between($string, $string)
-
Adds the locale specific marking to show that something has been truncated between the two strings. Returns a string comprising of the concatenation of the first string, the mark and the second string. This should be used in preference to
truncated_between
when the truncation occurs on a word boundary. - truncated_word_end($string)
-
Adds the locale specific marking to show that the string has been truncated at the end. This should be used in preference to
truncated_end
when the truncation occurs on a word boundary. - more_information()
-
The more information string is one that can be displayed in an interface to indicate that more information is available.
- quote($string)
-
Adds the locales primary quotation marks to the ends of the string. Also scans the string for paired primary and auxiliary quotation marks and flips them.
eg passing
z “abc” z
to this method for theen_GB
locale gives“z ‘abc’ z”
- measurement()
-
Returns the measurement type for the locale
- paper()
-
Returns the paper type for the locale
- all_units()
-
Returns a list of all the unit identifiers for the locale
- unit($number, $unit, $width)
-
Returns the localised string for the given number and unit formatted for the required width. The number must not be the localized version of the number. The returned string will be in the locales format, including the number.
- duration_unit($format, @data)
-
This method formats a duration. The format must be one of
hm
,hms
orms
corresponding tohour minuet
,hour minuet second
andminuet second
respectively. The data must correspond to the given format. - is_yes($string)
-
Returns true if the passed in string matches the locales idea of a string designating yes. Note that under POSIX rules unless the locales word for no starts with
Y
(U+0079) then a single 'y' will also be accepted as yes. The string will be matched case insensitive. - is_no($string)
-
Returns true if the passed in string matches the locales idea of a string designating no. Note that under POSIX rules unless the locales word for yes starts with
n
(U+006E) then a single 'n' will also be accepted as no The string will be matched case insensitive. - transform(from => $from, to => $to, variant => $variant, text => $text)
-
This method returns the transliterated string of
text
from scriptfrom
to scriptto
using variantvariant
. If c<from> is not given then the current locales script is used. Iftext
is not given then it defaults to an empty string. Thevariant
is optional. - list(@data)
-
Returns
data
as a string formatted by the locales idea of producing a list of elements. What is returned can be effected by the locale and the number of items indata
. Note thatdata
can contain 0 or more items. - plural($number)
-
This method takes a number and uses the locales pluralisation rules to calculate the type of pluralisation required for units, currencies and other data that changes depending on the plural state of the number
- get_day_period($time)
-
This method will calculate the correct period for a given time and return the period name in the Locales language and script
- format_for
-
TODO fix this
AUTHOR
John Imrie, <j dot imrie1 at virginmedia.com>
BUGS
Please report any bugs or feature requests to me at the above email address and ignore the CPAN stuff below for the present
Please report any bugs or feature requests to bug-locale-cldr at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Locale-CLDR. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Locale::CLDR
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2009-2014 John Imrie.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.