Perl 5 version 30.0 documentation

Unicode::Collate::Locale

NAME

Unicode::Collate::Locale - Linguistic tailoring for DUCET via Unicode::Collate

SYNOPSIS

  1. use Unicode::Collate::Locale;
  2. #construct
  3. $Collator = Unicode::Collate::Locale->
  4. new(locale => $locale_name, %tailoring);
  5. #sort
  6. @sorted = $Collator->sort(@not_sorted);
  7. #compare
  8. $result = $Collator->cmp($a, $b); # returns 1, 0, or -1.

Note: Strings in @not_sorted , $a and $b are interpreted according to Perl's Unicode support. See perlunicode, perluniintro, perlunitut, perlunifaq, utf8. Otherwise you can use preprocess (cf. Unicode::Collate ) or should decode them before.

DESCRIPTION

This module provides linguistic tailoring for it taking advantage of Unicode::Collate .

Constructor

The new method returns a collator object.

A parameter list for the constructor is a hash, which can include a special key locale and its value (case-insensitive) standing for a Unicode base language code (two or three-letter). For example, Unicode::Collate::Locale->new(locale => 'ES') returns a collator tailored for Spanish.

$locale_name may be suffixed with a Unicode script code (four-letter), a Unicode region (territory) code, a Unicode language variant code. These codes are case-insensitive, and separated with '_' or '-' . E.g. en_US for English in USA, az_Cyrl for Azerbaijani in the Cyrillic script, es_ES_traditional for Spanish in Spain (Traditional).

If $locale_name is not available, fallback is selected in the following order:

  1. 1. language with a variant code
  2. 2. language with a script code
  3. 3. language with a region code
  4. 4. language
  5. 5. default

Tailoring tags provided by Unicode::Collate are allowed as long as they are not used for locale support. Esp. the table tag is always untailorable, since it is reserved for DUCET.

However entry is allowed, even if it is used for locale support, to add or override mappings.

E.g. a collator for Spanish, which ignores diacritics and case difference (i.e. level 1), with reversed case ordering and no normalization.

  1. Unicode::Collate::Locale->new(
  2. level => 1,
  3. locale => 'es',
  4. upper_before_lower => 1,
  5. normalization => undef
  6. )

Overriding a behavior already tailored by locale is disallowed if such a tailoring is passed to new() .

  1. Unicode::Collate::Locale->new(
  2. locale => 'da',
  3. upper_before_lower => 0, # causes error as reserved by 'da'
  4. )

However change() inherited from Unicode::Collate allows such a tailoring that is reserved by locale . Examples:

  1. new(locale => 'fr_ca')->change(backwards => undef)
  2. new(locale => 'da')->change(upper_before_lower => 0)
  3. new(locale => 'ja')->change(overrideCJK => undef)

Methods

Unicode::Collate::Locale is a subclass of Unicode::Collate and methods other than new are inherited from Unicode::Collate .

Here is a list of additional methods:

  • $Collator->getlocale

    Returns a language code accepted and used actually on collation. If linguistic tailoring is not provided for a language code you passed (intensionally for some languages, or due to the incomplete implementation), this method returns a string 'default' meaning no special tailoring.

  • $Collator->locale_version

    (Since Unicode::Collate::Locale 0.87) Returns the version number (perhaps /\d\.\d\d/ ) of the locale, as that of Locale/*.pl.

    Note: Locale/*.pl that a collator uses should be identified by a combination of return values from getlocale and locale_version .

A list of tailorable locales

  1. locale name description
  2. --------------------------------------------------------------
  3. af Afrikaans
  4. ar Arabic
  5. as Assamese
  6. az Azerbaijani (Azeri)
  7. be Belarusian
  8. bn Bengali
  9. bs Bosnian (tailored as Croatian)
  10. bs_Cyrl Bosnian in Cyrillic (tailored as Serbian)
  11. ca Catalan
  12. cs Czech
  13. cu Church Slavic
  14. cy Welsh
  15. da Danish
  16. de__phonebook German (umlaut as 'ae', 'oe', 'ue')
  17. de_AT_phonebook Austrian German (umlaut primary greater)
  18. dsb Lower Sorbian
  19. ee Ewe
  20. eo Esperanto
  21. es Spanish
  22. es__traditional Spanish ('ch' and 'll' as a grapheme)
  23. et Estonian
  24. fa Persian
  25. fi Finnish (v and w are primary equal)
  26. fi__phonebook Finnish (v and w as separate characters)
  27. fil Filipino
  28. fo Faroese
  29. fr_CA Canadian French
  30. gu Gujarati
  31. ha Hausa
  32. haw Hawaiian
  33. he Hebrew
  34. hi Hindi
  35. hr Croatian
  36. hu Hungarian
  37. hy Armenian
  38. ig Igbo
  39. is Icelandic
  40. ja Japanese [1]
  41. kk Kazakh
  42. kl Kalaallisut
  43. kn Kannada
  44. ko Korean [2]
  45. kok Konkani
  46. lkt Lakota
  47. ln Lingala
  48. lt Lithuanian
  49. lv Latvian
  50. mk Macedonian
  51. ml Malayalam
  52. mr Marathi
  53. mt Maltese
  54. nb Norwegian Bokmal
  55. nn Norwegian Nynorsk
  56. nso Northern Sotho
  57. om Oromo
  58. or Oriya
  59. pa Punjabi
  60. pl Polish
  61. ro Romanian
  62. sa Sanskrit
  63. se Northern Sami
  64. si Sinhala
  65. si__dictionary Sinhala (U+0DA5 = U+0DA2,0DCA,0DA4)
  66. sk Slovak
  67. sl Slovenian
  68. sq Albanian
  69. sr Serbian
  70. sr_Latn Serbian in Latin (tailored as Croatian)
  71. sv Swedish (v and w are primary equal)
  72. sv__reformed Swedish (v and w as separate characters)
  73. ta Tamil
  74. te Telugu
  75. th Thai
  76. tn Tswana
  77. to Tonga
  78. tr Turkish
  79. ug_Cyrl Uyghur in Cyrillic
  80. uk Ukrainian
  81. ur Urdu
  82. vi Vietnamese
  83. vo Volapu"k
  84. wae Walser
  85. wo Wolof
  86. yo Yoruba
  87. zh Chinese
  88. zh__big5han Chinese (ideographs: big5 order)
  89. zh__gb2312han Chinese (ideographs: GB-2312 order)
  90. zh__pinyin Chinese (ideographs: pinyin order) [3]
  91. zh__stroke Chinese (ideographs: stroke order) [3]
  92. zh__zhuyin Chinese (ideographs: zhuyin order) [3]
  93. --------------------------------------------------------------

Locales according to the default UCA rules include am (Amharic) without [reorder Ethi] , bg (Bulgarian) without [reorder Cyrl] , chr (Cherokee) without [reorder Cher] , de (German), en (English), fr (French), ga (Irish), id (Indonesian), it (Italian), ka (Georgian) without [reorder Geor] , mn (Mongolian) without [reorder Cyrl Mong] , ms (Malay), nl (Dutch), pt (Portuguese), ru (Russian) without [reorder Cyrl] , sw (Swahili), zu (Zulu).

Note

[1] ja: Ideographs are sorted in JIS X 0208 order. Fullwidth and halfwidth forms are identical to their regular form. The difference between hiragana and katakana is at the 4th level, the comparison also requires (variable => 'Non-ignorable') , and then katakana_before_hiragana has no effect.

[2] ko: Plenty of ideographs are sorted by their reading. Such an ideograph is primary (level 1) equal to, and secondary (level 2) greater than, the corresponding hangul syllable.

[3] zh__pinyin, zh__stroke and zh__zhuyin: implemented alt='short', where a smaller number of ideographs are tailored.

A list of variant codes and their aliases

  1. variant code alias
  2. ------------------------------------------
  3. dictionary dict
  4. phonebook phone phonebk
  5. reformed reform
  6. traditional trad
  7. ------------------------------------------
  8. big5han big5
  9. gb2312han gb2312
  10. pinyin
  11. stroke
  12. zhuyin
  13. ------------------------------------------

Note: 'pinyin' is Han in Latin, 'zhuyin' is Han in Bopomofo.

INSTALL

Installation of Unicode::Collate::Locale requires Collate/Locale.pm, Collate/Locale/*.pm, Collate/CJK/*.pm and Collate/allkeys.txt. On building, Unicode::Collate::Locale doesn't require any of data/*.txt, gendata/*, and mklocale. Tests for Unicode::Collate::Locale are named t/loc_*.t.

CAVEAT

  • Tailoring is not maximum

    Even if a certain letter is tailored, its equivalent would not always tailored as well as it. For example, even though W is tailored, fullwidth W (U+FF37 ), W with acute (U+1E82 ), etc. are not tailored. The result may depend on whether source strings are normalized or not, and whether decomposed or composed. Thus (normalization => undef) is less preferred.

  • Collation reordering is not supported

    The order of any groups including scripts is not changed.

Reference

  1. locale based CLDR or other reference
  2. --------------------------------------------------------------------
  3. af 30 = 1.8.1
  4. ar 30 = 28 ("compat" wo [reorder Arab]) = 1.9.0
  5. as 30 = 28 (without [reorder Beng..]) = 23
  6. az 30 = 24 ("standard" wo [reorder Latn Cyrl])
  7. be 30 = 28 (without [reorder Cyrl])
  8. bn 30 = 28 ("standard" wo [reorder Beng..]) = 2.0.1
  9. bs 30 = 28 (type="standard": [import hr])
  10. bs_Cyrl 30 = 28 (type="standard": [import sr])
  11. ca 30 = 23 (alt="proposed" type="standard")
  12. cs 30 = 1.8.1 (type="standard")
  13. cu 34 = 30 (without [reorder Cyrl])
  14. cy 30 = 1.8.1
  15. da 22.1 = 1.8.1 (type="standard")
  16. de__phonebook 30 = 2.0 (type="phonebook")
  17. de_AT_phonebook 30 = 27 (type="phonebook")
  18. dsb 30 = 26
  19. ee 30 = 21
  20. eo 30 = 1.8.1
  21. es 30 = 1.9.0 (type="standard")
  22. es__traditional 30 = 1.8.1 (type="traditional")
  23. et 30 = 26
  24. fa 22.1 = 1.8.1
  25. fi 22.1 = 1.8.1 (type="standard" alt="proposed")
  26. fi__phonebook 22.1 = 1.8.1 (type="phonebook")
  27. fil 30 = 1.9.0 (type="standard") = 1.8.1
  28. fo 22.1 = 1.8.1 (alt="proposed" type="standard")
  29. fr_CA 30 = 1.9.0
  30. gu 30 = 28 ("standard" wo [reorder Gujr..]) = 1.9.0
  31. ha 30 = 1.9.0
  32. haw 30 = 24
  33. he 30 = 28 (without [reorder Hebr]) = 23
  34. hi 30 = 28 (without [reorder Deva..]) = 1.9.0
  35. hr 30 = 28 ("standard" wo [reorder Latn Cyrl]) = 1.9.0
  36. hu 22.1 = 1.8.1 (alt="proposed" type="standard")
  37. hy 30 = 28 (without [reorder Armn]) = 1.8.1
  38. ig 30 = 1.8.1
  39. is 22.1 = 1.8.1 (type="standard")
  40. ja 22.1 = 1.8.1 (type="standard")
  41. kk 30 = 28 (without [reorder Cyrl])
  42. kl 22.1 = 1.8.1 (type="standard")
  43. kn 30 = 28 ("standard" wo [reorder Knda..]) = 1.9.0
  44. ko 22.1 = 1.8.1 (type="standard")
  45. kok 30 = 28 (without [reorder Deva..]) = 1.8.1
  46. lkt 30 = 25
  47. ln 30 = 2.0 (type="standard") = 1.8.1
  48. lt 22.1 = 1.9.0
  49. lv 22.1 = 1.9.0 (type="standard") = 1.8.1
  50. mk 30 = 28 (without [reorder Cyrl])
  51. ml 22.1 = 1.9.0
  52. mr 30 = 28 (without [reorder Deva..]) = 1.8.1
  53. mt 22.1 = 1.9.0
  54. nb 22.1 = 2.0 (type="standard")
  55. nn 22.1 = 2.0 (type="standard")
  56. nso [*] 26 = 1.8.1
  57. om 22.1 = 1.8.1
  58. or 30 = 28 (without [reorder Orya..]) = 1.9.0
  59. pa 22.1 = 1.8.1
  60. pl 30 = 1.8.1
  61. ro 30 = 1.9.0 (type="standard")
  62. sa [*] 1.9.1 = 1.8.1 (type="standard" alt="proposed")
  63. se 22.1 = 1.8.1 (type="standard")
  64. si 30 = 28 ("standard" wo [reorder Sinh..]) = 1.9.0
  65. si__dictionary 30 = 28 ("dictionary" wo [reorder Sinh..]) = 1.9.0
  66. sk 22.1 = 1.9.0 (type="standard")
  67. sl 22.1 = 1.8.1 (type="standard" alt="proposed")
  68. sq 22.1 = 1.8.1 (alt="proposed" type="standard")
  69. sr 30 = 28 (without [reorder Cyrl])
  70. sr_Latn 30 = 28 (type="standard": [import hr])
  71. sv 22.1 = 1.9.0 (type="standard")
  72. sv__reformed 22.1 = 1.8.1 (type="reformed")
  73. ta 22.1 = 1.9.0
  74. te 30 = 28 (without [reorder Telu..]) = 1.9.0
  75. th 22.1 = 22
  76. tn [*] 26 = 1.8.1
  77. to 22.1 = 22
  78. tr 22.1 = 1.8.1 (type="standard")
  79. uk 30 = 28 (without [reorder Cyrl])
  80. ug_Cyrl https://en.wikipedia.org/wiki/Uyghur_Cyrillic_alphabet
  81. ur 22.1 = 1.9.0
  82. vi 22.1 = 1.8.1
  83. vo 30 = 25
  84. wae 30 = 2.0
  85. wo [*] 1.9.1 = 1.8.1
  86. yo 30 = 1.8.1
  87. zh 22.1 = 1.8.1 (type="standard")
  88. zh__big5han 22.1 = 1.8.1 (type="big5han")
  89. zh__gb2312han 22.1 = 1.8.1 (type="gb2312han")
  90. zh__pinyin 22.1 = 2.0 (type='pinyin' alt='short')
  91. zh__stroke 22.1 = 1.9.1 (type='stroke' alt='short')
  92. zh__zhuyin 22.1 = 22 (type='zhuyin' alt='short')
  93. --------------------------------------------------------------------

[*] http://www.unicode.org/repos/cldr/tags/latest/seed/collation/

AUTHOR

The Unicode::Collate::Locale module for perl was written by SADAHIRO Tomoyuki, <SADAHIRO@cpan.org>. This module is Copyright(C) 2004-2018, SADAHIRO Tomoyuki. Japan. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO