CLDR::Number - Localized number formatters using the Unicode CLDR
This document describes CLDR::Number v0.08, built with Unicode CLDR v24.
use CLDR::Number; my $cldr = CLDR::Number->new(locale => 'es'); # decimals my $decf = $cldr->decimal_formatter; say $decf->format(1234.5); # '1 234,5' (Spanish) $decf->locale('es-MX'); say $decf->format(1234.5); # '1,234.5' (Mexican Spanish) $decf->locale('ar'); say $decf->format(1234.5); # '١٬٢٣٤٫٥' (Arabic) # percents my $perf = $cldr->percent_formatter(locale => 'tr'); say $perf->format(0.05); # '%5' (Turkish) # currencies my $curf = $cldr->currency_formatter( locale => 'en', currency_code => 'USD', ); say $curf->format(9.99); # '$9.99' (English / USD) $curf->locale('en-CA'); say $curf->format(9.99); # 'US$9.99' (Canadian English / USD) $curf->locale('fr-CA'); say $curf->format(9.99); # '9,99 $US' (Canadian French / USD)
Software localization includes much more than just translations. Numbers, prices, and even percents should all be localized based on the user’s language, script, and region. Fortunately, the Unicode Common Locale Data Repository (CLDR) provides locale data and specifications for formatting numeric data to use with many of the world’s locales.
This class provides common attributes shared among the supported formatter classes as well as methods to instantiate decimal, percent, and currency formatter objects. The value for any attribute (such as locale or decimal_sign) will be passed to the formatter objects on instantiation but can be overwritten by manually passing another value for the attribute or calling a setter method on the formatter object.
Returns a decimal formatter, which is a CLDR::Number::Format::Decimal object instantiated with all of the attributes from your CLDR::Number object as well as any attributes passed to this method.
Returns a percent formatter, which is a CLDR::Number::Format::Percent object instantiated with all of the attributes from your CLDR::Number object as well as any attributes passed to this method.
Returns a currency formatter, which is a CLDR::Number::Format::Currency object instantiated with all of the attributes from your CLDR::Number object as well as any attributes passed to this method.
These are common attributes among this class and all formatter classes. All attributes other than locale, default_locale, and cldr_version have defaults that change depending on the current locale. All string attributes are expected to be character strings, not byte strings.
Default: value of default_locale attribute if it exists, otherwise root
root
Valid: Unicode locale identifiers
Examples: es (Spanish), es-ES (European Spanish), es-419 (Latin American Spanish), zh-Hant (Traditional Chinese), zh-Hans (Simplified Chinese), chr (Cherokee)
es
es-ES
es-419
zh-Hant
zh-Hans
chr
The locale is case-insensitive and can use either - (hyphen-minus) or _ (low line) as a separator.
-
_
Default: none
Use this if you want a locale other than the generic root if the locale attribute is not set or not valid.
Valid: currently only decimal numbering systems are supported
Examples: latn (Western Digits), arab (Arabic-Indic Digits), hanidec (Chinese Decimal Numerals), fullwide (Full Width Digits)
latn
arab
hanidec
fullwide
In the future, algorithmic numbering systems like hant (Traditional Chinese Numerals), hebr (Hebrew Numerals), and roman (Roman Numerals) will be supported.
hant
hebr
roman
The numbering system may alternately be provided as a Unicode locale extension subtag. For example, locale ja-u-nu-fullwide for the Japanese language (ja) with the numbering system (nu) set to Full Width Digits (fullwide).
ja-u-nu-fullwide
ja
nu
Examples: . (full stop) for root, en; , (comma) for de, fr
.
,
Examples: , (comma) for root, en; . (full stop) for de; (no-break space) for fr
Examples: + (plus sign) for root, en, and most locales
+
Examples: - (hyphen-minus) for root, en, and most locales
Value: 24
24
This is a read-only attribute that will always reflect the currently supported Unicode CLDR version.
The Unicode private-use characters U+F8F0 through U+F8F4 are used internally and are therefore not supported in custom patterns and signs.
CLDR::Number::FAQ
CLDR::Number::TODO
UTS #35: Unicode LDML, Part 3: Numbers
CLDR Translation Guidelines: Number Patterns
CLDR Translation Guidelines: Number Symbols
Nick Patch <patch@cpan.org>
This project is brought to you by Perl CLDR and Shutterstock. Additional open source projects from Shutterstock can be found at code.shutterstock.com.
© 2013–2014 Shutterstock, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install CLDR::Number, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CLDR::Number
CPAN shell
perl -MCPAN -e shell install CLDR::Number
For more information on module installation, please visit the detailed CPAN module installation guide.