twitter_cldr 3.3.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +3 -1
  3. data/README.md +44 -10
  4. data/lib/twitter_cldr/data_readers/timespan_data_reader.rb +6 -4
  5. data/lib/twitter_cldr/localized/localized_number.rb +5 -1
  6. data/lib/twitter_cldr/localized/localized_object.rb +1 -7
  7. data/lib/twitter_cldr/localized/localized_string.rb +1 -1
  8. data/lib/twitter_cldr/shared.rb +1 -0
  9. data/lib/twitter_cldr/shared/unit.rb +126 -0
  10. data/lib/twitter_cldr/version.rb +1 -1
  11. data/resources/custom/locales/af/fields.yml +19 -0
  12. data/resources/custom/locales/ar/fields.yml +35 -0
  13. data/resources/custom/locales/be/fields.yml +27 -0
  14. data/resources/custom/locales/bg/fields.yml +19 -0
  15. data/resources/custom/locales/bn/fields.yml +15 -0
  16. data/resources/custom/locales/ca/fields.yml +19 -0
  17. data/resources/custom/locales/cs/fields.yml +23 -0
  18. data/resources/custom/locales/cy/fields.yml +35 -0
  19. data/resources/custom/locales/da/fields.yml +19 -0
  20. data/resources/custom/locales/de/fields.yml +19 -0
  21. data/resources/custom/locales/el/fields.yml +19 -0
  22. data/resources/custom/locales/en-GB/fields.yml +19 -0
  23. data/resources/custom/locales/en/fields.yml +19 -0
  24. data/resources/custom/locales/es/fields.yml +19 -0
  25. data/resources/custom/locales/eu/fields.yml +19 -0
  26. data/resources/custom/locales/fa/fields.yml +15 -0
  27. data/resources/custom/locales/fi/fields.yml +19 -0
  28. data/resources/custom/locales/fil/fields.yml +19 -0
  29. data/resources/custom/locales/fr/fields.yml +19 -0
  30. data/resources/custom/locales/ga/fields.yml +24 -0
  31. data/resources/custom/locales/gl/fields.yml +19 -0
  32. data/resources/custom/locales/he/fields.yml +164 -0
  33. data/resources/custom/locales/hi/fields.yml +19 -0
  34. data/resources/custom/locales/hr/fields.yml +9 -0
  35. data/resources/custom/locales/hu/fields.yml +19 -0
  36. data/resources/custom/locales/id/{units.yml → fields.yml} +5 -5
  37. data/resources/custom/locales/it/fields.yml +19 -0
  38. data/resources/custom/locales/ja/{units.yml → fields.yml} +5 -5
  39. data/resources/custom/locales/ko/{units.yml → fields.yml} +5 -5
  40. data/resources/custom/locales/lv/fields.yml +23 -0
  41. data/resources/custom/locales/ms/{units.yml → fields.yml} +5 -5
  42. data/resources/custom/locales/nb/fields.yml +19 -0
  43. data/resources/custom/locales/nl/fields.yml +19 -0
  44. data/resources/custom/locales/pl/fields.yml +27 -0
  45. data/resources/custom/locales/pt/fields.yml +19 -0
  46. data/resources/custom/locales/ro/fields.yml +23 -0
  47. data/resources/custom/locales/ru/fields.yml +27 -0
  48. data/resources/custom/locales/sk/fields.yml +23 -0
  49. data/resources/custom/locales/sr/fields.yml +27 -0
  50. data/resources/custom/locales/sv/{units.yml → fields.yml} +9 -9
  51. data/resources/custom/locales/ta/fields.yml +11 -0
  52. data/resources/custom/locales/th/fields.yml +15 -0
  53. data/resources/custom/locales/tr/{units.yml → fields.yml} +5 -5
  54. data/resources/custom/locales/uk/fields.yml +27 -0
  55. data/resources/custom/locales/ur/fields.yml +19 -0
  56. data/resources/custom/locales/vi/{units.yml → fields.yml} +5 -5
  57. data/resources/custom/locales/zh-Hant/{units.yml → fields.yml} +5 -5
  58. data/resources/custom/locales/zh/{units.yml → fields.yml} +5 -5
  59. data/resources/locales/af/fields.yml +108 -0
  60. data/resources/locales/af/units.yml +855 -104
  61. data/resources/locales/ar/fields.yml +220 -0
  62. data/resources/locales/ar/units.yml +1975 -216
  63. data/resources/locales/be/fields.yml +122 -0
  64. data/resources/locales/be/units.yml +284 -118
  65. data/resources/locales/bg/fields.yml +108 -0
  66. data/resources/locales/bg/units.yml +855 -104
  67. data/resources/locales/bn/fields.yml +108 -0
  68. data/resources/locales/bn/units.yml +855 -104
  69. data/resources/locales/ca/fields.yml +108 -0
  70. data/resources/locales/ca/units.yml +879 -104
  71. data/resources/locales/cs/fields.yml +136 -0
  72. data/resources/locales/cs/units.yml +1822 -132
  73. data/resources/locales/cy/fields.yml +108 -0
  74. data/resources/locales/cy/units.yml +1193 -104
  75. data/resources/locales/da/fields.yml +108 -0
  76. data/resources/locales/da/units.yml +883 -104
  77. data/resources/locales/de-CH/fields.yml +108 -0
  78. data/resources/locales/de-CH/units.yml +1096 -104
  79. data/resources/locales/de/fields.yml +108 -0
  80. data/resources/locales/de/units.yml +1096 -104
  81. data/resources/locales/el/fields.yml +108 -0
  82. data/resources/locales/el/units.yml +855 -104
  83. data/resources/locales/en-150/fields.yml +108 -0
  84. data/resources/locales/en-150/units.yml +1090 -104
  85. data/resources/locales/en-AU/fields.yml +108 -0
  86. data/resources/locales/en-AU/units.yml +1090 -104
  87. data/resources/locales/en-CA/fields.yml +108 -0
  88. data/resources/locales/en-CA/units.yml +1090 -104
  89. data/resources/locales/en-GB/fields.yml +108 -0
  90. data/resources/locales/en-GB/units.yml +1090 -104
  91. data/resources/locales/en-IE/fields.yml +108 -0
  92. data/resources/locales/en-IE/units.yml +1090 -104
  93. data/resources/locales/en-SG/fields.yml +108 -0
  94. data/resources/locales/en-SG/units.yml +1090 -104
  95. data/resources/locales/en-ZA/fields.yml +108 -0
  96. data/resources/locales/en-ZA/units.yml +1090 -104
  97. data/resources/locales/en/fields.yml +108 -0
  98. data/resources/locales/en/units.yml +1090 -104
  99. data/resources/locales/es-419/fields.yml +108 -0
  100. data/resources/locales/es-419/units.yml +855 -104
  101. data/resources/locales/es-CO/fields.yml +108 -0
  102. data/resources/locales/es-CO/units.yml +855 -104
  103. data/resources/locales/es-MX/fields.yml +108 -0
  104. data/resources/locales/es-MX/units.yml +855 -104
  105. data/resources/locales/es-US/fields.yml +108 -0
  106. data/resources/locales/es-US/units.yml +855 -104
  107. data/resources/locales/es/fields.yml +108 -0
  108. data/resources/locales/es/units.yml +855 -104
  109. data/resources/locales/eu/fields.yml +108 -0
  110. data/resources/locales/eu/units.yml +855 -104
  111. data/resources/locales/fa/fields.yml +108 -0
  112. data/resources/locales/fa/units.yml +865 -104
  113. data/resources/locales/fi/fields.yml +108 -0
  114. data/resources/locales/fi/units.yml +1096 -104
  115. data/resources/locales/fil/fields.yml +108 -0
  116. data/resources/locales/fil/units.yml +855 -104
  117. data/resources/locales/fr-BE/fields.yml +108 -0
  118. data/resources/locales/fr-BE/units.yml +944 -104
  119. data/resources/locales/fr-CA/fields.yml +108 -0
  120. data/resources/locales/fr-CA/units.yml +944 -104
  121. data/resources/locales/fr-CH/fields.yml +108 -0
  122. data/resources/locales/fr-CH/units.yml +944 -104
  123. data/resources/locales/fr/fields.yml +108 -0
  124. data/resources/locales/fr/units.yml +944 -104
  125. data/resources/locales/ga/fields.yml +108 -0
  126. data/resources/locales/ga/units.yml +2013 -104
  127. data/resources/locales/gl/fields.yml +108 -0
  128. data/resources/locales/gl/units.yml +774 -104
  129. data/resources/locales/gu/fields.yml +108 -0
  130. data/resources/locales/gu/units.yml +855 -104
  131. data/resources/locales/he/fields.yml +164 -0
  132. data/resources/locales/he/units.yml +1420 -160
  133. data/resources/locales/hi/fields.yml +108 -0
  134. data/resources/locales/hi/units.yml +855 -104
  135. data/resources/locales/hr/fields.yml +164 -0
  136. data/resources/locales/hr/units.yml +1459 -160
  137. data/resources/locales/hu/fields.yml +108 -0
  138. data/resources/locales/hu/units.yml +855 -104
  139. data/resources/locales/id/fields.yml +108 -0
  140. data/resources/locales/id/units.yml +575 -104
  141. data/resources/locales/is/fields.yml +108 -0
  142. data/resources/locales/is/units.yml +854 -104
  143. data/resources/locales/it-CH/fields.yml +108 -0
  144. data/resources/locales/it-CH/units.yml +855 -104
  145. data/resources/locales/it/fields.yml +108 -0
  146. data/resources/locales/it/units.yml +855 -104
  147. data/resources/locales/ja/fields.yml +108 -0
  148. data/resources/locales/ja/units.yml +733 -104
  149. data/resources/locales/kn/fields.yml +108 -0
  150. data/resources/locales/kn/units.yml +855 -104
  151. data/resources/locales/ko/fields.yml +108 -0
  152. data/resources/locales/ko/units.yml +575 -104
  153. data/resources/locales/lv/fields.yml +136 -0
  154. data/resources/locales/lv/units.yml +1135 -132
  155. data/resources/locales/mr/fields.yml +108 -0
  156. data/resources/locales/mr/units.yml +855 -104
  157. data/resources/locales/ms/fields.yml +108 -0
  158. data/resources/locales/ms/units.yml +575 -104
  159. data/resources/locales/nb/fields.yml +108 -0
  160. data/resources/locales/nb/units.yml +886 -104
  161. data/resources/locales/nl/fields.yml +108 -0
  162. data/resources/locales/nl/units.yml +1096 -104
  163. data/resources/locales/pl/fields.yml +164 -0
  164. data/resources/locales/pl/units.yml +1415 -160
  165. data/resources/locales/pt/fields.yml +108 -0
  166. data/resources/locales/pt/units.yml +855 -104
  167. data/resources/locales/ro/fields.yml +136 -0
  168. data/resources/locales/ro/units.yml +1135 -132
  169. data/resources/locales/ru/fields.yml +164 -0
  170. data/resources/locales/ru/units.yml +1415 -160
  171. data/resources/locales/sk/fields.yml +136 -0
  172. data/resources/locales/sk/units.yml +1635 -132
  173. data/resources/locales/sq/fields.yml +108 -0
  174. data/resources/locales/sq/units.yml +870 -104
  175. data/resources/locales/sr/fields.yml +164 -0
  176. data/resources/locales/sr/units.yml +1135 -160
  177. data/resources/locales/sv/fields.yml +108 -0
  178. data/resources/locales/sv/units.yml +1081 -104
  179. data/resources/locales/ta/fields.yml +108 -0
  180. data/resources/locales/ta/units.yml +855 -104
  181. data/resources/locales/th/fields.yml +108 -0
  182. data/resources/locales/th/units.yml +575 -104
  183. data/resources/locales/tr/fields.yml +108 -0
  184. data/resources/locales/tr/units.yml +1096 -104
  185. data/resources/locales/uk/fields.yml +164 -0
  186. data/resources/locales/uk/units.yml +1425 -160
  187. data/resources/locales/ur/fields.yml +108 -0
  188. data/resources/locales/ur/units.yml +855 -104
  189. data/resources/locales/vi/fields.yml +108 -0
  190. data/resources/locales/vi/units.yml +575 -104
  191. data/resources/locales/zh-Hant/fields.yml +108 -0
  192. data/resources/locales/zh-Hant/units.yml +733 -104
  193. data/resources/locales/zh/fields.yml +108 -0
  194. data/resources/locales/zh/units.yml +575 -104
  195. data/spec/resources/loader_spec.rb +4 -4
  196. data/spec/shared/unit_spec.rb +283 -0
  197. data/twitter_cldr.gemspec +1 -1
  198. metadata +124 -54
  199. data/resources/custom/locales/af/units.yml +0 -19
  200. data/resources/custom/locales/ar/units.yml +0 -35
  201. data/resources/custom/locales/be/units.yml +0 -27
  202. data/resources/custom/locales/bg/units.yml +0 -19
  203. data/resources/custom/locales/bn/units.yml +0 -15
  204. data/resources/custom/locales/ca/units.yml +0 -19
  205. data/resources/custom/locales/cs/units.yml +0 -23
  206. data/resources/custom/locales/cy/units.yml +0 -35
  207. data/resources/custom/locales/da/units.yml +0 -19
  208. data/resources/custom/locales/de/units.yml +0 -19
  209. data/resources/custom/locales/el/units.yml +0 -19
  210. data/resources/custom/locales/en-GB/units.yml +0 -19
  211. data/resources/custom/locales/en/units.yml +0 -19
  212. data/resources/custom/locales/es/units.yml +0 -19
  213. data/resources/custom/locales/eu/units.yml +0 -19
  214. data/resources/custom/locales/fa/units.yml +0 -15
  215. data/resources/custom/locales/fi/units.yml +0 -19
  216. data/resources/custom/locales/fil/units.yml +0 -19
  217. data/resources/custom/locales/fr/units.yml +0 -19
  218. data/resources/custom/locales/ga/units.yml +0 -24
  219. data/resources/custom/locales/gl/units.yml +0 -19
  220. data/resources/custom/locales/he/units.yml +0 -164
  221. data/resources/custom/locales/hi/units.yml +0 -19
  222. data/resources/custom/locales/hr/units.yml +0 -9
  223. data/resources/custom/locales/hu/units.yml +0 -19
  224. data/resources/custom/locales/it/units.yml +0 -19
  225. data/resources/custom/locales/lv/units.yml +0 -23
  226. data/resources/custom/locales/nb/units.yml +0 -19
  227. data/resources/custom/locales/nl/units.yml +0 -19
  228. data/resources/custom/locales/pl/units.yml +0 -27
  229. data/resources/custom/locales/pt/units.yml +0 -19
  230. data/resources/custom/locales/ro/units.yml +0 -23
  231. data/resources/custom/locales/ru/units.yml +0 -27
  232. data/resources/custom/locales/sk/units.yml +0 -23
  233. data/resources/custom/locales/sr/units.yml +0 -27
  234. data/resources/custom/locales/ta/units.yml +0 -11
  235. data/resources/custom/locales/th/units.yml +0 -15
  236. data/resources/custom/locales/uk/units.yml +0 -27
  237. data/resources/custom/locales/ur/units.yml +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d3c83418de63bc5d460bb981ad0d1564a09de4f
4
- data.tar.gz: 376f8ac7e27080e7cc1b604ef01e2f870bf9546d
3
+ metadata.gz: 24c9124b0a865bb5129c1ee452c64523388c511c
4
+ data.tar.gz: b4dcd2273f4220961ef9cb0f08e028003e3d859a
5
5
  SHA512:
6
- metadata.gz: 625ac607af99d9ea241ffbcb406a6d024595ebe7255bb340a38a573e50ddd11afc577954e400427bf588b73fca3c0b75ea7c3848ee4c90f86fd2c7106bd617b1
7
- data.tar.gz: 9746a38d2c5f56ec515e63ca88a75e0f72754d6b5553d05429bb93a8ef89d5f69ab742b1d8b269bcd4a41215fa6d87a068541c8852230ee9a0361b4af9b068e4
6
+ metadata.gz: 4c0cb24e46abd72a293cba324d00e03b973cdf00f40ba3f11fccd44fe71e378ab9d5a06a03acb4f6a71aeb3f60f1e91a1da714caae2e52afafeeebd97f6c6cbf
7
+ data.tar.gz: c7f81da3faeb01ab877a54fe66e7bcb68117dc015d321d84592dd79303f1407386cc3a413095f53d8ed3bf72821168ce52e74b17600489525e500cbe6ac23206
data/History.txt CHANGED
@@ -1,5 +1,7 @@
1
- == 3.3.0
1
+ == 3.4.0
2
+ * Add units support, eg. "12 degrees Celsius", etc.
2
3
 
4
+ == 3.3.0
3
5
  * Added `#as_territory` convenience method to LocalizedSymbol (@Anthony-Gaudino).
4
6
  * Improved documentation for world territories (@Anthony-Gaudino).
5
7
  * Fixed issues with Unicode regular expressions
data/README.md CHANGED
@@ -86,6 +86,31 @@ In addition to formatting regular decimals, TwitterCLDR supports short and long
86
86
  1337123.localize.to_long_decimal.to_s # "1 million"
87
87
  ```
88
88
 
89
+ ### Units
90
+
91
+ TwitterCLDR supports formatting numbers with an attached unit, for example "12 degrees Celsius". It's easy to make use of this functionality via the `#to_unit` method:
92
+
93
+ ```ruby
94
+ 12.localize.to_unit.length_mile # "12 miles"
95
+ 12.localize(:ru).to_unit.length_mile # "12 миль"
96
+ ```
97
+ Units support a few different forms, long, short, and narrow:
98
+
99
+ ```ruby
100
+ 12.localize.to_unit.mass_kilogram(form: :short) # "12 kg"
101
+ ```
102
+
103
+ To get a list of all available unit types, use the `#unit_types` method:
104
+
105
+ ```ruby
106
+ unit = 12.localize.to_unit
107
+ unit.unit_types # => [:length_mile, :temperature_celsius, :mass_kilogram, ...]
108
+ ```
109
+
110
+
111
+
112
+
113
+
89
114
  ### Number Spellout, Ordinalization, and More
90
115
 
91
116
  TwitterCLDR's rule-based number formatters are capable of transforming integers into their written equivalents. Note that rule-based formatting of decimal numbers is currently not supported for languages other than English.
@@ -290,6 +315,15 @@ TwitterCldr::Localized::LocalizedTimespan.new(45).to_s(:approximate => true) #
290
315
  TwitterCldr::Localized::LocalizedTimespan.new(52).to_s(:approximate => true) # "In 1 minute"
291
316
  ```
292
317
 
318
+ ### Calendar Data
319
+
320
+ CLDR contains a trove of calendar data, much of which can be accessed. One example is names of months, days, years.
321
+
322
+ ```ruby
323
+ TwitterCldr::Shared::Calendar.new(:sv).months.take(3) # ["Januari", "Februari", "Mars"]
324
+ ```
325
+
326
+
293
327
  ### Lists
294
328
 
295
329
  TwitterCLDR supports formatting lists of strings as you might do in English by using commas, eg: "Apples, cherries, and oranges". Use the `localize` method on an array followed by a call to `to_sentence`:
@@ -450,10 +484,10 @@ In addition to translating territory codes, TwitterCLDR provides access to the f
450
484
 
451
485
  ```ruby
452
486
  # get all territories for the default locale
453
- TwitterCldr::Shared::Territories.all # { ... :tl=>"East Timor", :tm=>"Turkmenistan" ... }
487
+ TwitterCldr::Shared::Territories.all # { ... :tl => "East Timor", :tm => "Turkmenistan" ... }
454
488
 
455
489
  # get all territories for a specific locale
456
- TwitterCldr::Shared::Territories.all_for(:pt) # { ... :tl=>"República Democrática de Timor-Leste", :tm=>"Turcomenistão" ... }
490
+ TwitterCldr::Shared::Territories.all_for(:pt) # { ... :tl => "República Democrática de Timor-Leste", :tm => "Turcomenistão" ... }
457
491
 
458
492
  # get a territory by its code for the default locale
459
493
  TwitterCldr::Shared::Territories.from_territory_code(:'gb') # "U.K."
@@ -514,7 +548,7 @@ postal_code.regexp # /(\d{5})(?:[ \-](\d{4}))?/
514
548
  Get a sample of valid postal codes with the `#sample` method:
515
549
 
516
550
  ```ruby
517
- postal_code.sample(5) # ["79220", "97037-1396", "41756", "07232-5538", "99181-2266"]
551
+ postal_code.sample(5) # ["04937-1403", "24033-3284", "40707-3618", "56564", "53993"]
518
552
  ```
519
553
 
520
554
  ### Phone Codes
@@ -668,7 +702,7 @@ You can break a string into sentences using the `LocalizedString#each_sentence`
668
702
 
669
703
  ```ruby
670
704
  "The. Quick. Brown. Fox.".localize.each_sentence do |sentence|
671
- puts sentence.to_s # "The.", " Quick.", " Brown.", " Fox."
705
+ puts sentence.to_s # "The. ", "Quick. ", "Brown. ", "Fox."
672
706
  end
673
707
  ```
674
708
 
@@ -676,9 +710,9 @@ Under the hood, text segmentation is performed by the `BreakIterator` class (nam
676
710
 
677
711
  ```ruby
678
712
 
679
- iterator = TwitterCldr::Shared::BreakIterator.new(:en)
713
+ iterator = TwitterCldr::Segmentation::BreakIterator.new(:en)
680
714
  iterator.each_sentence("The. Quick. Brown. Fox.") do |sentence|
681
- puts sentence # "The.", " Quick.", " Brown.", " Fox."
715
+ puts sentence # "The. ", "Quick. ", "Brown. ", "Fox."
682
716
  end
683
717
  ```
684
718
 
@@ -686,9 +720,9 @@ To improve segmentation accuracy, a list of special segmentation exceptions have
686
720
 
687
721
  ```ruby
688
722
 
689
- iterator = TwitterCldr::Shared::BreakIterator.new(:en, :use_uli_exceptions => false)
723
+ iterator = TwitterCldr::Segmentation::BreakIterator.new(:en, :use_uli_exceptions => false)
690
724
  iterator.each_sentence("I like Ms. Murphy, she's nice.") do |sentence|
691
- puts sentence # "I like Ms.", " Murphy, she's nice."
725
+ puts sentence # "I like Ms. ", "Murphy, she's nice."
692
726
  end
693
727
  ```
694
728
 
@@ -700,7 +734,7 @@ Retrieve data for code points:
700
734
 
701
735
  ```ruby
702
736
 
703
- code_point = TwitterCldr::Shared::CodePoint.find(0x1F3E9)
737
+ code_point = TwitterCldr::Shared::CodePoint.get(0x1F3E9)
704
738
  code_point.name # "LOVE HOTEL"
705
739
  code_point.bidi_mirrored # "N"
706
740
  code_point.category # "So"
@@ -901,6 +935,6 @@ TwitterCLDR currently supports localization of certain textual objects in JavaSc
901
935
 
902
936
  ## License
903
937
 
904
- Copyright 2015 Twitter, Inc.
938
+ Copyright 2016 Twitter, Inc.
905
939
 
906
940
  Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
@@ -9,8 +9,8 @@ module TwitterCldr
9
9
 
10
10
  DEFAULT_DIRECTION = :none
11
11
  DEFAULT_TYPE = :default
12
- VALID_UNITS = [:second, :minute, :hour, :day, :week, :month, :year]
13
- BASE_PATH = [:units]
12
+ VALID_FIELDS = [:second, :minute, :hour, :day, :week, :month, :year]
13
+ BASE_PATH = [:fields]
14
14
 
15
15
  PATHS = {
16
16
  ago: {
@@ -23,6 +23,7 @@ module TwitterCldr
23
23
  month: :'month-past',
24
24
  year: :'year-past'
25
25
  },
26
+
26
27
  until: {
27
28
  default: :'hour-future',
28
29
  second: :'second-future',
@@ -33,6 +34,7 @@ module TwitterCldr
33
34
  month: :'month-future',
34
35
  year: :'year-future'
35
36
  },
37
+
36
38
  none: {
37
39
  default: :second,
38
40
  second: :second,
@@ -113,9 +115,9 @@ module TwitterCldr
113
115
 
114
116
  def resource_for_locale(locale)
115
117
  @resources ||= {}
116
- @resources[locale] ||= TwitterCldr.get_locale_resource(locale, :units)[TwitterCldr.convert_locale(locale)]
118
+ @resources[locale] ||= TwitterCldr.get_locale_resource(locale, :fields)[TwitterCldr.convert_locale(locale)]
117
119
  end
118
120
  end
119
121
  end
120
122
  end
121
- end
123
+ end
@@ -55,7 +55,11 @@ module TwitterCldr
55
55
  @rbnf ||= TwitterCldr::Formatters::Rbnf::RbnfFormatter.new(locale)
56
56
  end
57
57
 
58
- protected
58
+ def to_unit
59
+ TwitterCldr::Shared::Unit.create(base_obj, locale)
60
+ end
61
+
62
+ private
59
63
 
60
64
  def to_type(target_type)
61
65
  self.class.new(base_obj, locale, {
@@ -17,14 +17,8 @@ module TwitterCldr
17
17
 
18
18
  options = options.dup
19
19
  options[:locale] = @locale
20
-
21
- # @formatter = formatter_const.new(options) if formatter_const
22
20
  end
23
21
 
24
- # def formatter_const
25
- # raise NotImplementedError
26
- # end
27
-
28
22
  def self.localize(klass)
29
23
  klass.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
30
24
  def localize(locale = TwitterCldr.locale, options = {})
@@ -35,4 +29,4 @@ module TwitterCldr
35
29
  end
36
30
 
37
31
  end
38
- end
32
+ end
@@ -151,7 +151,7 @@ module TwitterCldr
151
151
  protected
152
152
 
153
153
  def escape_plural_interpolation(string)
154
- # escape plura interpolation patterns ()see PluralFormatter)
154
+ # escape plural interpolation patterns (see PluralFormatter)
155
155
  string.gsub(TwitterCldr::Formatters::PluralFormatter::PLURALIZATION_REGEXP, '%\0')
156
156
  end
157
157
 
@@ -30,5 +30,6 @@ module TwitterCldr
30
30
  autoload :TerritoriesContainment, 'twitter_cldr/shared/territories_containment'
31
31
  autoload :Territory, 'twitter_cldr/shared/territory'
32
32
  autoload :UnicodeRegex, 'twitter_cldr/shared/unicode_regex'
33
+ autoload :Unit, 'twitter_cldr/shared/unit'
33
34
  end
34
35
  end
@@ -0,0 +1,126 @@
1
+ # encoding: UTF-8
2
+
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'set'
7
+
8
+ module TwitterCldr
9
+ module Shared
10
+ class Unit
11
+ class << self
12
+ def create(value, locale = TwitterCldr.locale)
13
+ subtype_for(locale).new(value, locale)
14
+ end
15
+
16
+ private
17
+
18
+ def reader_for(locale)
19
+ readers[locale] ||= TwitterCldr::DataReaders::NumberDataReader.new(locale)
20
+ end
21
+
22
+ def resource_for(locale)
23
+ TwitterCldr.get_locale_resource(locale, :units)[locale][:units]
24
+ end
25
+
26
+ def subtype_for(locale)
27
+ subtypes[locale] ||= begin
28
+ klass = Class.new(Unit)
29
+
30
+ all_unit_types_for(locale).each do |unit_type|
31
+ method_name = unit_type_to_method_name(unit_type)
32
+ klass.send(:define_method, method_name) do |*args|
33
+ format(unit_type, *args)
34
+ end
35
+ end
36
+
37
+ klass
38
+ end
39
+ end
40
+
41
+ def all_unit_types_for(locale)
42
+ unit_types[locale] ||= begin
43
+ resource = resource_for(locale)
44
+ lengths = resource[:unitLength].keys
45
+
46
+ lengths.each_with_object(Set.new) do |length, ret|
47
+ ret.merge(resource[:unitLength][length].keys)
48
+ end
49
+ end
50
+ end
51
+
52
+ def all_unit_methods_for(locale)
53
+ unit_methods[locale] ||= all_unit_types_for(locale).map do |unit_type|
54
+ unit_type_to_method_name(unit_type).to_sym
55
+ end
56
+ end
57
+
58
+ def unit_type_to_method_name(unit_type)
59
+ unit_type.to_s.gsub('-', '_')
60
+ end
61
+
62
+ def subtypes
63
+ @subtypes ||= {}
64
+ end
65
+
66
+ def unit_types
67
+ @unit_types ||= {}
68
+ end
69
+
70
+ def unit_methods
71
+ @unit_methods ||= {}
72
+ end
73
+
74
+ def readers
75
+ @readers ||= {}
76
+ end
77
+ end
78
+
79
+ DEFAULT_FORM = :long
80
+
81
+ attr_reader :value, :locale
82
+
83
+ def initialize(value, locale = TwitterCldr.locale)
84
+ @value = value
85
+ @locale = locale
86
+ end
87
+
88
+ def unit_types
89
+ self.class.send(:all_unit_methods_for, locale)
90
+ end
91
+
92
+ private
93
+
94
+ def format(unit_type, options = {})
95
+ form = options.fetch(:form, DEFAULT_FORM)
96
+
97
+ if variant = variant_for(form, unit_type)
98
+ variant.sub('{0}', formatted_value)
99
+ end
100
+ end
101
+
102
+ def formatted_value
103
+ if value.is_a?(Numeric)
104
+ self.class.send(:reader_for, locale).format_number(value)
105
+ else
106
+ value
107
+ end
108
+ end
109
+
110
+ def variant_for(form, unit_type)
111
+ variant = resource[:unitLength]
112
+ .fetch(form, {})
113
+ .fetch(unit_type, {})
114
+ .fetch(plural_rule.to_sym, nil)
115
+ end
116
+
117
+ def plural_rule
118
+ TwitterCldr::Formatters::Plurals::Rules.rule_for(value, locale)
119
+ end
120
+
121
+ def resource
122
+ @resource ||= self.class.send(:resource_for, locale)
123
+ end
124
+ end
125
+ end
126
+ end
@@ -4,5 +4,5 @@
4
4
  # http://www.apache.org/licenses/LICENSE-2.0
5
5
 
6
6
  module TwitterCldr
7
- VERSION = "3.3.0"
7
+ VERSION = '3.4.0'
8
8
  end
@@ -0,0 +1,19 @@
1
+ ---
2
+ :af:
3
+ :fields:
4
+ :day:
5
+ :abbreviated:
6
+ :one: "{0}d"
7
+ :other: "{0}d"
8
+ :hour:
9
+ :abbreviated:
10
+ :one: "{0}h"
11
+ :other: "{0}h"
12
+ :minute:
13
+ :abbreviated:
14
+ :one: "{0}m"
15
+ :other: "{0}m"
16
+ :second:
17
+ :abbreviated:
18
+ :one: "{0}s"
19
+ :other: "{0}s"
@@ -0,0 +1,35 @@
1
+ ---
2
+ :ar:
3
+ :fields:
4
+ :day:
5
+ :abbreviated:
6
+ :zero: "{0}يومًا"
7
+ :one: "{0}يومًا"
8
+ :two: "{0}يومًا"
9
+ :few: "{0}يومًا"
10
+ :many: "{0}يومًا"
11
+ :other: "{0}يومًا"
12
+ :hour:
13
+ :abbreviated:
14
+ :zero: "{0} ساعة"
15
+ :one: "{0} ساعة"
16
+ :two: "{0} ساعة"
17
+ :few: "{0} ساعة"
18
+ :many: "{0} ساعة"
19
+ :other: "{0} ساعة"
20
+ :minute:
21
+ :abbreviated:
22
+ :zero: "{0} دقيقة"
23
+ :one: "{0} دقيقة"
24
+ :two: "{0} دقيقة"
25
+ :few: "{0} دقيقة"
26
+ :many: "{0} دقيقة"
27
+ :other: "{0} دقيقة"
28
+ :second:
29
+ :abbreviated:
30
+ :zero: "{0} ثانية"
31
+ :one: "{0} ثانية"
32
+ :two: "{0} ثانية"
33
+ :few: "{0} ثانية"
34
+ :many: "{0} ثانية"
35
+ :other: "{0} ثانية"
@@ -0,0 +1,27 @@
1
+ ---
2
+ :be:
3
+ :fields:
4
+ :day:
5
+ :abbreviated:
6
+ :one: "{0} дн"
7
+ :few: "{0} дн"
8
+ :many: "{0} дн"
9
+ :other: "{0} дн"
10
+ :hour:
11
+ :abbreviated:
12
+ :one: "{0} г"
13
+ :few: "{0} г"
14
+ :many: "{0} г"
15
+ :other: "{0} г"
16
+ :minute:
17
+ :abbreviated:
18
+ :one: "{0} мін"
19
+ :few: "{0} мін"
20
+ :many: "{0} мін"
21
+ :other: "{0} мін"
22
+ :second:
23
+ :abbreviated:
24
+ :one: "{0} сэк"
25
+ :few: "{0} сэк"
26
+ :many: "{0} сэк"
27
+ :other: "{0} сэк"