Locale-Unicode-Data

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

        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',
        );

README  view on Meta::CPAN

            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 unit_prefs based on the "unit_id" ID provided.

  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 table unit_prefs

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

    *   "territory"

        A "territory" code as can be found in table territories

    *   "category"

README  view on Meta::CPAN

        A string field.

    *   "power"

        An integer field.

    *   "factor"

        An integer field.

  Table unit_prefs
    *   "unit_pref_id"

        An integer field.

    *   "unit_id"

        A string field.

    *   "territory"

README.md  view on Meta::CPAN

    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',
    );

README.md  view on Meta::CPAN

    Some constant values declared for certain measurement units.

- [Unit quantities](#table-unit_quantities)

    Defines the quantity type for certain units.

- [Unit conversions](#table-unit_conversions)

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

- [Unit preferences by territories](#unit_prefs)

    Defines what units are preferred by territory.

- [Unit aliases](#table-unit_aliases)

    Provides some aliases for otherwise outdated units.

- [Localised units](#table-units_l10n)

    Localised unit formatting.

README.md  view on Meta::CPAN

    {
        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 [unit\_prefs](#table-unit_prefs) based on the `unit_id` ID provided.

## 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 [table unit\_prefs](#table-unit_prefs)

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

- `territory`

    A `territory` code as can be found in table [territories](#table-territories)

- `category`

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

README.md  view on Meta::CPAN

    A string field.

- `power`

    An integer field.

- `factor`

    An integer field.

## Table unit\_prefs

- `unit_pref_id`

    An integer field.

- `unit_id`

    A string field.

- `territory`

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

}, @_ ) ); }

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({

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

    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',
    );

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

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.

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

    {
        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>

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

=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.

scripts/cldr-schema.sql  view on Meta::CPAN

    -- luminous-intensity, mass, volume, area, length, time, year-duration, electric-current, temperature, angle, substance-amount, portion, digital, graphics, typewidth, frequency, force, pressure, pressure-per-length, energy, th, power, voltage, el...
    ,category           VARCHAR(20)
    ,PRIMARY KEY(unit_conversion_id)
    ,CHECK( category REGEXP '^[a-zA-Z][a-zA-Z0-9]+(?:\-[a-zA-Z0-9]+)*$' )
    ,FOREIGN KEY(base_unit) REFERENCES unit_quantities(base_unit) ON UPDATE CASCADE ON DELETE RESTRICT
);
CREATE UNIQUE INDEX idx_unit_conversions_unique ON unit_conversions(source, base_unit);

-- Source: supplemental/units.xml/supplementalData/unitPreferenceData/unitPreferences/unitPreference
-- <https://cldr-smoke.unicode.org/spec/main/ldml/tr35-info.html#Unit_Preferences_Data>
CREATE TABLE unit_prefs (
     unit_pref_id       INTEGER
    -- Example: cubic-centimeter. One would expect this is a foreign key to unit_quantities, but it is not unfortunately
    ,unit_id            VARCHAR(70) NOT NULL COLLATE NOCASE
    ,territory          VARCHAR(3) NOT NULL
    -- Example: area, concentration, consumption, duration, energy, length, power, pressure, speed, temperature, volume, year-duration
    ,category           VARCHAR(20)
    -- Example: default, geograph, land, floor, blood-glucose, etc
    ,usage              VARCHAR(20)
    -- Example: 2.5
    ,geq                DECIMAL
    -- Example: precision-increment/50
    -- <https://github.com/unicode-org/icu/blob/main/docs/userguide/format_parse/numbers/skeletons.md#precision>
    ,skeleton           VARCHAR(70)
    ,PRIMARY KEY(unit_pref_id)
    ,CHECK( unit_id REGEXP '^[a-zA-Z][a-zA-Z0-9]+(?:\-[a-zA-Z0-9]+)*$' )
    ,CHECK( category REGEXP '^[a-zA-Z]+(?:\-[a-zA-Z0-9]+)*$' )
    ,CHECK( usage REGEXP '^[a-zA-Z]+(?:\-[a-zA-Z0-9]+)*$' )
    ,CHECK( skeleton REGEXP '^[a-zA-Z]+(?:\-[a-zA-Z0-9\/]+)*$' )
    ,FOREIGN KEY(territory) REFERENCES territories(territory) ON UPDATE CASCADE ON DELETE RESTRICT
);
CREATE UNIQUE INDEX idx_unit_prefs_unique ON unit_prefs(category, usage, unit_id, territory, geq);

-- Source: supplemental/units.xml/supplementalData/metadata/alias/unitAlias
CREATE TABLE unit_aliases (
     unit_alias_id      INTEGER
    ,alias              VARCHAR(70) NOT NULL COLLATE NOCASE
    ,target             VARCHAR(70) NOT NULL COLLATE NOCASE
    ,reason             VARCHAR(20)
    ,PRIMARY KEY(unit_alias_id)
    ,CHECK( alias REGEXP '^[a-zA-Z][a-zA-Z0-9]+(?:\-[a-zA-Z0-9]+)*$' )
    -- target could be '1e6', so it does not necessarily start with alphabetical characters

scripts/create_database.pl  view on Meta::CPAN

        # This is defined in the extend_timezones_cities() function
        timezones_cities_supplemental => undef,
        timezones_formats => "INSERT INTO timezones_formats (locale, type, subtype, format_pattern) VALUES(?, ?, ?, ?)",
        timezones_info => "INSERT INTO timezones_info (timezone, metazone, start, until) VALUES(?, ?, ?, ?)",
        timezones_names => "INSERT INTO timezones_names (locale, timezone, width, generic, standard, daylight) VALUES(?, ?, ?, ?, ?, ?)",
        unit_aliases => "INSERT INTO unit_aliases (alias, target, reason) VALUES(?, ?, ?)",
        unit_constants => "INSERT INTO unit_constants (constant, expression, value, description, status) VALUES(?, ?, ?, ?, ?)",
        unit_conversions => "INSERT INTO unit_conversions (source, base_unit, expression, factor, systems, category) VALUES(?, ?, ?, ?, ?, ?)",
        units_l10n => "INSERT INTO units_l10n (locale, format_length, unit_type, unit_id, unit_pattern, pattern_type, locale_name, count, gender, gram_case) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
        unit_prefixes => "INSERT INTO unit_prefixes (unit_id, symbol, power, factor) VALUES(?, ?, ?, ?)",
        unit_prefs => "INSERT INTO unit_prefs (unit_id, territory, category, usage, geq, skeleton) VALUES(?, ?, ?, ?, ?, ?)",
        unit_quantities => "INSERT INTO unit_quantities (base_unit, quantity, status, comment) VALUES(?, ?, ?, ?)",
        variants => "INSERT INTO variants (variant, status) VALUES(?, ?)",
        variants_l10n => "INSERT INTO variants_l10n (locale, variant, locale_name, alt) VALUES(?, ?, ?, ?)",
        week_preferences => "INSERT INTO week_preferences (locale, ordering) VALUES(?, ?)",
    ];
    my $sths = {};
    
    for( my $i = 0; $i < scalar( @$queries ); $i += 2 )
    {
        my $id = $queries->[$i];

scripts/create_database.pl  view on Meta::CPAN

    }
    $sth = $sths->{week_preferences} || die( "No SQL statement object for week_preferences" );
    # Example: <weekOfPreference ordering="weekOfYear weekOfDate weekOfMonth" locales="fi zh_TW"/>
    while( my $el = $weekPrefsRest->shift )
    {
        my $locales = $el->getAttribute( 'locales' ) ||
            die( "No attribute 'locales' for this element: ", $el->toString() );
        # Example: <weekOfPreference ordering="weekOfYear weekOfDate weekOfMonth" locales="fi zh_TW"/>
        $locales =~ tr/_/-/;
        $locales = [split( /[[:blank:]\h\v]+/, $locales )];
        my $prefs = $el->getAttribute( 'ordering' ) ||
            die( "No attribute 'ordering' for this element: ", $el->toString() );
        $prefs = [split( /[[:blank:]\h\v]+/, $prefs )];
        foreach my $locale ( @$locales )
        {
            # Should not be needed, but better safe than sorry
            if( index( $locale, 'root' ) != -1 )
            {
                if( length( $locale ) > 4 )
                {
                    my $loc = Locale::Unicode->new( $locale );
                    $loc->language( 'und' );
                    $locale = $loc->as_string;
                }
                else
                {
                    $locale = 'und';
                }
            }
    
            $out->print( "[${locale}] " ) if( $DEBUG );
            eval
            {
                $sth->execute( $locale, to_array( $prefs ) );
            } || die( "Error adding week of preference information for locale '${locale}': ", ( $@ || $sth->errstr ) );
            $out->print( "ok\n" ) if( $DEBUG );
            $n++;
        }
    }
    &log( "${n} week of preference information added." );
    
    # NOTE: Loading code mappings
    &log( "Loading code mappings." );
    $n = 0;

scripts/create_database.pl  view on Meta::CPAN

        } || die( "Error adding unit conversion information for source '$def->{source}' and base unit '$def->{base_unit}' in file $units_file: ", ( $@ || $sth->errstr ), "\n", dump( $def ) );
        $n++;
        $j++;
        $out->print( "ok\n" ) if( $DEBUG );
    }
    &log( "${j} unit conversions added." );
    
    # NOTE: Loading unit preferences
    &log( "Loading unit preferences." );
    $j = 0;
    $sth = $sths->{unit_prefs} || die( "No statement object for 'unit_prefs'" );
    while( my $el = $unitsPrefsRes->shift )
    {
        my $cat = $el->getAttribute( 'category' ) ||
            die( "Unable to get the unit preferences category from attribute 'category' for this element in file $units_file: ", $el->toString() );
        my $usage = $el->getAttribute( 'usage' ) ||
            die( "Unable to get the unit preferences usage from attribute 'usage' for this element in file $units_file: ", $el->toString() );
        my $prefsRes = $el->findnodes( './unitPreference' ) ||
            die( "Unable to get unit preferences for the category '${cat}' and usage '${usage}' for this element in file $units_file: ", $el->toString() );
        # Example: <unitPreference regions="001" geq="10" skeleton="precision-increment/10">meter</unitPreference>
        while( my $el_pref = $prefsRes->shift )
        {
            my $def =
            {
                unit_id => ( $el_pref->textContent || die( "No content found for this preference element in file $units_file: ", $el_pref->toString() ) ),
                category => $cat,
                usage => $usage,
            };
            $out->print( "[$def->{unit_id}] " ) if( $DEBUG );
            if( $el_pref->hasAttribute( 'geq' ) )
            {

t/01.locale-data.t  view on Meta::CPAN

can_ok( $cldr, 'unit_aliases' );
can_ok( $cldr, 'unit_constant' );
can_ok( $cldr, 'unit_constants' );
can_ok( $cldr, 'unit_conversion' );
can_ok( $cldr, 'unit_conversions' );
can_ok( $cldr, 'unit_l10n' );
can_ok( $cldr, 'units_l10n' );
can_ok( $cldr, 'unit_prefix' );
can_ok( $cldr, 'unit_prefixes' );
can_ok( $cldr, 'unit_pref' );
can_ok( $cldr, 'unit_prefs' );
can_ok( $cldr, 'unit_quantity' );
can_ok( $cldr, 'unit_quantities' );
can_ok( $cldr, 'variant' );
can_ok( $cldr, 'variants' );
can_ok( $cldr, 'variant_l10n' );
can_ok( $cldr, 'variants_l10n' );
can_ok( $cldr, 'week_preference' );
can_ok( $cldr, 'week_preferences' );

my $db_file = $cldr->datafile;

t/01.locale-data.t  view on Meta::CPAN

        locales_info locales_l10n metainfos metazones
        metazones_names number_formats_l10n number_symbols_l10n
        number_systems number_systems_l10n person_name_defaults
        plural_ranges plural_rules
        rbnf refs scripts scripts_l10n subdivisions
        subdivisions_l10n territories territories_l10n
        time_formats time_relative_l10n timezones timezones_cities
        timezones_cities_extended timezones_cities_supplemental
        timezones_formats timezones_info timezones_names
        unit_aliases unit_constants unit_conversions
        unit_prefixes unit_prefs unit_quantities units_l10n
        variants variants_l10n week_preferences
     )];
    is_deeply( \@tables, $expected, 'tables' );
};
my $vers = $cldr->cldr_version;
is( $vers, $CLDR_VERSION, 'CLDR version' );

my $tests =
{
    # NOTE: aliases

t/01.locale-data.t  view on Meta::CPAN

                power   => 10,
                factor  => -6,
            },
        },
        {
            method      => 'unit_prefixes',
            args        => [],
            expect      => 'array',
        },
    ],
    # NOTE: unit_prefs
    unit_prefs =>
    [
        {
            method      => 'unit_pref',
            args        => [unit_id => 'square-meter'],
            expect      =>
            {
                unit_id         => 'square-meter',
                territory       => '001',
                category        => 'area',
                usage           => 'default',
                geq             => undef,
                skeleton        => undef,
            },
        },
        {
            method      => 'unit_prefs',
            args        => [],
            expect      => 'array',
        },
        {
            method      => 'unit_prefs',
            args        => [territory => 'US'],
            expect      => 'array',
        },
        {
            method      => 'unit_prefs',
            args        => [category => 'area'],
            expect      => 'array',
        },
    ],
    # NOTE: unit_quantities
    unit_quantities =>
    [
        {
            method      => 'unit_quantity',
            args        => [base_unit => 'kilogram'],



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