📄 locale.pm
字号:
and will not be returned by querying methods such as C<ids()> orC<names()>. register( id => $locale_id, en_language => ..., # something like 'English' or 'Afar', # All other keys are optional. These are: en_territory => ..., en_variant => ..., native_language => ..., native_territory => ..., native_variant => ..., # Optional - defaults to DateTime::Locale::$locale_id class => $class_name, replace => $boolean )The locale id and English name are required, and the following formatsshould used wherever possible: id: languageId[_territoryId[_variantId]] Where: languageId = Lower case ISO 639 code - Always choose 639-1 over 639-2 where possible. territoryId = Upper case ISO 3166 code - Always choose 3166-1 over 3166-2 where possible. variantId = Upper case variant id - Basically anything you want, since this is typically the component that uniquely identifies a custom locale.You cannot not use '@' or '=' in locale ids - these are reserved forfuture use. The underscore (_) is the component separator, and shouldnot be used for any other purpose.If the "native_*" components are supplied, they must be utf8 encodedand follow:If omitted, the native name is assumed to be identical to the Englishname.If class is supplied, it must be the full module name of your customlocale. If omitted, the locale module is assumed to be aDateTime::Locale subclass.Examples: DateTime::Locale->register ( id => 'en_GB_RIDAS', en_language => 'English', en_territory => 'United Kingdom', en_variant => 'Ridas Custom Locale', ); # Returns instance of class DateTime::Locale::en_GB_RIDAS my $l = DateTime::Locale->load('en_GB_RIDAS'); DateTime::Locale->register ( id => 'hu_HU', en_language => 'Hungarian', en_territory => Hungary', native_language => 'Magyar', native_territory => 'Magyarorsz谩g', ); # Returns instance of class DateTime::Locale::hu_HU my $l = DateTime::Locale->load('hu_HU'); DateTime::Locale->register ( id => 'en_GB_RIDAS', name => 'English United Kingdom Ridas custom locale', class => 'Ridas::Locales::CustomGB', ); # Returns instance of class Ridas::Locales::CustomGB # NOT Ridas::Locales::Custom::en_GB_RIDAS ! my $l = DateTime::Locale->load('en_GB_RIDAS');If you a locale for that id already exists, you must specify the"replace" parameter as true, or an exception will be thrown.The complete name for a registered locale is generated by joiningtogether the language, territory, and variant components with a singlespace.This means that in the first example, the complete English and nativenames for the locale would be "English United Kingdom Ridas CustomLocale", and in the second example the complete English name is"Hungarian Hungary", while the complete native name is "MagyarMagyarorsz谩g". The locale will be loadable by these complete names(English and native), via the C<load()> method.=back=head1 ADDING CUSTOM LOCALESThese are added in one of two ways:=over 4=item 1.Subclass an existing locale implementing only the changes you require.=item 2.Create a completely new locale.=backIn either case the locale MUST be registered before use.=head2 Subclass an existing locale.The following example sublasses the United Kingdom English locale toprovide different date/time formats: package Ridas::Locale::en_GB_RIDAS1; use strict; use DateTime::Locale::en_GB; @Ridas::Locale::en_GB_RIDAS1::ISA = qw ( DateTime::Locale::en_GB ); my $locale_id = 'en_GB_RIDAS1'; my $date_formats = [ "%A %{day} %B %{ce_year}", "%{day} %B %{ce_year}", "%{day} %b %{ce_year}", "%{day}/%m/%y", ]; my $time_formats = [ "%H h %{minute} %{time_zone_short_name}", "%{hour12}:%M:%S %p", "%{hour12}:%M:%S %p", "%{hour12}:%M %p", ]; sub date_formats { $date_formats } sub time_formats { $time_formats } 1;Now register it: DateTime::Locale->register ( id => 'en_GB_RIDAS1', # name, territory, and variant as described in register() documentation class => 'Ridas::Locale::en_GB_RIDAS1' );=head2 Creating a completely new localeA completely new custom locale must implement the following methods: id month_names month_abbreviations day_names day_abbreviations am_pms eras date_formats time_formats datetime_format_pattern_order date_parts_order _default_date_format_length _default_time_format_lengthSee C<DateTime::Locale::Base> for a description of each method, andtake a look at F<DateTime/Locale/root.pm> for an example of a completeimplementation.You are, of course, free to subclass C<DateTime::Locale::Base> if youwant to, though this is not required.Once created, remember to register it!Of course, you can always do the registration in the module itself,and simply load it before using it.=head1 LOCALE OBJECT METHODSAll objects that inherit from C<DateTime::Locale::Base> will offercertain methods. All the included locales areC<DateTime::Locale::Base> subclasses.The following methods can be used to get information about thelocale's id and name.=over 4=item * idThe complete locale id, something like "en_US".=item * language_idThe language portion of the id, like "en".=item * territory_idThe territory portion of the id, like "US".=item * variant_idThe variant portion of the id, like "PREEURO".=item * nameThe locale's complete name, which always includes at least a languagecomponent, plus optional territory and variant components. Somethinglike "English United States". The value returned will always be inEnglish.=item * language=item * territory=item * variantThe relevant component from the locale's complete name, like "English"or "United States".=item * native_nameThe locale's complete name in localized form as a UTF-8 string.=item * native_language=item * native_territory=item * native_variantThe relevant component from the locale's complete native name as aUTF-8 string.=backThe following methods all accept a C<DateTime.pm> object and returna localized name.=over 4=item * month_name ($dt)=item * month_abbreviation ($dt)=item * day_name ($dt)=item * day_abbreviation ($dt)=item * am_pm ($dt)=backThe following methods return strings appropriate for theC<DateTime.pm> C<strftime()> method:=over 4=item * full_date_format=item * long_date_format=item * medium_date_format=item * short_date_format=item * full_time_format=item * long_time_format=item * medium_time_format=item * short_time_format=item * full_datetime_format=item * long_datetime_format=item * medium_datetime_format=item * short_datetime_format=backThe following methods deal with the default format lengths:=over 4=item default_date_format_length=item default_time_format_lengthThese methods return one of "full", "long", "medium", or "short",indicating the current default format length.The default when an object is created is determined by the ICU localedata.=item set_default_date_format_length ($length)=item set_default_time_format_length ($length)These methods return one of "full", "long", "medium", or "short",indicating the current default format length.=backThe following methods can be used to get the object's raw localizationdata. If a method returns a reference, altering it will alter theobject, so make a copy if you need to do so.=over 4=item * month_namesReturns an array reference containing the full names of the months,with January as the first month.=item * month_abbreviationsReturns an array reference containing the abbreviated names of themonths, with January as the first month.=item * day_namesReturns an array reference containing the full names of the days,with Monday as the first day.=item * day_abbreviationsReturns an array reference containing the abbreviated names of thedays, with Monday as the first day.=item * am_pmsReturns an array reference containing the localized forms of "AM" and"PM".=item * date_formatsReturns a hash reference containing the date formats used for thelocale. The hash contains the keys "long", "full", "medium", and"short".=item * time_formatsReturns a hash reference containing the time formats used for thelocale. The hash contains the keys "long", "full", "medium", and"short".=item * date_before_timeThis returns a boolean value indicating whether or not the date comesbefore the time when formatting a complete date and time forpresentation.=item * date_parts_orderThis returns a string indicating the order of the parts of a date thatis in the form XX/YY/ZZ. The possible values are "dmy", "mdy", "ydm"and "ymd".=back=head1 SUPPORTPlease be aware that all locale data has been generated from theCommon XML Locale Repository project locales (originally ICU localedata). The data B<is> currently incomplete, and B<will> containerrors in some locales.When reporting errors in data, please check the primary data sourcesfirst, then where necessary report errors directly to the primarysource via the ICU project's Jitterbug system athttp://www.jtcsv.com/cgibin/icu-bugs/Once these errors have been confirmed, please forward the errorreport, and corrections to the DateTime mailing list,datetime@perl.org.Support for this module is provided via the datetime@perl.org emaillist. See http://lists.perl.org/ for more details.=head1 AUTHORSRichard Evans <rich@ridas.com>Dave Rolsky <autarch@urth.org>These modules are based on the DateTime::Language modules, which werein turn based on the Date::Language modules from Graham Barr'sTimeDate distribution.Thanks to Rick Measham for providing the Java to strftime patternconversion routines used during locale generation.=head1 COPYRIGHTCopyright (c) 2003 Richard Evans. All rights reserved.This program is free software; you can redistribute it and/or modifyit under the same terms as Perl itself.The full text of the license can be found in the LICENSE file includedwith this module.The locale modules in directory C<DateTime/Locale/> have beengenerated from data provided by the Common XML Locale Repositoryproject, see C<DateTime/Locale/LICENSE.icu> for details on the ICUdata's license.=head1 SEE ALSOL<DateTime::Locale::Base>datetime@perl.org mailing listhttp://datetime.perl.org/=cut
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -