Locale-Unicode-Data

 view release on metacpan or  search on metacpan

lib/Locale/Unicode/Data.pm  view on Meta::CPAN

}, @_ ) ); }

sub unit_aliases { return( shift->_fetch_all({
    id      => 'unit_aliases',
    table   => 'unit_aliases',
}, @_ ) ); }

sub unit_constant { return( shift->_fetch_one({
    id      => 'get_unit_constant',
    field   => 'constant',
    table   => 'unit_constants',
}, @_ ) ); }

sub unit_constants { return( shift->_fetch_all({
    id      => 'unit_constants',
    table   => 'unit_constants',
}, @_ ) ); }

sub unit_conversion { return( shift->_fetch_one({
    id          => 'get_unit_conversion',
    field       => 'source',
    table       => 'unit_conversions',
    has_array   => [qw( systems )],
}, @_ ) ); }

sub unit_conversions { return( shift->_fetch_all({
    id          => 'unit_conversions',
    table       => 'unit_conversions',
    by          => [qw( base_unit category )],
    has_array   => [qw( systems )],
}, @_ ) ); }

sub unit_l10n { return( shift->_fetch_one({
    id          => 'get_unit_l10n',
    field       => 'unit_id',
    table       => 'units_l10n',
    requires    => [qw( locale format_length unit_type count gender gram_case )],
    default     => { count => undef, gender => undef, gram_case => undef },
}, @_ ) ); }

sub units_l10n { return( shift->_fetch_all({
    id          => 'units_l10n',
    table       => 'units_l10n',
    by          => [qw( locale format_length unit_type unit_id pattern_type count gender gram_case )],
}, @_ ) ); }

sub unit_prefix { return( shift->_fetch_one({
    id      => 'get_unit_prefix',
    field   => 'unit_id',
    table   => 'unit_prefixes',
}, @_ ) ); }

sub unit_prefixes { return( shift->_fetch_all({
    id      => 'unit_prefixes',
    table   => 'unit_prefixes',
}, @_ ) ); }

sub unit_pref { return( shift->_fetch_one({
    id      => 'get_unit_pref',
    field   => 'unit_id',
    table   => 'unit_prefs',
}, @_ ) ); }

sub unit_prefs { return( shift->_fetch_all({
    id      => 'unit_prefs',
    table   => 'unit_prefs',
    by      => [qw( territory category )],
}, @_ ) ); }

sub unit_quantity { return( shift->_fetch_one({
    id      => 'get_unit_quantity',
    field   => 'base_unit',
    table   => 'unit_quantities',
}, @_ ) ); }

sub unit_quantities { return( shift->_fetch_all({
    id          => 'unit_quantities',
    table       => 'unit_quantities',
    by          => [qw( quantity )],
    has_status  => 1,
}, @_ ) ); }

sub variant { return( shift->_fetch_one({
    id      => 'get_variant',
    field   => 'variant',
    table   => 'variants',
}, @_ ) ); }

sub variants { return( shift->_fetch_all({
    id      => 'variants',
    table   => 'variants',
    has_status  => 1,
}, @_ ) ); }

sub variant_l10n { return( shift->_fetch_one({
    id          => 'get_variant_l10n',
    field       => 'variant',
    table       => 'variants_l10n',
    requires    => [qw( locale alt )],
    default     => { alt => undef },
}, @_ ) ); }

sub variants_l10n { return( shift->_fetch_all({
    id          => 'variants_l10n',
    table       => 'variants_l10n',
    by          => [qw( locale alt )],
}, @_ ) ); }

sub week_preference { return( shift->_fetch_one({
    id          => 'get_week_preference',
    field       => 'locale',
    table       => 'week_preferences',
    has_array   => [qw( ordering )],
}, @_ ) ); }

sub week_preferences { return( shift->_fetch_all({
    id          => 'week_preferences',
    table       => 'week_preferences',
    has_array   => [qw( ordering )],
}, @_ ) ); }

sub _dbh
{
    my $self = shift( @_ );
    my $opts = $self->_get_args_as_hash( @_ );
    my $file = $opts->{datafile} || $self->datafile || $DB_FILE;

lib/Locale/Unicode/Data.pm  view on Meta::CPAN

    my $all = $cldr->time_formats( locale => 'en' );
    my $ref = $cldr->timezone( timezone => 'Asia/Tokyo' );
    my $all = $cldr->timezones;
    my $all = $cldr->timezones( territory => 'US' );
    my $all = $cldr->timezones( region => 'Asia' );
    my $all = $cldr->timezones( tzid => 'sing' );
    my $all = $cldr->timezones( tz_bcpid => 'sgsin' );
    my $all = $cldr->timezones( metazone => 'Singapore' );
    my $all = $cldr->timezones( is_golden => undef );
    my $all = $cldr->timezones( is_golden => 1 );
    my $all = $cldr->timezones( is_primary => 1 );
    my $all = $cldr->timezones( is_canonical => 1 );
    my $ref = $cldr->timezone_city(
        locale => 'fr',
        timezone => 'Asia/Tokyo',
    );
    my $all = $cldr->timezones_cities;
    my $ref = $cldr->timezone_info(
        timezone    => 'Asia/Tokyo',
        start       => undef,
    );
    my $ref = $cldr->timezone_info(
        timezone    => 'Europe/Simferopol',
        start       => ['>1991-01-01', '<1995-01-01'],
    );
    my $all = $cldr->timezones_info;
    my $all = $cldr->timezones_info( metazone => 'Singapore' );
    my $all = $cldr->timezones_info( start => undef );
    my $all = $cldr->timezones_info( until => undef );
    my $ref = $cldr->unit_alias( alias => 'meter-per-second-squared' );
    my $all = $cldr->unit_aliases;
    my $ref = $cldr->unit_constant( constant => 'lb_to_kg' );
    my $all = $cldr->unit_constants;
    my $ref = $cldr->unit_conversion( source => 'kilogram' );
    my $all = $cldr->unit_conversions;
    my $all = $cldr->unit_conversions( base_unit => 'kilogram' );;
    my $all = $cldr->unit_conversions( category => 'kilogram' );
    my $ref = $cldr->unit_l10n(
        locale          => 'en',
        # long, narrow, short
        format_length   => 'long',
        # compound, regular
        unit_type       => 'regular',
        unit_id         => 'length-kilometer',
        count           => 'one',
        gender          => undef,
        gram_case       => undef,
    );
    my $all = $cldr->units_l10n;
    my $all = $cldr->units_l10n( locale => 'en' );
    my $all = $cldr->units_l10n(
        locale          => 'en',
        format_length   => 'long',
        unit_type       => 'regular',
        unit_id         => 'length-kilometer',
        pattern_type    => 'regular',
    );
    my $ref = $cldr->unit_prefix( unit_id => 'micro' );
    my $all = $cldr->unit_prefixes;
    my $ref = $cldr->unit_pref( unit_id => 'square-meter' );
    my $all = $cldr->unit_prefs;
    my $all = $cldr->unit_prefs( territory => 'US' );
    my $all = $cldr->unit_prefs( category => 'area' );
    my $ref = $cldr->unit_quantity( base_unit => 'kilogram' );
    my $all = $cldr->unit_quantities;
    my $all = $cldr->unit_quantities( quantity => 'mass' );
    my $ref = $cldr->variant( variant => 'valencia' );
    my $all = $cldr->variants;
    my $ref = $cldr->variant_l10n(
        locale  => 'en',
        alt     => undef,
        variant => 'valencia',
    );
    my $all = $cldr->variants_l10n;
    my $all = $cldr->variants_l10n( locale => 'en' );
    my $all = $cldr->variants_l10n(
        locale  => 'en',
        alt     => undef,
    );
    my $ref = $cldr->week_preference( locale => 'ja' );
    my $all = $cldr->week_preferences;

With advanced search:

    my $all = $cldr->timezone_info(
        timezone => 'Europe/Simferopol',
        start => ['>1991-01-01','<1995-01-01'],
    );
    my $all = $cldr->time_formats(
        region => '~^U.*',
    );
    my $all = $cldr->time_formats(
        region => qr/^U.*/,
    );

Enabling fatal exceptions:

    use v5.34;
    use experimental 'try';
    no warnings 'experimental';
    try
    {
        my $locale = Locale::Unicode::Data->new( fatal => 1 );
        # Missing the 'width' argument
        my $str = $cldr->timezone_names( timezone => 'Asia/Tokyo', locale => 'en' );
        # More code
    }
    catch( $e )
    {
        say "Oops: ", $e->message;
    }

Or, you could set the global variable C<$FATAL_EXCEPTIONS> instead:

    use v5.34;
    use experimental 'try';
    no warnings 'experimental';
    $Locale::Unicode::Data::FATAL_EXCEPTIONS = 1;
    try
    {
        my $locale = Locale::Unicode::Data->new;
        # Missing the 'width' argument
        my $str = $cldr->timezone_names( timezone => 'Asia/Tokyo', locale => 'en' );

lib/Locale/Unicode/Data.pm  view on Meta::CPAN

This contains all the references behind the CLDR data.

=item * L<BCP47 time zones|/"Table bcp47_timezones">

This contains BCP 47 time zones along with possible aliases and preferred time zone

=item * L<BCP47 currencies|/"Table bcp47_currencies">

This includes the currency ID, an ISO 4217 code, description and a boolean value whether it is obsolete or not.

=item * L<BCP47 extensions|/"Table bcp47_extensions">

This contains the extension category, extension ID, possibly alias, value type and description, and whether it is deprecated,

=item * L<BCP47 extension values|/"Table bcp47_values">

This includes an extension category, and extension ID, an extension value and description.

=item * L<Annotations|/"Table annotations">

This provide annotations (single character like a symbol or an emoji) and default short description for a given C<locale>

=item * L<RBNF (Rule-Based Number Format)|/"Table rbnf">

This provides RBNF rules with its grouping value, such as C<SpelloutRules> or C<OrdinalRules>, the rule set ID such as C<spellout-numbering-year> or C<spellout-cardinal>, the rule ID such as C<Inf> and the rule value.

=item * L<Casings|/"Table casings">

This provides information about casing for a given C<locale>

It includes the C<locale>, a C<token> such as C<currencyName>, C<language> and a C<value>, such as C<lowercase>, C<titlecase>

=item * L<Localised calendar terms|/"Table calendar_terms">

This provides localised terms used in different parts of a calendar system, for a given C<locale> and C<calendar> ID.

=item * L<Localised calendar eras|/"Table calendar_eras">

This provides the localised era names for a given C<locale> and C<calendar> ID.

=item * Localised L<calendar date, time|/"Table calendar_datetime_formats"> and L<interval formattings|/"Table calendar_interval_formats">

This provides the C<CLDR> C<DateTime> formattings for a given C<locale> and C<calendar> ID.

=item * L<Language matching|/"Table languages_match">

This provides a matching between a desired C<locale> and what is actually supported, and a C<distance> factor, which designed to be the opposite of a percentage, by Unicode. The desired C<locale> can be a perl regular expression.

=item * Unit L<constants|/"Table unit_constants">

Some constant values declared for certain measurement units.

=item * L<Unit quantities|/"Table unit_quantities">

Defines the quantity type for certain units.

=item * L<Unit conversions|/"Table unit_conversions">

Define a list of unit conversion from one unit to another.

=item * L<Unit preferences by territories|/unit_prefs">

Defines what units are preferred by territory.

=item * L<Unit aliases|/"Table unit_aliases">

Provides some aliases for otherwise outdated units.

=item * L<Localised units|/"Table units_l10n">

Localised unit formatting.

=item * Locale L<Number symbols|/"Table number_symbols_l10n">

Value used for each locale for C<approximately>, C<currency_decimal>, C<currency_group>, C<decimal>, C<exponential>, C<group>, C<infinity>, C<list>, C<minus>, C<nan>, C<per_mille>, C<percent>, C<plus>, C<superscript>, and C<time_separator>

Not every C<locale> has a value for each of those properties though.

=item * L<Locale number formatting|/"Table number_formats_l10n">

Localised formatting for currency or decimal numbers.

=back

If you need a more granular access to the data, feel free to access the SQL data directly. You can retrieve a L<database handler|/database_handler>, as an instance of the L<DBI> API, or you can instantiate a connection yourself using the L<database f...

=head1 CONSTRUCTOR

=head2 new

This takes some hash or hash reference of options, instantiates a new L<Locale::Unicode::Data> object, connects to the SQLite database file specified, or the default one, and returns the newly instantiated object.

If an error occurred, an L<error object|Locale::Unicode::Data::Exception> is created and C<undef> is returned in scalar context, or an empty list in list context.

Supported options are as follows. Each option can be later accessed or modified by their associated method.

=over 4

=item * C<datafile>

The file path to the SQLite database file. If this option is not provided, the SQLite database file used will be the one set in the global variable C<$DB_FILE>

=item * C<decode_sql_arrays>

Boolean value to enable or disable automatic decoding of SQL arrays into perl arrays using L<JSON::XS>

This is enabled by default.

If you want to retrieve a lot of data and do not need access to those arrays, you should deactivate decoding to improve speed.

=back

If an error occurs, an L<exception object|Locale::Unicode::Data::Exception> is set and C<undef> is returned in scalar context, or an empty list in list context. The L<exception object|Locale::Unicode::Data::Exception> can then be retrieved using L<er...

    my $cldr = Locale::Unicode::Data->new( $somthing_bad ) ||
        die( Locale::Unicode::Data->error );

=head1 METHODS

=head2 alias

lib/Locale/Unicode/Data.pm  view on Meta::CPAN

    my $ref = $cldr->unit_prefix( unit_id => 'micro' );
    # Returns an hash reference like this:
    {
        unit_prefix_id  => 9,
        unit_id         => 'micro',
        symbol          => 'μ',
        power           => 10,
        factor          => -6,
    }

Returns an hash reference of a unit prefix information from the table L<unit_prefixes|/"Table unit_prefixes"> based on the C<unit_id> ID provided.

The meaning of the fields are as follows:

=over 4

=item * C<unit_prefix_id>

A unique incremental value automatically generated by SQLite.

=item * C<unit_id>

A C<unit> ID

=item * C<symbol>

A string representing the unit symbol.

=item * C<power>

A value representing the unit power

=item * C<factor>

A value representing the unit factor.

=back

=head2 unit_prefixes

    my $all = $cldr->unit_prefixes;

Returns all the unit prefixes information as an array reference of hash reference from the L<table unit_prefixes|/"Table unit_prefixes">

No additional parameter is needed.

=head2 unit_pref

    my $ref = $cldr->unit_pref( unit_id => 'square-meter' );
    # Returns an hash reference like this:
    {
        unit_pref_id    => 3,
        unit_id         => 'square-meter',
        territory       => '001',
        category        => 'area',
        usage           => 'default',
        geq             => undef,
        skeleton        => undef,
    }

Returns an hash reference of a unit preference information from the table L<unit_prefs|/"Table unit_prefs"> based on the C<unit_id> ID provided.

=head2 unit_prefs

    my $all = $cldr->unit_prefs;
    my $all = $cldr->unit_prefs( territory => 'US' );
    my $all = $cldr->unit_prefs( category => 'area' );

Returns all the unit preferences information as an array reference of hash reference from the L<table unit_prefs|/"Table unit_prefs">

A combination of the following fields may be provided to filter the information returned:

=over 4

=item * C<territory>

A C<territory> code as can be found in table L<territories|/"Table territories">

=item * C<category>

A category ID. Known categories are: C<area>, C<concentration>, C<consumption>, C<duration>, C<energy>, C<length>, C<mass>, C<mass-density>, C<power>, C<pressure>, C<speed>, C<temperature>, C<volume>, C<year-duration>

=back

=head2 unit_quantity

    my $ref = $cldr->unit_quantity( base_unit => 'kilogram' );
    # Returns an hash reference like this:
    {
        unit_quantity_id    => 4,
        base_unit           => 'kilogram',
        quantity            => 'mass',
        status              => 'simple',
        comment             => undef,
    }

Returns an hash reference of a unit quantities information from the table L<unit_quantities|/"Table unit_quantities"> based on the C<unit_id> ID provided.

The meaning of the fields are as follows:

=over 4

=item * C<unit_quantity_id>

A unique incremental value automatically generated by SQLite.

=item * C<base_unit>

A string representing the base unit.

=item * C<quantity>

A string representing the unit quantity.

Known values are: C<acceleration>, C<angle>, C<area>, C<catalytic-activity>, C<concentration>, C<concentration-mass>, C<consumption>, C<current-density>, C<digital>, C<duration>, C<electric-capacitance>, C<electric-charge>, C<electric-conductance>, C...

=item * C<status>

A string representing the unit status.

Known values are: C<undef> and C<simple>

=item * C<comment>

A text providing some comments about this unit quantity.

=back

=head2 unit_quantities

lib/Locale/Unicode/Data.pm  view on Meta::CPAN

=head2 Table unit_conversions

=over 4

=item * C<unit_conversion_id>

An integer field.

=item * C<source>

A string field.

=item * C<base_unit>

A string field.

=item * C<expression>

A string field.

=item * C<factor>

A decimal field.

=item * C<systems>

A string array field.

=item * C<category>

A string field.

=back

=head2 Table unit_prefixes

=over 4

=item * C<unit_prefix_id>

An integer field.

=item * C<unit_id>

A string field.

=item * C<symbol>

A string field.

=item * C<power>

An integer field.

=item * C<factor>

An integer field.

=back

=head2 Table unit_prefs

=over 4

=item * C<unit_pref_id>

An integer field.

=item * C<unit_id>

A string field.

=item * C<territory>

A string field.

=item * C<category>

A string field.

=item * C<usage>

A string field.

=item * C<geq>

A decimal field.

=item * C<skeleton>

A string field.

=back

=head2 Table unit_quantities

=over 4

=item * C<unit_quantity_id>

An integer field.

=item * C<base_unit>

A string field.

=item * C<quantity>

A string field.

=item * C<status>

A string field.

=item * C<comment>

A string field.

=back

=head2 Table units_l10n



( run in 1.692 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )