package DateTime::Locale;
use strict;
use DateTime::LocaleCatalog;
# Loading this here isn't necessary, but it makes it easier to catch
# syntax errors when testing.
use DateTime::Locale::Base;
use Params::Validate qw( validate validate_pos SCALAR );
use vars qw($VERSION);
$VERSION = 0.35;
BEGIN
{
if ( $] >= 5.006 )
{
require utf8; import utf8;
}
}
my %Class;
my %DataForID;
my %NameToID;
my %NativeNameToID;
my %AliasToID;
my %IDToExtra;
my %LoadCache;
sub register
{
my $class = shift;
%LoadCache = ();
if ( ref $_[0] )
{
$class->_register(%$_) foreach @_;
}
else
{
$class->_register(@_);
}
}
sub _register
{
my $class = shift;
my %p = validate( @_,
{ id => { type => SCALAR },
en_language => { type => SCALAR },
en_script => { type => SCALAR, optional => 1 },
en_territory => { type => SCALAR, optional => 1 },
en_variant => { type => SCALAR, optional => 1 },
native_language => { type => SCALAR, optional => 1 },
native_script => { type => SCALAR, optional => 1 },
native_territory => { type => SCALAR, optional => 1 },
native_variant => { type => SCALAR, optional => 1 },
# undocumented hack so we don't have to
# generate .pm files for CLDR XML locales which
# don't differ from their parents in terms of
# datetime data.
real_class => { type => SCALAR, optional => 1 },
class => { type => SCALAR, optional => 1 },
replace => { type => SCALAR, default => 0 },
} );
my $id = $p{id};
die "'\@' or '=' are not allowed in locale ids"
if $id =~ /[\@=]/;
die "You cannot replace an existing locale ('$id') unless you also specify the 'replace' parameter as true\n"
if ! delete $p{replace} && exists $DataForID{$id};
$p{native_language} = $p{en_language}
unless exists $p{native_language};
my @en_pieces;
my @native_pieces;
foreach my $p ( qw( language script territory variant ) )
{
push @en_pieces, $p{"en_$p"} if exists $p{"en_$p"};
push @native_pieces, $p{"native_$p"} if exists $p{"native_$p"};
}
$p{en_complete_name} = join ' ', @en_pieces;
$p{native_complete_name} = join ' ', @native_pieces;
$DataForID{$id} = \%p;
$NameToID{ $p{en_complete_name} } = $id;
$NativeNameToID{ $p{native_complete_name} } = $id;
=1= |