Perl Localization with the Unicode CLDR

Perl Localization with the Unicode CLDR

Unicode is much more than just characters. The Unicode Consortium defines open standards for collating, parsing, and formatting data in much of the world’s languages. The Common Locale Data Repository (CLDR) is the largest standard repository of locale data along with specifications for its use and is a powerful resource for software localization. Unicode CLDR is quickly becoming the de facto locale standard with widespread use among companies including Google, Apple, and IBM; projects ranging from Linux distributions to Wikipedia; and increasing support in many programming languages.

This talk will provide an introduction to software localization with the CLDR, highlight several CLDR-based CPAN projects, demonstrate how Shutterstock uses and contributes to them, and discuss the remaining work for the Perl community to provide first-class CLDR support.

Presented at:
◦ 2014-05-03: DC–Baltimore Perl Workshop (DCBPW) 2014, Silver Spring, MD
◦  2014-06-23: YAPC::NA 2014, Orlando, FL

Video: https://youtu.be/DcPpUnlENAs
Notes: http://opensourcebridge.org/wiki/2014/Unicode_Beyond_Just_Characters:_Localization_with_the_CLDR

05bab33cfd102c84f045838aa4e05bec?s=128

Nova Patch

June 23, 2014
Tweet

Transcript

  1. Unicode Beyond Just Characters Localization with the CLDR Nick Patch

    @nickpatch Shutterstock
  2. None
  3. ぷ Ꮨ ⇱ K ㋻

  4. Ꙃ २ ௲

  5. ⇱ ⤳ ⪷ ௲ २ ൪ G K ж Ꙃ

    ﲵ Ꮨ 얜 ぷ ㋻ 森
  6. → g ﲵ ← حض ㋻ →ワ

  7. Perl ♥ Unicode

  8. Unicode CLDR

  9. i18n vs. L10n

  10. None
  11. Locales

  12. $locale = Locales->new('fr'); say $locale->get_language_from_code('en'); anglais

  13. $locale = Locales->new('fr'); say $locale->get_territory_from_code('US'); États-Unis

  14. None
  15. None
  16. None
  17. None
  18. CLDR::Number

  19. $cldr = CLDR::Number->new(locale => 'es');

  20. $cldr = CLDR::Number->new(locale => 'es'); $decf = $cldr->decimal_formatter;

  21. $cldr = CLDR::Number->new(locale => 'es'); $decf = $cldr->decimal_formatter; say $decf->format(1234.5);

  22. $cldr = CLDR::Number->new(locale => 'es'); $decf = $cldr->decimal_formatter; say $decf->format(1234.5);

    1 234,5
  23. $decf->locale('es-MX'); say $decf->format(1234.5); 1,234.5

  24. $decf->locale('ar'); say $decf->format(1234.5); ١٬٢٣٤٫٥

  25. $decf->locale('bn'); say $decf->format(123_000); ১,২৩,০০০

  26. $decf->locale('bn'); say $decf->format(12_300_000); ১,২৩,০০,০০০

  27. $perf = $cldr->percent_formatter( locale => 'tr' );

  28. $perf = $cldr->percent_formatter( locale => 'tr' );

  29. $perf = $cldr->percent_formatter( locale => 'tr' ); say $perf->format(0.05);

  30. $perf = $cldr->percent_formatter( locale => 'tr' ); say $perf->format(0.05); %5

  31. $perf->locale('ar'); say $perf->format(0.05); ٥٪

  32. $perf->locale('fr'); say $perf->format(0.05); 5 %

  33. $perf->permil(1); say $perf->format(0.05); 50 ‰

  34. $curf = $cldr->currency_formatter( locale => 'en', currency_code => 'USD', );

  35. $curf = $cldr->currency_formatter( locale => 'en', currency_code => 'USD', );

  36. $curf = $cldr->currency_formatter( locale => 'en', currency_code => 'USD', );

    say $curf->format(9.99);
  37. $curf = $cldr->currency_formatter( locale => 'en', currency_code => 'USD', );

    say $curf->format(9.99); $9.99
  38. $curf->locale('en-CA'); say $curf->format(9.99); US$9.99

  39. $curf->locale('fr-CA'); say $curf->format(9.99); 9,99 $US

  40. $curf->locale('fr-CA'); $curf->currency_code('CAD') say $curf->format(9.99); 9,99 $

  41. $curf->locale('bn'); $curf->currency_code('INR'); say $curf->format(123_000); ১,২৩,০০০.০০₹

  42. $decf->locale('en'); translate( '[_1]–[_2] of [_3]', $decf->format(1), $decf->format(25), $decf->format(1500), );

  43. $decf->locale('en'); translate( '[_1]–[_2] of [_3]', $decf->format(1), $decf->format(25), $decf->format(1500), ); 1–25

    of 1,500
  44. $decf->locale('en'); translate( '[_1] of [_2]', $decf->range(1, 25), $decf->format(1500), ); 1–25

    of 1,500
  45. $decf->locale('ja'); translate( '[_1] of [_2]', $decf->range(1, 25), $decf->format(1500), ); 1

    ~ 25 の 1,500
  46. $decf->locale('ja'); $decf->numbering_system('fullwide'); translate( '[_1] of [_2]', $decf->range(1, 25), $decf->format(1500), );

    1~25の1 , 500
  47. $decf->locale('ja-u-nu-fullwide'); translate( '[_1] of [_2]', $decf->range(1, 25), $decf->format(1500), ); 1~25の1

    , 500
  48. Unicode::Collate::Locale

  49. use Unicode::Collate::Locale;

  50. use Unicode::Collate::Locale; $c = Unicode::Collate::Locale->new( locale => 'pl' );

  51. use Unicode::Collate::Locale; $c = Unicode::Collate::Locale->new( locale => 'pl' ); @sorted

    = $c->sort(@words);
  52. DateTime DateTime::Locale

  53. use DateTime; $dt = DateTime->now(locale => 'ja'); say $dt->format_cldr( $dt->locale->datetime_format_full

    ); 2014 年 6 月 23 日水曜日 9 時 50 分 42 秒 UTC
  54. Locale::CLDR

  55. perl-cldr.github.io @PerlCLDR

  56. TODO DateTime DateTime::Locale CLDR::Transform CLDR::Segment

  57. Nick Patch @nickpatch Shutterstock