twitter_cldr 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (303) hide show
  1. data/NOTICE +95 -1
  2. data/README.md +4 -4
  3. data/Rakefile +18 -28
  4. data/lib/ext/calendars/date.rb +3 -0
  5. data/lib/ext/calendars/datetime.rb +3 -0
  6. data/lib/ext/calendars/time.rb +3 -0
  7. data/lib/ext/localized_object.rb +3 -0
  8. data/lib/ext/numbers/bignum.rb +3 -0
  9. data/lib/ext/numbers/fixnum.rb +3 -0
  10. data/lib/ext/numbers/float.rb +3 -0
  11. data/lib/ext/numbers/localized_number.rb +3 -0
  12. data/lib/ext/strings/string.rb +31 -0
  13. data/lib/ext/strings/symbol.rb +3 -0
  14. data/lib/formatters/base.rb +3 -0
  15. data/lib/formatters/calendars/date_formatter.rb +3 -0
  16. data/lib/formatters/calendars/datetime_formatter.rb +3 -0
  17. data/lib/formatters/calendars/time_formatter.rb +3 -0
  18. data/lib/formatters/numbers/currency_formatter.rb +3 -0
  19. data/lib/formatters/numbers/decimal_formatter.rb +3 -0
  20. data/lib/formatters/numbers/helpers/base.rb +3 -0
  21. data/lib/formatters/numbers/helpers/fraction.rb +3 -0
  22. data/lib/formatters/numbers/helpers/integer.rb +3 -0
  23. data/lib/formatters/numbers/number_formatter.rb +3 -0
  24. data/lib/formatters/numbers/percent_formatter.rb +3 -0
  25. data/lib/formatters/plurals/plural_formatter.rb +141 -0
  26. data/lib/formatters/plurals/rules.rb +4 -1
  27. data/lib/normalizers/base.rb +17 -0
  28. data/lib/normalizers/canonical/nfd.rb +81 -0
  29. data/lib/shared/currencies.rb +4 -1
  30. data/lib/shared/languages.rb +4 -1
  31. data/lib/shared/resources.rb +8 -28
  32. data/lib/shared/timezones.rb +3 -0
  33. data/lib/shared/unicode_data.rb +44 -0
  34. data/lib/tokenizers/base.rb +3 -0
  35. data/lib/tokenizers/calendars/date_tokenizer.rb +3 -0
  36. data/lib/tokenizers/calendars/datetime_tokenizer.rb +4 -1
  37. data/lib/tokenizers/calendars/time_tokenizer.rb +3 -0
  38. data/lib/tokenizers/key_path.rb +3 -0
  39. data/lib/tokenizers/numbers/number_tokenizer.rb +4 -1
  40. data/lib/tokenizers/token.rb +3 -0
  41. data/lib/twitter_cldr.rb +52 -29
  42. data/lib/utils/interpolation.rb +105 -0
  43. data/lib/utils.rb +28 -0
  44. data/lib/version.rb +6 -1
  45. data/resources/unicode_data/aegean_numbers.yml +913 -0
  46. data/resources/unicode_data/alchemical_symbols.yml +1857 -0
  47. data/resources/unicode_data/alphabetic_presentation_forms.yml +929 -0
  48. data/resources/unicode_data/ancient_greek_musical_notation.yml +1121 -0
  49. data/resources/unicode_data/ancient_greek_numbers.yml +1201 -0
  50. data/resources/unicode_data/ancient_symbols.yml +193 -0
  51. data/resources/unicode_data/arabic.yml +4049 -0
  52. data/resources/unicode_data/arabic_extended_a.yml +625 -0
  53. data/resources/unicode_data/arabic_mathematical_alphabetic_symbols.yml +2289 -0
  54. data/resources/unicode_data/arabic_presentation_forms_a.yml +9777 -0
  55. data/resources/unicode_data/arabic_presentation_forms_b.yml +2257 -0
  56. data/resources/unicode_data/arabic_supplement.yml +769 -0
  57. data/resources/unicode_data/armenian.yml +1393 -0
  58. data/resources/unicode_data/arrows.yml +1793 -0
  59. data/resources/unicode_data/avestan.yml +977 -0
  60. data/resources/unicode_data/balinese.yml +1937 -0
  61. data/resources/unicode_data/bamum.yml +1409 -0
  62. data/resources/unicode_data/bamum_supplement.yml +9105 -0
  63. data/resources/unicode_data/basic_latin.yml +2049 -0
  64. data/resources/unicode_data/batak.yml +897 -0
  65. data/resources/unicode_data/bengali.yml +1473 -0
  66. data/resources/unicode_data/block_elements.yml +513 -0
  67. data/resources/unicode_data/blocks.yml +881 -0
  68. data/resources/unicode_data/bopomofo.yml +657 -0
  69. data/resources/unicode_data/bopomofo_extended.yml +433 -0
  70. data/resources/unicode_data/box_drawing.yml +2049 -0
  71. data/resources/unicode_data/brahmi.yml +1729 -0
  72. data/resources/unicode_data/braille_patterns.yml +4097 -0
  73. data/resources/unicode_data/buginese.yml +481 -0
  74. data/resources/unicode_data/buhid.yml +321 -0
  75. data/resources/unicode_data/byzantine_musical_symbols.yml +3937 -0
  76. data/resources/unicode_data/carian.yml +785 -0
  77. data/resources/unicode_data/chakma.yml +1073 -0
  78. data/resources/unicode_data/cham.yml +1329 -0
  79. data/resources/unicode_data/cherokee.yml +1361 -0
  80. data/resources/unicode_data/cjk_compatibility.yml +4097 -0
  81. data/resources/unicode_data/cjk_compatibility_forms.yml +513 -0
  82. data/resources/unicode_data/cjk_compatibility_ideographs.yml +7553 -0
  83. data/resources/unicode_data/cjk_compatibility_ideographs_supplement.yml +8673 -0
  84. data/resources/unicode_data/cjk_radicals_supplement.yml +1841 -0
  85. data/resources/unicode_data/cjk_strokes.yml +577 -0
  86. data/resources/unicode_data/cjk_symbols_and_punctuation.yml +1025 -0
  87. data/resources/unicode_data/cjk_unified_ideographs.yml +33 -0
  88. data/resources/unicode_data/cjk_unified_ideographs_extension_a.yml +33 -0
  89. data/resources/unicode_data/cjk_unified_ideographs_extension_b.yml +33 -0
  90. data/resources/unicode_data/cjk_unified_ideographs_extension_c.yml +33 -0
  91. data/resources/unicode_data/cjk_unified_ideographs_extension_d.yml +33 -0
  92. data/resources/unicode_data/combining_diacritical_marks.yml +1793 -0
  93. data/resources/unicode_data/combining_diacritical_marks_for_symbols.yml +529 -0
  94. data/resources/unicode_data/combining_diacritical_marks_supplement.yml +689 -0
  95. data/resources/unicode_data/combining_half_marks.yml +113 -0
  96. data/resources/unicode_data/common_indic_number_forms.yml +161 -0
  97. data/resources/unicode_data/control_pictures.yml +625 -0
  98. data/resources/unicode_data/coptic.yml +1969 -0
  99. data/resources/unicode_data/counting_rod_numerals.yml +289 -0
  100. data/resources/unicode_data/cuneiform.yml +14065 -0
  101. data/resources/unicode_data/cuneiform_numbers_and_punctuation.yml +1649 -0
  102. data/resources/unicode_data/currency_symbols.yml +417 -0
  103. data/resources/unicode_data/cypriot_syllabary.yml +881 -0
  104. data/resources/unicode_data/cyrillic.yml +4097 -0
  105. data/resources/unicode_data/cyrillic_extended_a.yml +513 -0
  106. data/resources/unicode_data/cyrillic_extended_b.yml +1425 -0
  107. data/resources/unicode_data/cyrillic_supplement.yml +641 -0
  108. data/resources/unicode_data/deseret.yml +1281 -0
  109. data/resources/unicode_data/devanagari.yml +2033 -0
  110. data/resources/unicode_data/devanagari_extended.yml +449 -0
  111. data/resources/unicode_data/dingbats.yml +3057 -0
  112. data/resources/unicode_data/domino_tiles.yml +1601 -0
  113. data/resources/unicode_data/egyptian_hieroglyphs.yml +17137 -0
  114. data/resources/unicode_data/emoticons.yml +1217 -0
  115. data/resources/unicode_data/enclosed_alphanumeric_supplement.yml +2737 -0
  116. data/resources/unicode_data/enclosed_alphanumerics.yml +2561 -0
  117. data/resources/unicode_data/enclosed_cjk_letters_and_months.yml +4065 -0
  118. data/resources/unicode_data/enclosed_ideographic_supplement.yml +913 -0
  119. data/resources/unicode_data/ethiopic.yml +5729 -0
  120. data/resources/unicode_data/ethiopic_extended.yml +1265 -0
  121. data/resources/unicode_data/ethiopic_extended_a.yml +513 -0
  122. data/resources/unicode_data/ethiopic_supplement.yml +417 -0
  123. data/resources/unicode_data/general_punctuation.yml +1713 -0
  124. data/resources/unicode_data/geometric_shapes.yml +1537 -0
  125. data/resources/unicode_data/georgian.yml +1409 -0
  126. data/resources/unicode_data/georgian_supplement.yml +641 -0
  127. data/resources/unicode_data/glagolitic.yml +1505 -0
  128. data/resources/unicode_data/gothic.yml +433 -0
  129. data/resources/unicode_data/greek_and_coptic.yml +2145 -0
  130. data/resources/unicode_data/greek_extended.yml +3729 -0
  131. data/resources/unicode_data/gujarati.yml +1345 -0
  132. data/resources/unicode_data/gurmukhi.yml +1265 -0
  133. data/resources/unicode_data/halfwidth_and_fullwidth_forms.yml +3601 -0
  134. data/resources/unicode_data/hangul_compatibility_jamo.yml +1505 -0
  135. data/resources/unicode_data/hangul_jamo.yml +4097 -0
  136. data/resources/unicode_data/hangul_jamo_extended_a.yml +465 -0
  137. data/resources/unicode_data/hangul_jamo_extended_b.yml +1153 -0
  138. data/resources/unicode_data/hangul_syllables.yml +33 -0
  139. data/resources/unicode_data/hanunoo.yml +369 -0
  140. data/resources/unicode_data/hebrew.yml +1393 -0
  141. data/resources/unicode_data/high_private_use_surrogates.yml +33 -0
  142. data/resources/unicode_data/high_surrogates.yml +33 -0
  143. data/resources/unicode_data/hiragana.yml +1489 -0
  144. data/resources/unicode_data/ideographic_description_characters.yml +193 -0
  145. data/resources/unicode_data/imperial_aramaic.yml +497 -0
  146. data/resources/unicode_data/inscriptional_pahlavi.yml +433 -0
  147. data/resources/unicode_data/inscriptional_parthian.yml +481 -0
  148. data/resources/unicode_data/ipa_extensions.yml +1537 -0
  149. data/resources/unicode_data/javanese.yml +1457 -0
  150. data/resources/unicode_data/kaithi.yml +1057 -0
  151. data/resources/unicode_data/kana_supplement.yml +33 -0
  152. data/resources/unicode_data/kanbun.yml +257 -0
  153. data/resources/unicode_data/kangxi_radicals.yml +3425 -0
  154. data/resources/unicode_data/kannada.yml +1377 -0
  155. data/resources/unicode_data/katakana.yml +1537 -0
  156. data/resources/unicode_data/katakana_phonetic_extensions.yml +257 -0
  157. data/resources/unicode_data/kayah_li.yml +769 -0
  158. data/resources/unicode_data/kharoshthi.yml +1041 -0
  159. data/resources/unicode_data/khmer.yml +1825 -0
  160. data/resources/unicode_data/khmer_symbols.yml +513 -0
  161. data/resources/unicode_data/lao.yml +1073 -0
  162. data/resources/unicode_data/latin_1_supplement.yml +2049 -0
  163. data/resources/unicode_data/latin_extended_a.yml +2049 -0
  164. data/resources/unicode_data/latin_extended_additional.yml +4097 -0
  165. data/resources/unicode_data/latin_extended_b.yml +3329 -0
  166. data/resources/unicode_data/latin_extended_c.yml +513 -0
  167. data/resources/unicode_data/latin_extended_d.yml +2145 -0
  168. data/resources/unicode_data/lepcha.yml +1185 -0
  169. data/resources/unicode_data/letterlike_symbols.yml +1281 -0
  170. data/resources/unicode_data/limbu.yml +1057 -0
  171. data/resources/unicode_data/linear_b_ideograms.yml +1969 -0
  172. data/resources/unicode_data/linear_b_syllabary.yml +1409 -0
  173. data/resources/unicode_data/lisu.yml +769 -0
  174. data/resources/unicode_data/low_surrogates.yml +33 -0
  175. data/resources/unicode_data/lycian.yml +465 -0
  176. data/resources/unicode_data/lydian.yml +433 -0
  177. data/resources/unicode_data/mahjong_tiles.yml +705 -0
  178. data/resources/unicode_data/malayalam.yml +1569 -0
  179. data/resources/unicode_data/mandaic.yml +465 -0
  180. data/resources/unicode_data/mathematical_alphanumeric_symbols.yml +15937 -0
  181. data/resources/unicode_data/mathematical_operators.yml +4097 -0
  182. data/resources/unicode_data/meetei_mayek.yml +897 -0
  183. data/resources/unicode_data/meetei_mayek_extensions.yml +369 -0
  184. data/resources/unicode_data/meroitic_cursive.yml +417 -0
  185. data/resources/unicode_data/meroitic_hieroglyphs.yml +513 -0
  186. data/resources/unicode_data/miao.yml +2129 -0
  187. data/resources/unicode_data/miscellaneous_mathematical_symbols_a.yml +769 -0
  188. data/resources/unicode_data/miscellaneous_mathematical_symbols_b.yml +2049 -0
  189. data/resources/unicode_data/miscellaneous_symbols.yml +4097 -0
  190. data/resources/unicode_data/miscellaneous_symbols_and_arrows.yml +1393 -0
  191. data/resources/unicode_data/miscellaneous_symbols_and_pictographs.yml +8529 -0
  192. data/resources/unicode_data/miscellaneous_technical.yml +3905 -0
  193. data/resources/unicode_data/modifier_tone_letters.yml +513 -0
  194. data/resources/unicode_data/mongolian.yml +2497 -0
  195. data/resources/unicode_data/musical_symbols.yml +3521 -0
  196. data/resources/unicode_data/myanmar.yml +2561 -0
  197. data/resources/unicode_data/myanmar_extended_a.yml +449 -0
  198. data/resources/unicode_data/new_tai_lue.yml +1329 -0
  199. data/resources/unicode_data/nko.yml +945 -0
  200. data/resources/unicode_data/number_forms.yml +929 -0
  201. data/resources/unicode_data/ogham.yml +465 -0
  202. data/resources/unicode_data/ol_chiki.yml +769 -0
  203. data/resources/unicode_data/old_italic.yml +561 -0
  204. data/resources/unicode_data/old_persian.yml +801 -0
  205. data/resources/unicode_data/old_south_arabian.yml +513 -0
  206. data/resources/unicode_data/old_turkic.yml +1169 -0
  207. data/resources/unicode_data/optical_character_recognition.yml +177 -0
  208. data/resources/unicode_data/oriya.yml +1441 -0
  209. data/resources/unicode_data/osmanya.yml +641 -0
  210. data/resources/unicode_data/phags_pa.yml +897 -0
  211. data/resources/unicode_data/phaistos_disc.yml +737 -0
  212. data/resources/unicode_data/phoenician.yml +465 -0
  213. data/resources/unicode_data/phonetic_extensions.yml +2049 -0
  214. data/resources/unicode_data/phonetic_extensions_supplement.yml +1025 -0
  215. data/resources/unicode_data/playing_cards.yml +945 -0
  216. data/resources/unicode_data/private_use_area.yml +33 -0
  217. data/resources/unicode_data/rejang.yml +593 -0
  218. data/resources/unicode_data/rumi_numeral_symbols.yml +497 -0
  219. data/resources/unicode_data/runic.yml +1297 -0
  220. data/resources/unicode_data/samaritan.yml +977 -0
  221. data/resources/unicode_data/saurashtra.yml +1297 -0
  222. data/resources/unicode_data/sharada.yml +1329 -0
  223. data/resources/unicode_data/shavian.yml +769 -0
  224. data/resources/unicode_data/sinhala.yml +1281 -0
  225. data/resources/unicode_data/small_form_variants.yml +417 -0
  226. data/resources/unicode_data/sora_sompeng.yml +561 -0
  227. data/resources/unicode_data/spacing_modifier_letters.yml +1281 -0
  228. data/resources/unicode_data/specials.yml +81 -0
  229. data/resources/unicode_data/sundanese.yml +1025 -0
  230. data/resources/unicode_data/sundanese_supplement.yml +129 -0
  231. data/resources/unicode_data/superscripts_and_subscripts.yml +673 -0
  232. data/resources/unicode_data/supplemental_arrows_a.yml +257 -0
  233. data/resources/unicode_data/supplemental_arrows_b.yml +2049 -0
  234. data/resources/unicode_data/supplemental_mathematical_operators.yml +4097 -0
  235. data/resources/unicode_data/supplemental_punctuation.yml +961 -0
  236. data/resources/unicode_data/supplementary_private_use_area_a.yml +33 -0
  237. data/resources/unicode_data/supplementary_private_use_area_b.yml +33 -0
  238. data/resources/unicode_data/syloti_nagri.yml +705 -0
  239. data/resources/unicode_data/syriac.yml +1233 -0
  240. data/resources/unicode_data/tagalog.yml +321 -0
  241. data/resources/unicode_data/tagbanwa.yml +289 -0
  242. data/resources/unicode_data/tags.yml +1553 -0
  243. data/resources/unicode_data/tai_le.yml +561 -0
  244. data/resources/unicode_data/tai_tham.yml +2033 -0
  245. data/resources/unicode_data/tai_viet.yml +1153 -0
  246. data/resources/unicode_data/tai_xuan_jing_symbols.yml +1393 -0
  247. data/resources/unicode_data/takri.yml +1057 -0
  248. data/resources/unicode_data/tamil.yml +1153 -0
  249. data/resources/unicode_data/telugu.yml +1489 -0
  250. data/resources/unicode_data/thaana.yml +801 -0
  251. data/resources/unicode_data/thai.yml +1393 -0
  252. data/resources/unicode_data/tibetan.yml +3377 -0
  253. data/resources/unicode_data/tifinagh.yml +945 -0
  254. data/resources/unicode_data/transport_and_map_symbols.yml +1121 -0
  255. data/resources/unicode_data/ugaritic.yml +497 -0
  256. data/resources/unicode_data/unified_canadian_aboriginal_syllabics.yml +10241 -0
  257. data/resources/unicode_data/unified_canadian_aboriginal_syllabics_extended.yml +1121 -0
  258. data/resources/unicode_data/vai.yml +4801 -0
  259. data/resources/unicode_data/variation_selectors.yml +257 -0
  260. data/resources/unicode_data/variation_selectors_supplement.yml +3841 -0
  261. data/resources/unicode_data/vedic_extensions.yml +625 -0
  262. data/resources/unicode_data/vertical_forms.yml +161 -0
  263. data/resources/unicode_data/yi_radicals.yml +881 -0
  264. data/resources/unicode_data/yi_syllables.yml +18641 -0
  265. data/resources/unicode_data/yijing_hexagram_symbols.yml +1025 -0
  266. data/spec/ext/calendars/date_spec.rb +5 -1
  267. data/spec/ext/calendars/datetime_spec.rb +5 -1
  268. data/spec/ext/calendars/time_spec.rb +5 -1
  269. data/spec/ext/numbers/bignum_spec.rb +5 -1
  270. data/spec/ext/numbers/fixnum_spec.rb +5 -1
  271. data/spec/ext/numbers/float_spec.rb +5 -1
  272. data/spec/ext/numbers/localized_number_spec.rb +5 -1
  273. data/spec/ext/strings/string_spec.rb +102 -0
  274. data/spec/ext/strings/symbol_spec.rb +5 -1
  275. data/spec/formatters/base_spec.rb +5 -1
  276. data/spec/formatters/calendars/datetime_formatter_spec.rb +5 -1
  277. data/spec/formatters/numbers/currency_formatter_spec.rb +5 -1
  278. data/spec/formatters/numbers/decimal_formatter_spec.rb +5 -1
  279. data/spec/formatters/numbers/helpers/fraction_spec.rb +5 -1
  280. data/spec/formatters/numbers/helpers/integer_spec.rb +5 -1
  281. data/spec/formatters/numbers/number_formatter_spec.rb +6 -2
  282. data/spec/formatters/numbers/percent_formatter_spec.rb +5 -1
  283. data/spec/formatters/plurals/plural_formatter_spec.rb +205 -0
  284. data/spec/formatters/plurals/rules_spec.rb +28 -28
  285. data/spec/normalizers/NormalizationTest.txt +602 -0
  286. data/spec/normalizers/base_spec.rb +16 -0
  287. data/spec/normalizers/canonical/nfd_spec.rb +50 -0
  288. data/spec/shared/currencies_spec.rb +5 -1
  289. data/spec/shared/languages_spec.rb +5 -1
  290. data/spec/shared/resources_spec.rb +5 -18
  291. data/spec/shared/unicode_data_spec.rb +51 -0
  292. data/spec/spec_helper.rb +6 -3
  293. data/spec/tokenizers/base_spec.rb +3 -0
  294. data/spec/tokenizers/calendars/date_tokenizer_spec.rb +5 -1
  295. data/spec/tokenizers/calendars/datetime_tokenizer_spec.rb +5 -1
  296. data/spec/tokenizers/calendars/time_tokenizer_spec.rb +5 -1
  297. data/spec/tokenizers/key_path_spec.rb +3 -0
  298. data/spec/tokenizers/numbers/number_tokenizer_spec.rb +5 -1
  299. data/spec/tokenizers/token_spec.rb +5 -1
  300. data/spec/twitter_cldr_spec.rb +23 -1
  301. data/spec/utils/interpolation_spec.rb +124 -0
  302. data/spec/utils_spec.rb +32 -0
  303. metadata +285 -21
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr
5
9
 
6
10
  describe Date do
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr
5
9
 
6
10
  describe DateTime do
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr
5
9
 
6
10
  describe Time do
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr
5
9
 
6
10
  describe Bignum do
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr
5
9
 
6
10
  describe Fixnum do
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr
5
9
 
6
10
  describe Float do
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr
5
9
 
6
10
  describe LocalizedNumber do
@@ -0,0 +1,102 @@
1
+ # encoding: UTF-8
2
+
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
8
+ include TwitterCldr
9
+
10
+ describe String do
11
+
12
+ describe '#localize' do
13
+ it 'returns localized string object' do
14
+ 'foo'.localize.should be_a(LocalizedString)
15
+ end
16
+
17
+ it "uses default locale if it's not explicitly specified" do
18
+ mock(TwitterCldr).get_locale { :jp }
19
+ 'foo'.localize.locale.should == :jp
20
+ end
21
+
22
+ it 'uses provided locale if there is one' do
23
+ 'foo'.localize(:ru).locale.should == :ru
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ describe LocalizedString do
30
+ describe '#%' do
31
+ context 'when argument is not a Hash' do
32
+ it 'performs regular formatting of values' do
33
+ ('%d is an integer'.localize % 3.14).should == '3 is an integer'
34
+ end
35
+
36
+ it 'performs regular formatting of arrays' do
37
+ ('"% 04d" is a %s'.localize % [12, 'number']).should == '" 012" is a number'
38
+ end
39
+
40
+ it 'ignores pluralization placeholders' do
41
+ ('%s: %{horses_count:horses}'.localize % 'total').should == 'total: %{horses_count:horses}'
42
+ end
43
+
44
+ it 'raises ArgumentError when the string contains named placeholder' do
45
+ lambda { '%{msg}: %{horses_count:horses}'.localize % 'total' }.should raise_error(ArgumentError)
46
+ end
47
+ end
48
+
49
+ context 'when argument is a Hash' do
50
+ let(:horses) { { :one => '1 horse', :other => '%{horses_count} horses' } }
51
+
52
+ before(:each) do
53
+ stub(Formatters::Plurals::Rules).rule_for { |n, _| n == 1 ? :one : :other }
54
+ end
55
+
56
+ it 'interpolates named placeholders' do
57
+ ('%<num>.2f is a %{noun}'.localize % { :num => 3.1415, :noun => 'number' }).should == '3.14 is a number'
58
+ end
59
+
60
+ it 'performs regular pluralization' do
61
+ ('%{horses_count:horses}'.localize % { :horses_count => 2, :horses => horses }).should == '2 horses'
62
+ end
63
+
64
+ it 'performs inline pluralization' do
65
+ string = '%<{ "horses_count": { "other": "%{horses_count} horses" } }>'.localize
66
+ (string % { :horses_count => 2 }).should == '2 horses'
67
+ end
68
+
69
+ it 'performs both formatting and regular pluralization simultaneously' do
70
+ string = '%{msg}: %{horses_count:horses}'.localize
71
+ (string % { :horses_count => 2, :horses => horses, :msg => 'result' }).should == 'result: 2 horses'
72
+ end
73
+
74
+ it 'performs both formatting and inline pluralization simultaneously' do
75
+ string = '%{msg}: %<{"horses_count": {"other": "%{horses_count} horses"}}>'.localize
76
+ (string % { :horses_count => 2, :msg => 'result' }).should == 'result: 2 horses'
77
+ end
78
+
79
+ it 'performs both formatted interpolation and inline pluralization simultaneously' do
80
+ string = '%<number>d, %<{"horses_count": {"other": "%{horses_count} horses" }}>'.localize
81
+ (string % { :number => 3.14, :horses_count => 2 }).should == '3, 2 horses'
82
+ end
83
+
84
+ it 'leaves regular pluralization placeholders unchanged if not enough information given' do
85
+ string = '%{msg}: %{horses_count:horses}'.localize
86
+ (string % { :msg => 'no pluralization' } ).should == 'no pluralization: %{horses_count:horses}'
87
+ end
88
+
89
+ it 'leaves inline pluralization placeholders unchanged if not enough information given' do
90
+ string = '%<number>d, %<{"horses_count": {"one": "one horse"}}>'.localize
91
+ (string % { :number => 3.14, :horses_count => 2 }).should == '3, %<{"horses_count": {"one": "one horse"}}>'
92
+ end
93
+
94
+ it 'raises KeyError when value for a named placeholder is missing' do
95
+ lambda do
96
+ '%{msg}: %{horses_count:horses}'.localize % { :horses_count => 2, :horses => horses }
97
+ end.should raise_error(KeyError)
98
+ end
99
+ end
100
+ end
101
+
102
+ end
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr
5
9
 
6
10
  describe LocalizedSymbol do
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(__FILE__), %w[.. spec_helper])
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr::Formatters
5
9
 
6
10
  describe Base do
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr::Formatters
5
9
 
6
10
  describe DateTimeFormatter do
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr::Formatters
5
9
 
6
10
  describe CurrencyFormatter do
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr::Formatters
5
9
 
6
10
  describe DecimalFormatter do
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr::Formatters::Numbers
5
9
  include TwitterCldr::Tokenizers
6
10
 
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr::Formatters::Numbers
5
9
  include TwitterCldr::Tokenizers
6
10
 
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr::Formatters
5
9
 
6
10
  describe NumberFormatter do
@@ -78,4 +82,4 @@ describe NumberFormatter do
78
82
  @formatter.format(1337.37).should == "1 337,37"
79
83
  end
80
84
  end
81
- end
85
+ end
@@ -1,6 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr::Formatters
5
9
 
6
10
  describe PercentFormatter do
@@ -0,0 +1,205 @@
1
+ # encoding: UTF-8
2
+
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
8
+ include TwitterCldr::Formatters
9
+
10
+ describe PluralFormatter do
11
+
12
+ describe '#initialize' do
13
+ it 'fetches locale from options hash' do
14
+ PluralFormatter.new(:locale => :ru).locale.should == :ru
15
+ end
16
+
17
+ it "uses default locale if it's not passed in options hash" do
18
+ PluralFormatter.new.locale.should == TwitterCldr::DEFAULT_LOCALE
19
+ end
20
+ end
21
+
22
+ describe '#format' do
23
+ subject { PluralFormatter.new }
24
+
25
+ before(:each) do
26
+ stub(subject).pluralization_rule { |n| n == 1 ? :one : :other }
27
+ end
28
+
29
+ let(:horses) { { :one => 'is 1 horse', :other => 'are %{horses_count} horses' } }
30
+ let(:horses_string) { '%<{ "horses_count": {"one": "is 1 horse", "other": "are %{horses_count} horses"} }>' }
31
+
32
+ let(:simple_horses) { { :one => '1 horse', :other => '%{horses_count} horses' } }
33
+ let(:simple_horses_string) { '%<{ "horses_count": {"one": "1 horse", "other": "%{horses_count} horses"} }>' }
34
+
35
+ let(:to_be) { { :one => 'is', :other => 'are' } }
36
+ let(:yaks) { { :one => 'is 1 yak', :other => 'are %{yaks_count} yaks' } }
37
+
38
+ context 'when there is nothing to pluralize' do
39
+ it "doesn't change the string if no interpolation found" do
40
+ string = 'no interpolation here'
41
+ subject.format(string, {}).should == string
42
+ end
43
+
44
+ context 'with regular pluralization' do
45
+ it "doesn't change the string if a number is not provided" do
46
+ string = 'there %{horses_count:horses}'
47
+ subject.format(string, :horses => horses).should == string
48
+ end
49
+
50
+ it "doesn't change the string if a patterns hash is not provided" do
51
+ string = 'there %{horses_count:horses}'
52
+ subject.format(string, :horses_count => 1).should == string
53
+ end
54
+
55
+ it "doesn't change the string if required pattern is not provided" do
56
+ string = 'there %{horses_count:horses}'
57
+ subject.format(string, :horses_count => 2, :horses => { :one => 'is 1 horse' }).should == string
58
+ end
59
+ end
60
+
61
+ context 'with inline pluralization' do
62
+ it "doesn't change the string if a number is not provided" do
63
+ string = "there #{horses_string}"
64
+ subject.format(string, {}).should == string
65
+ end
66
+
67
+ it "doesn't change the string if required pattern is not provided" do
68
+ string = 'there %<{ "horses_count": {"one": "is 1 horse"} }>'
69
+ subject.format(string, :horses_count => 2).should == string
70
+ end
71
+ end
72
+
73
+ context 'with mixed pluralization' do
74
+ it "doesn't change the string if a number is not provided" do
75
+ string = "there #{horses_string} %{horses_count:horses}"
76
+ subject.format(string, :horses => horses).should == string
77
+ end
78
+
79
+ it "doesn't change the string if required pattern is not provided" do
80
+ string = 'there %<{ "horses_count": {"one": "is 1 horse"} }> %{horses_count:horses}'
81
+ subject.format(string, :horses_count => 2, :horses => { :one => 'is 1 horse' }).should == string
82
+ end
83
+ end
84
+ end
85
+
86
+ context 'when something should be pluralized' do
87
+ context 'with regular pluralization' do
88
+ it 'pluralizes with a simple replacement' do
89
+ subject.format(
90
+ 'there %{horses_count:horses}',
91
+ :horses_count => 1, :horses => horses
92
+ ).should == 'there is 1 horse'
93
+ end
94
+
95
+ it 'pluralizes when there are named interpolation patterns in the string' do
96
+ subject.format(
97
+ '%{there} %{horses_count:horses}',
98
+ :horses_count => 1, :horses => horses
99
+ ).should == '%{there} is 1 horse'
100
+ end
101
+
102
+ it 'supports multiple patterns sets for the same number' do
103
+ subject.format(
104
+ 'there %{horses_count:to_be} %{horses_count:horses}',
105
+ :horses_count => 1, :horses => simple_horses, :to_be => to_be
106
+ ).should == 'there is 1 horse'
107
+ end
108
+
109
+ it 'pluralizes multiple entries' do
110
+ subject.format(
111
+ 'there %{yaks_count:yaks} and %{horses_count:horses}',
112
+ :yaks_count => 1, :yaks => yaks, :horses_count => 2, :horses => simple_horses
113
+ ).should == 'there is 1 yak and 2 horses'
114
+ end
115
+
116
+ it 'substitutes the number for a placeholder in the pattern' do
117
+ subject.format(
118
+ 'there %{horses_count:horses}',
119
+ :horses_count => 3, :horses => horses
120
+ ).should == 'there are 3 horses'
121
+ end
122
+
123
+ it 'substitutes the number for multiple placeholders in the pattern' do
124
+ subject.format(
125
+ 'there are %{horses_count:horses}',
126
+ :horses_count => 3, :horses => { :other => '%{horses_count}, seriously %{horses_count}, horses' }
127
+ ).should == 'there are 3, seriously 3, horses'
128
+ end
129
+
130
+ it 'throws an exception if pluralization patterns is not a hash' do
131
+ lambda do
132
+ subject.format('there %{horses_count:horses}', :horses_count => 1, :horses => [])
133
+ end.should raise_error(ArgumentError, 'expected patterns to be a Hash')
134
+ end
135
+ end
136
+
137
+ context 'with inline pluralization' do
138
+ it 'pluralizes with a simple replacement' do
139
+ subject.format("there #{horses_string}", :horses_count => 1).should == 'there is 1 horse'
140
+ end
141
+
142
+ it 'pluralizes when there are named interpolation patterns in the string' do
143
+ subject.format("%{there} #{horses_string}", :horses_count => 1).should == '%{there} is 1 horse'
144
+ end
145
+
146
+ it 'supports multiple patterns sets for the same number' do
147
+ subject.format(
148
+ %Q(there %<{ "horses_count": {"one": "is", "other": "are"} }> #{simple_horses_string}), :horses_count => 1
149
+ ).should == 'there is 1 horse'
150
+ end
151
+
152
+ it 'pluralizes multiple entries' do
153
+ subject.format(
154
+ %Q(there %<{ "yaks_count": {"one": "is 1 yak", "other": "are %{yaks_count} yaks"} }> and #{simple_horses_string}),
155
+ :yaks_count => 1, :horses_count => 2
156
+ ).should == 'there is 1 yak and 2 horses'
157
+ end
158
+
159
+ it 'substitutes the number for a placeholder in the pattern' do
160
+ subject.format(
161
+ "there #{horses_string}", :horses_count => 3, :horses => horses
162
+ ).should == 'there are 3 horses'
163
+ end
164
+
165
+ it 'substitutes the number for multiple placeholders in the pattern' do
166
+ subject.format(
167
+ 'there are %<{ "horses_count": {"other": "%{horses_count}, seriously %{horses_count}, horses"} }>',
168
+ :horses_count => 3
169
+ ).should == 'there are 3, seriously 3, horses'
170
+ end
171
+
172
+ it 'throws an exception if pluralization hash has more than one key' do
173
+ lambda do
174
+ subject.format('there are %<{ "horses_count": {}, "foo": {} }>', {})
175
+ end.should raise_error(ArgumentError, 'expected a Hash with a single key')
176
+ end
177
+ end
178
+
179
+ context 'with mixed pluralization' do
180
+ it 'pluralizes separate groups' do
181
+ subject.format(
182
+ "there %{yaks_count:yaks} and #{simple_horses_string}",
183
+ :yaks => yaks, :yaks_count => 3, :horses_count => 2
184
+ ).should == 'there are 3 yaks and 2 horses'
185
+ end
186
+
187
+ it 'pluralizes similar groups' do
188
+ subject.format(
189
+ "there %{horses_count:horses} + #{simple_horses_string}",
190
+ :horses => horses, :horses_count => 2
191
+ ).should == 'there are 2 horses + 2 horses'
192
+ end
193
+ end
194
+ end
195
+
196
+ end
197
+
198
+ describe '#pluralization_rule' do
199
+ it 'delegates pluralization rule fetching to Rules.rule_for method' do
200
+ mock(Plurals::Rules).rule_for(42, :jp) { 'result' }
201
+ PluralFormatter.new(:locale => :jp).send(:pluralization_rule, 42).should == 'result'
202
+ end
203
+ end
204
+
205
+ end
@@ -1,20 +1,28 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
4
8
  include TwitterCldr::Formatters::Plurals
5
9
 
6
10
  describe Rules do
7
11
  describe "#get_resource" do
8
12
  it "calls eval on the hash that gets returned, lambdas and all" do
9
13
  result = Rules.send(:get_resource, :ru)
10
- result.should include(:ru)
11
- result[:ru].should include(:i18n)
12
- result[:ru][:i18n].should include(:plural)
13
- result[:ru][:i18n][:plural].should include(:keys)
14
- result[:ru][:i18n][:plural][:keys].size.should == 4
15
14
 
16
- result[:ru][:i18n][:plural].should include(:rule)
17
- result[:ru][:i18n][:plural][:rule].should be_a(Proc)
15
+ [:ru, :i18n, :plural].inject(result) do |current, key|
16
+ current.should have_key(key)
17
+ current[key]
18
+ end
19
+
20
+ plural = result[:ru][:i18n][:plural]
21
+
22
+ plural.should include(:keys, :rule)
23
+
24
+ plural[:keys].size.should == 4
25
+ plural[:rule].should be_a(Proc)
18
26
  end
19
27
  end
20
28
 
@@ -27,21 +35,15 @@ describe Rules do
27
35
  end
28
36
 
29
37
  it "returns the correct values for Russian rules" do
30
- Rules.rule_for(1, :ru).should == :one
31
- Rules.rule_for(2, :ru).should == :few
32
- Rules.rule_for(3, :ru).should == :few
33
- Rules.rule_for(4, :ru).should == :few
34
- Rules.rule_for(5, :ru).should == :many
35
- Rules.rule_for(6, :ru).should == :many
36
- Rules.rule_for(7, :ru).should == :many
37
- Rules.rule_for(8, :ru).should == :many
38
- Rules.rule_for(9, :ru).should == :many
39
- Rules.rule_for(10, :ru).should == :many
40
- Rules.rule_for(11, :ru).should == :many
38
+ rules = {
39
+ :one => [1, 101],
40
+ :few => [2, 3, 4, 102],
41
+ :many => ((5..11).to_a + [111])
42
+ }
41
43
 
42
- Rules.rule_for(101, :ru).should == :one
43
- Rules.rule_for(102, :ru).should == :few
44
- Rules.rule_for(111, :ru).should == :many
44
+ rules.each do |rule, examples|
45
+ examples.each { |n| Rules.rule_for(n, :ru).should == rule }
46
+ end
45
47
  end
46
48
 
47
49
  it "returns :other if there's an error" do
@@ -53,11 +55,11 @@ describe Rules do
53
55
 
54
56
  describe "#all_for" do
55
57
  it "returns a list of all applicable rules for the given locale" do
56
- Rules.all_for(:en).each { |rule| [:one, :other].should include(rule) }
57
- Rules.all_for(:ru).each { |rule| [:one, :few, :many, :other].should include(rule) }
58
+ Rules.all_for(:en).should =~ [:one, :other]
59
+ Rules.all_for(:ru).should =~ [:one, :few, :many, :other]
58
60
  end
59
61
 
60
- it "should return an empty array on error" do
62
+ it "returns an empty array on error" do
61
63
  stub(Rules).get_resource { lambda { raise "Jelly beans" } }
62
64
  Rules.all_for(:en).should == []
63
65
  Rules.all_for(:ru).should == []
@@ -67,9 +69,7 @@ describe Rules do
67
69
  describe "#all" do
68
70
  it "gets rules for the default locale (usually supplied by FastGettext)" do
69
71
  mock(TwitterCldr).get_locale { :ru }
70
- rules = Rules.all
71
- rules.size.should == 4
72
- rules.each { |rule| [:one, :few, :many, :other].should include(rule) }
72
+ Rules.all.should =~ [:one, :few, :many, :other]
73
73
  end
74
74
  end
75
75
  end