twitter_cldr 1.8.1 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (280) hide show
  1. data/Gemfile +3 -2
  2. data/History.txt +7 -1
  3. data/README.md +55 -0
  4. data/lib/twitter_cldr/core_ext.rb +1 -1
  5. data/lib/twitter_cldr/formatters/list_formatter.rb +64 -0
  6. data/lib/twitter_cldr/formatters.rb +4 -2
  7. data/lib/twitter_cldr/localized/localized_array.rb +19 -1
  8. data/lib/twitter_cldr/localized/localized_hash.rb +20 -0
  9. data/lib/twitter_cldr/localized/localized_string.rb +46 -1
  10. data/lib/twitter_cldr/localized/localized_symbol.rb +4 -0
  11. data/lib/twitter_cldr/localized.rb +1 -0
  12. data/lib/twitter_cldr/resources/bidi_test_importer.rb +118 -0
  13. data/lib/twitter_cldr/resources/locales_resources_importer.rb +1 -1
  14. data/lib/twitter_cldr/resources.rb +1 -0
  15. data/lib/twitter_cldr/shared/bidi.rb +526 -0
  16. data/lib/twitter_cldr/shared/languages.rb +5 -0
  17. data/lib/twitter_cldr/shared.rb +1 -0
  18. data/lib/twitter_cldr/utils/code_points.rb +1 -1
  19. data/lib/twitter_cldr/utils/yaml.rb +390 -0
  20. data/lib/twitter_cldr/utils.rb +1 -0
  21. data/lib/twitter_cldr/version.rb +1 -1
  22. data/lib/twitter_cldr.rb +2 -0
  23. data/resources/custom/locales/en/units.yml +19 -18
  24. data/resources/locales/af/calendars.yml +67 -66
  25. data/resources/locales/af/languages.yml +22 -22
  26. data/resources/locales/af/layout.yml +5 -0
  27. data/resources/locales/af/lists.yml +7 -0
  28. data/resources/locales/af/numbers.yml +36 -36
  29. data/resources/locales/af/plurals.yml +2 -3
  30. data/resources/locales/af/units.yml +75 -75
  31. data/resources/locales/ar/calendars.yml +149 -148
  32. data/resources/locales/ar/languages.yml +501 -501
  33. data/resources/locales/ar/layout.yml +5 -0
  34. data/resources/locales/ar/lists.yml +7 -0
  35. data/resources/locales/ar/numbers.yml +31 -31
  36. data/resources/locales/ar/plurals.yml +2 -9
  37. data/resources/locales/ar/units.yml +220 -220
  38. data/resources/locales/ca/calendars.yml +78 -77
  39. data/resources/locales/ca/languages.yml +199 -199
  40. data/resources/locales/ca/layout.yml +5 -0
  41. data/resources/locales/ca/lists.yml +7 -0
  42. data/resources/locales/ca/numbers.yml +36 -36
  43. data/resources/locales/ca/plurals.yml +2 -3
  44. data/resources/locales/ca/units.yml +108 -108
  45. data/resources/locales/cs/calendars.yml +141 -140
  46. data/resources/locales/cs/languages.yml +399 -399
  47. data/resources/locales/cs/layout.yml +5 -0
  48. data/resources/locales/cs/lists.yml +7 -0
  49. data/resources/locales/cs/numbers.yml +41 -41
  50. data/resources/locales/cs/plurals.yml +2 -3
  51. data/resources/locales/cs/units.yml +142 -142
  52. data/resources/locales/da/calendars.yml +73 -73
  53. data/resources/locales/da/languages.yml +36 -36
  54. data/resources/locales/da/layout.yml +5 -0
  55. data/resources/locales/da/lists.yml +7 -0
  56. data/resources/locales/da/numbers.yml +37 -37
  57. data/resources/locales/da/plurals.yml +2 -3
  58. data/resources/locales/da/units.yml +97 -97
  59. data/resources/locales/de/calendars.yml +71 -71
  60. data/resources/locales/de/languages.yml +51 -51
  61. data/resources/locales/de/layout.yml +5 -0
  62. data/resources/locales/de/lists.yml +7 -0
  63. data/resources/locales/de/numbers.yml +36 -36
  64. data/resources/locales/de/plurals.yml +2 -3
  65. data/resources/locales/de/units.yml +108 -108
  66. data/resources/locales/el/calendars.yml +213 -212
  67. data/resources/locales/el/languages.yml +520 -520
  68. data/resources/locales/el/layout.yml +5 -0
  69. data/resources/locales/el/lists.yml +7 -0
  70. data/resources/locales/el/numbers.yml +39 -39
  71. data/resources/locales/el/plurals.yml +2 -3
  72. data/resources/locales/el/units.yml +143 -143
  73. data/resources/locales/en/calendars.yml +66 -65
  74. data/resources/locales/en/languages.yml +24 -24
  75. data/resources/locales/en/layout.yml +5 -0
  76. data/resources/locales/en/lists.yml +7 -0
  77. data/resources/locales/en/numbers.yml +27 -27
  78. data/resources/locales/en/plurals.yml +2 -3
  79. data/resources/locales/en/units.yml +94 -94
  80. data/resources/locales/es/calendars.yml +80 -79
  81. data/resources/locales/es/languages.yml +139 -139
  82. data/resources/locales/es/layout.yml +5 -0
  83. data/resources/locales/es/lists.yml +7 -0
  84. data/resources/locales/es/numbers.yml +36 -36
  85. data/resources/locales/es/plurals.yml +2 -3
  86. data/resources/locales/es/units.yml +96 -96
  87. data/resources/locales/eu/calendars.yml +68 -67
  88. data/resources/locales/eu/languages.yml +11 -11
  89. data/resources/locales/eu/layout.yml +5 -0
  90. data/resources/locales/eu/lists.yml +7 -0
  91. data/resources/locales/eu/numbers.yml +36 -36
  92. data/resources/locales/eu/plurals.yml +2 -3
  93. data/resources/locales/eu/units.yml +80 -80
  94. data/resources/locales/fa/calendars.yml +223 -222
  95. data/resources/locales/fa/languages.yml +489 -489
  96. data/resources/locales/fa/layout.yml +5 -0
  97. data/resources/locales/fa/lists.yml +7 -0
  98. data/resources/locales/fa/numbers.yml +26 -26
  99. data/resources/locales/fa/plurals.yml +2 -3
  100. data/resources/locales/fa/units.yml +122 -122
  101. data/resources/locales/fi/calendars.yml +87 -87
  102. data/resources/locales/fi/languages.yml +86 -86
  103. data/resources/locales/fi/layout.yml +5 -0
  104. data/resources/locales/fi/lists.yml +7 -0
  105. data/resources/locales/fi/numbers.yml +41 -41
  106. data/resources/locales/fi/plurals.yml +2 -3
  107. data/resources/locales/fi/units.yml +124 -124
  108. data/resources/locales/fil/calendars.yml +68 -67
  109. data/resources/locales/fil/languages.yml +19 -19
  110. data/resources/locales/fil/layout.yml +5 -0
  111. data/resources/locales/fil/lists.yml +7 -0
  112. data/resources/locales/fil/numbers.yml +27 -27
  113. data/resources/locales/fil/plurals.yml +2 -3
  114. data/resources/locales/fil/units.yml +80 -80
  115. data/resources/locales/fr/calendars.yml +83 -83
  116. data/resources/locales/fr/languages.yml +117 -117
  117. data/resources/locales/fr/layout.yml +5 -0
  118. data/resources/locales/fr/lists.yml +7 -0
  119. data/resources/locales/fr/numbers.yml +37 -37
  120. data/resources/locales/fr/plurals.yml +2 -3
  121. data/resources/locales/fr/units.yml +80 -80
  122. data/resources/locales/he/calendars.yml +155 -154
  123. data/resources/locales/he/languages.yml +282 -282
  124. data/resources/locales/he/layout.yml +5 -0
  125. data/resources/locales/he/lists.yml +7 -0
  126. data/resources/locales/he/numbers.yml +27 -27
  127. data/resources/locales/he/plurals.yml +2 -3
  128. data/resources/locales/he/units.yml +122 -122
  129. data/resources/locales/hi/calendars.yml +132 -131
  130. data/resources/locales/hi/languages.yml +511 -511
  131. data/resources/locales/hi/layout.yml +5 -0
  132. data/resources/locales/hi/lists.yml +7 -0
  133. data/resources/locales/hi/numbers.yml +27 -27
  134. data/resources/locales/hi/plurals.yml +2 -3
  135. data/resources/locales/hi/units.yml +122 -122
  136. data/resources/locales/hu/calendars.yml +121 -120
  137. data/resources/locales/hu/languages.yml +214 -214
  138. data/resources/locales/hu/layout.yml +5 -0
  139. data/resources/locales/hu/lists.yml +7 -0
  140. data/resources/locales/hu/numbers.yml +39 -39
  141. data/resources/locales/hu/plurals.yml +2 -3
  142. data/resources/locales/hu/units.yml +102 -102
  143. data/resources/locales/id/calendars.yml +68 -67
  144. data/resources/locales/id/languages.yml +21 -21
  145. data/resources/locales/id/layout.yml +5 -0
  146. data/resources/locales/id/lists.yml +7 -0
  147. data/resources/locales/id/numbers.yml +37 -37
  148. data/resources/locales/id/plurals.yml +2 -3
  149. data/resources/locales/id/units.yml +73 -73
  150. data/resources/locales/it/calendars.yml +81 -80
  151. data/resources/locales/it/languages.yml +20 -20
  152. data/resources/locales/it/layout.yml +5 -0
  153. data/resources/locales/it/lists.yml +7 -0
  154. data/resources/locales/it/numbers.yml +36 -36
  155. data/resources/locales/it/plurals.yml +2 -3
  156. data/resources/locales/it/units.yml +94 -94
  157. data/resources/locales/ja/calendars.yml +123 -122
  158. data/resources/locales/ja/languages.yml +516 -516
  159. data/resources/locales/ja/layout.yml +5 -0
  160. data/resources/locales/ja/lists.yml +7 -0
  161. data/resources/locales/ja/numbers.yml +38 -38
  162. data/resources/locales/ja/plurals.yml +2 -3
  163. data/resources/locales/ja/units.yml +108 -108
  164. data/resources/locales/ko/calendars.yml +141 -140
  165. data/resources/locales/ko/languages.yml +509 -509
  166. data/resources/locales/ko/layout.yml +5 -0
  167. data/resources/locales/ko/lists.yml +7 -0
  168. data/resources/locales/ko/numbers.yml +37 -37
  169. data/resources/locales/ko/plurals.yml +2 -3
  170. data/resources/locales/ko/units.yml +108 -108
  171. data/resources/locales/ms/calendars.yml +68 -67
  172. data/resources/locales/ms/languages.yml +19 -19
  173. data/resources/locales/ms/layout.yml +5 -0
  174. data/resources/locales/ms/lists.yml +7 -0
  175. data/resources/locales/ms/numbers.yml +26 -26
  176. data/resources/locales/ms/plurals.yml +2 -3
  177. data/resources/locales/ms/units.yml +73 -73
  178. data/resources/locales/nb/calendars.yml +78 -78
  179. data/resources/locales/nb/languages.yml +93 -93
  180. data/resources/locales/nb/layout.yml +5 -0
  181. data/resources/locales/nb/lists.yml +7 -0
  182. data/resources/locales/nb/numbers.yml +37 -37
  183. data/resources/locales/nb/plurals.yml +2 -3
  184. data/resources/locales/nb/units.yml +99 -99
  185. data/resources/locales/nl/calendars.yml +67 -67
  186. data/resources/locales/nl/languages.yml +30 -30
  187. data/resources/locales/nl/layout.yml +5 -0
  188. data/resources/locales/nl/lists.yml +7 -0
  189. data/resources/locales/nl/numbers.yml +36 -36
  190. data/resources/locales/nl/plurals.yml +2 -3
  191. data/resources/locales/nl/units.yml +87 -87
  192. data/resources/locales/pl/calendars.yml +102 -101
  193. data/resources/locales/pl/languages.yml +139 -139
  194. data/resources/locales/pl/layout.yml +5 -0
  195. data/resources/locales/pl/lists.yml +7 -0
  196. data/resources/locales/pl/numbers.yml +41 -41
  197. data/resources/locales/pl/plurals.yml +2 -5
  198. data/resources/locales/pl/units.yml +149 -149
  199. data/resources/locales/pt/calendars.yml +83 -83
  200. data/resources/locales/pt/languages.yml +161 -161
  201. data/resources/locales/pt/layout.yml +5 -0
  202. data/resources/locales/pt/lists.yml +7 -0
  203. data/resources/locales/pt/numbers.yml +39 -39
  204. data/resources/locales/pt/plurals.yml +2 -3
  205. data/resources/locales/pt/units.yml +110 -110
  206. data/resources/locales/ru/calendars.yml +213 -212
  207. data/resources/locales/ru/languages.yml +511 -511
  208. data/resources/locales/ru/layout.yml +5 -0
  209. data/resources/locales/ru/lists.yml +7 -0
  210. data/resources/locales/ru/numbers.yml +40 -40
  211. data/resources/locales/ru/plurals.yml +2 -5
  212. data/resources/locales/ru/units.yml +192 -192
  213. data/resources/locales/sv/calendars.yml +85 -85
  214. data/resources/locales/sv/languages.yml +108 -108
  215. data/resources/locales/sv/layout.yml +5 -0
  216. data/resources/locales/sv/lists.yml +7 -0
  217. data/resources/locales/sv/numbers.yml +39 -39
  218. data/resources/locales/sv/plurals.yml +2 -3
  219. data/resources/locales/sv/units.yml +116 -116
  220. data/resources/locales/th/calendars.yml +172 -171
  221. data/resources/locales/th/languages.yml +510 -510
  222. data/resources/locales/th/layout.yml +5 -0
  223. data/resources/locales/th/lists.yml +7 -0
  224. data/resources/locales/th/numbers.yml +38 -38
  225. data/resources/locales/th/plurals.yml +2 -3
  226. data/resources/locales/th/units.yml +107 -107
  227. data/resources/locales/tr/calendars.yml +117 -116
  228. data/resources/locales/tr/languages.yml +143 -143
  229. data/resources/locales/tr/layout.yml +5 -0
  230. data/resources/locales/tr/lists.yml +7 -0
  231. data/resources/locales/tr/numbers.yml +37 -37
  232. data/resources/locales/tr/plurals.yml +2 -3
  233. data/resources/locales/tr/units.yml +98 -98
  234. data/resources/locales/uk/calendars.yml +187 -186
  235. data/resources/locales/uk/languages.yml +520 -520
  236. data/resources/locales/uk/layout.yml +5 -0
  237. data/resources/locales/uk/lists.yml +7 -0
  238. data/resources/locales/uk/numbers.yml +44 -44
  239. data/resources/locales/uk/plurals.yml +2 -5
  240. data/resources/locales/uk/units.yml +192 -192
  241. data/resources/locales/ur/calendars.yml +112 -111
  242. data/resources/locales/ur/languages.yml +164 -164
  243. data/resources/locales/ur/layout.yml +5 -0
  244. data/resources/locales/ur/lists.yml +7 -0
  245. data/resources/locales/ur/numbers.yml +27 -27
  246. data/resources/locales/ur/plurals.yml +2 -3
  247. data/resources/locales/ur/units.yml +136 -136
  248. data/resources/locales/zh/calendars.yml +212 -211
  249. data/resources/locales/zh/languages.yml +506 -506
  250. data/resources/locales/zh/layout.yml +5 -0
  251. data/resources/locales/zh/lists.yml +7 -0
  252. data/resources/locales/zh/numbers.yml +37 -37
  253. data/resources/locales/zh/plurals.yml +2 -3
  254. data/resources/locales/zh/units.yml +108 -108
  255. data/resources/locales/zh-Hant/calendars.yml +159 -158
  256. data/resources/locales/zh-Hant/languages.yml +510 -510
  257. data/resources/locales/zh-Hant/layout.yml +5 -0
  258. data/resources/locales/zh-Hant/lists.yml +7 -0
  259. data/resources/locales/zh-Hant/numbers.yml +38 -38
  260. data/resources/locales/zh-Hant/plurals.yml +2 -3
  261. data/resources/locales/zh-Hant/units.yml +108 -108
  262. data/spec/bidi/bidi_spec.rb +72 -0
  263. data/spec/bidi/classpath_bidi_test.txt +217202 -0
  264. data/spec/collation/tailoring_tests/da.txt +1 -1
  265. data/spec/collation/tailoring_tests/fi.txt +1 -7
  266. data/spec/collation/tailoring_tests/zh-Hant.txt +1 -1
  267. data/spec/formatters/list_formatter_spec.rb +119 -0
  268. data/spec/localized/localized_array_spec.rb +28 -0
  269. data/spec/localized/localized_hash_spec.rb +22 -0
  270. data/spec/localized/localized_number_spec.rb +3 -3
  271. data/spec/localized/localized_string_spec.rb +52 -1
  272. data/spec/localized/localized_symbol_spec.rb +7 -0
  273. data/spec/normalization/base_spec.rb +2 -4
  274. data/spec/shared/languages_spec.rb +21 -0
  275. data/spec/shared/numbers_spec.rb +4 -4
  276. data/spec/spec_helper.rb +3 -1
  277. data/spec/utils/yaml/t.gif +0 -0
  278. data/spec/utils/yaml/t.yaml +5 -0
  279. data/spec/utils/yaml/yaml_spec.rb +426 -0
  280. metadata +82 -2
@@ -1,4 +1,4 @@
1
- # Pending: 'caseFirst="upper"' is not supported (http://unicode.org/cldr/trac/browser/tags/release-21/common/collation/da.xml#L176).
1
+ # Pending: failures identical to ICU.
2
2
 
3
3
  X
4
4
  x
@@ -1,10 +1,4 @@
1
- # Pending:
2
- #
3
- # [[305, "XW", "xvx"]] - failure identical to ICU
4
- #
5
- # [[125, "xǤx", "xgx"], [283, "xŦx", "xtx"], [347, "xǮx", "xzx"]] - tailoring rules for passing these tests are
6
- # proposed, but not confirmed - http://unicode.org/cldr/trac/browser/tags/release-21/common/collation/fi.xml#L219
7
- #
1
+ # Pending: failures identical to ICU
8
2
 
9
3
  x
10
4
  X
@@ -1,4 +1,4 @@
1
- # Pending: `type="stroke"` is not supported (http://unicode.org/cldr/trac/browser/tags/release-21/common/collation/zh_Hant.xml#L11).
1
+ # Pending: failures identical to ICU.
2
2
 
3
3
  x
4
4
  X
@@ -0,0 +1,119 @@
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 ListFormatter do
11
+ describe '#initialize' do
12
+ it 'fetches locale from options hash' do
13
+ ListFormatter.new(:locale => :pt).locale.should == :pt
14
+ end
15
+
16
+ it "uses default locale if it's not passed in options hash" do
17
+ ListFormatter.new.locale.should == TwitterCldr::DEFAULT_LOCALE
18
+ end
19
+ end
20
+
21
+ context "with an initialized list formatter" do
22
+ before(:each) do
23
+ @formatter = ListFormatter.new
24
+ end
25
+
26
+ describe "#compose" do
27
+ it "should reorder rtl lists" do
28
+ list = ["larry", "curly"]
29
+ @formatter.locale = :ar
30
+ @formatter.send(:compose, "{0} \331\210 {1}", list).should == "curly \331\210 larry"
31
+ end
32
+
33
+ it "should format a variable number of elements correctly" do
34
+ list = ["larry", "curly", "moe"]
35
+ @formatter.send(:compose, "{0} - {1} - {2}", list).should == "larry - curly - moe"
36
+ @formatter.send(:compose, "{0} - {1}", list).should == "larry - curly"
37
+ @formatter.send(:compose, "{0}", list).should == "larry"
38
+ @formatter.send(:compose, "", list).should == ""
39
+ end
40
+
41
+ it "should return the first element if the list only contains a single element" do
42
+ @formatter.send(:compose, "{0} - {1}", ["larry"]).should == "larry"
43
+ end
44
+
45
+ it "should return an empty string if the list is empty" do
46
+ @formatter.send(:compose, "{0} - {1}", []).should == ""
47
+ end
48
+ end
49
+
50
+ context "with a standard resource" do
51
+ before(:each) do
52
+ stub(@formatter).resource do
53
+ {
54
+ 2 => "{0} $ {1}",
55
+ :middle => "{0}; {1}",
56
+ :start => "{0}< {1}",
57
+ :end => "{0}> {1}"
58
+ }
59
+ end
60
+ end
61
+
62
+ describe "#compose_list" do
63
+ it "should compose a list with two elements using the :end format" do
64
+ @formatter.send(:compose_list, ["larry", "curly"]).should == "larry> curly"
65
+ end
66
+
67
+ it "should compose a list with three elements using the :start and :end formats" do
68
+ @formatter.send(:compose_list, ["larry", "curly", "moe"]).should == "larry< curly> moe"
69
+ end
70
+
71
+ it "should compose a list with four elements using all the formats (:start, :middle, and :end)" do
72
+ @formatter.send(:compose_list, ["larry", "curly", "moe", "jerry"]).should == "larry< curly; moe> jerry"
73
+ end
74
+
75
+ it "should compose a list of five elements just for the hell of it" do
76
+ @formatter.send(:compose_list, ["larry", "curly", "moe", "jerry", "helga"]).should == "larry< curly; moe; jerry> helga"
77
+ end
78
+ end
79
+
80
+ describe "#format" do
81
+ it "should format correctly using the integer index if it exists" do
82
+ @formatter.format(["larry", "curly"]).should == "larry $ curly"
83
+ end
84
+
85
+ it "should format correctly if no corresponding integer index exists" do
86
+ @formatter.format(["larry", "curly", "moe"]).should == "larry< curly> moe"
87
+ end
88
+ end
89
+ end
90
+
91
+ context "with a resource that doesn't contain a start or end" do
92
+ before(:each) do
93
+ stub(@formatter).resource do
94
+ { :middle => "{0}; {1}" }
95
+ end
96
+ end
97
+
98
+ describe "#compose_list" do
99
+ it "should correctly compose a list with four elements, falling back to :middle for the beginning and end" do
100
+ @formatter.send(:compose_list, ["larry", "curly", "moe", "jerry"]).should == "larry; curly; moe; jerry"
101
+ end
102
+ end
103
+ end
104
+
105
+ context "with an empty resource" do
106
+ before(:each) do
107
+ stub(@formatter).resource do
108
+ {}
109
+ end
110
+ end
111
+
112
+ describe "#compose_list" do
113
+ it "should return a blank string since no formats are available" do
114
+ @formatter.send(:compose_list, ["larry", "curly", "moe"]).should == ""
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -46,6 +46,34 @@ describe LocalizedArray do
46
46
  end
47
47
  end
48
48
  end
49
+
50
+ describe "#each" do
51
+ it "should iterate over the items in the array and yield each one" do
52
+ arr = [1, 2, 3]
53
+ index = 0
54
+
55
+ arr.localize.each do |item|
56
+ arr[index].should == item
57
+ index += 1
58
+ end
59
+ end
60
+
61
+ it "should support a few of the other methods in Enumerable" do
62
+ [1, 2, 3].localize.inject(0) { |sum, num| sum += num; sum }.should == 6
63
+ [1, 2, 3].localize.map { |item| item + 1 }.should == [2, 3, 4]
64
+ end
65
+ end
66
+
67
+ describe "#to_yaml" do
68
+ it "should be able to successfully roundtrip the array" do
69
+ arr = [:foo, "bar", Object.new]
70
+ result = YAML.load(arr.localize.to_yaml)
71
+
72
+ result[0].should == :foo
73
+ result[1].should == "bar"
74
+ result[2].should be_a(Object)
75
+ end
76
+ end
49
77
  end
50
78
 
51
79
  class FakeCollator
@@ -0,0 +1,22 @@
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::Localized
9
+
10
+ describe LocalizedHash do
11
+ describe "#to_yaml" do
12
+ it "should be able to successfully roundtrip the hash" do
13
+ hash = { :foo => "bar", "string_key" => Object.new }
14
+ result = YAML.load(hash.localize.to_yaml)
15
+
16
+ result.should include(:foo)
17
+ result.should include("string_key")
18
+ result[:foo].should == "bar"
19
+ result["string_key"].should be_a(Object)
20
+ end
21
+ end
22
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  require 'spec_helper'
7
7
 
8
- include TwitterCldr
8
+ include TwitterCldr::Localized
9
9
 
10
10
  describe LocalizedNumber do
11
11
 
@@ -18,7 +18,7 @@ describe LocalizedNumber do
18
18
  end
19
19
 
20
20
  it 'setups DecimalFormatter by default' do
21
- decimal.formatter.should be_an_instance_of(Formatters::DecimalFormatter)
21
+ decimal.formatter.should be_an_instance_of(TwitterCldr::Formatters::DecimalFormatter)
22
22
  end
23
23
 
24
24
  it 'uses provided type if there is one' do
@@ -26,7 +26,7 @@ describe LocalizedNumber do
26
26
  end
27
27
 
28
28
  it 'setups formatter corresponding to the specified type' do
29
- currency.formatter.should be_an_instance_of(Formatters::CurrencyFormatter)
29
+ currency.formatter.should be_an_instance_of(TwitterCldr::Formatters::CurrencyFormatter)
30
30
  end
31
31
 
32
32
  it 'setups formatter with correct locale' do
@@ -31,7 +31,7 @@ describe LocalizedString do
31
31
  let(:horses) { { :one => '1 horse', :other => '%{horses_count} horses' } }
32
32
 
33
33
  before(:each) do
34
- stub(Formatters::Plurals::Rules).rule_for { |n, _| n == 1 ? :one : :other }
34
+ stub(TwitterCldr::Formatters::Plurals::Rules).rule_for { |n, _| n == 1 ? :one : :other }
35
35
  end
36
36
 
37
37
  it 'interpolates named placeholders' do
@@ -120,4 +120,55 @@ describe LocalizedString do
120
120
  end
121
121
  end
122
122
 
123
+ describe "#each_char" do
124
+ it "iterates over each character in the string if a block is given" do
125
+ index = 0
126
+ str = "twitter"
127
+
128
+ str.localize.each_char do |char|
129
+ str.chars.to_a[index].should == char
130
+ index += 1
131
+ end
132
+ end
133
+
134
+ it "returns an enumerator if no block is given" do
135
+ "twitter".localize.each_char.should be_a(Enumerator)
136
+ end
137
+
138
+ it "responds to a few other methods from Enumerable" do
139
+ upcased = "twitter".localize.map { |letter| letter.upcase }
140
+ upcased.size.should == 7
141
+ upcased.join.should == "TWITTER"
142
+
143
+ "twitter".localize.inject("") { |str, letter| str = "#{letter}#{str}"; str }.should == "rettiwt"
144
+ end
145
+ end
146
+
147
+ describe "#to_yaml" do
148
+ it "should be able to successfully roundtrip the string" do
149
+ YAML.load("coolio".localize.to_yaml).should == "coolio"
150
+ YAML.load("coolió".localize.to_yaml).should == "coolió"
151
+ end
152
+ end
153
+
154
+ describe "#to_bidi" do
155
+ it "should return an instance of TwitterCldr::Shared::Bidi" do
156
+ "abc".localize.to_bidi.should be_a(TwitterCldr::Shared::Bidi)
157
+ end
158
+ end
159
+
160
+ describe "#to_reordered_s" do
161
+ it "should reverse the order a basic RTL string" do
162
+ str = "{0} \331\210 {1}".gsub("{0}", "a").gsub("{1}", "b")
163
+ chars = str.chars.to_a
164
+ chars.first.should == "a"
165
+ chars.last.should == "b"
166
+
167
+ result = str.localize.to_reordered_s(:direction => :RTL)
168
+ result_chars = result.chars.to_a
169
+ result_chars.first.should == "b"
170
+ result_chars.last.should == "a"
171
+ end
172
+ end
173
+
123
174
  end
@@ -28,4 +28,11 @@ describe LocalizedSymbol do
28
28
  end
29
29
  end
30
30
 
31
+ describe "#is_rtl?" do
32
+ it "should return true or false depending on the locale" do
33
+ :es.localize.is_rtl?.should be_false
34
+ :ar.localize.is_rtl?.should be_true
35
+ end
36
+ end
37
+
31
38
  end
@@ -5,13 +5,11 @@
5
5
 
6
6
  require 'spec_helper'
7
7
 
8
- include TwitterCldr::Normalization
9
-
10
8
  describe Base do
11
9
  describe "#combining_class_for" do
12
10
  it "returns the correct combining class for select code points" do
13
- Base.combining_class_for(0x303).should == 230 # combining tilde
14
- Base.combining_class_for(0x6E).should == 0 # latin letter n
11
+ TwitterCldr::Normalization::Base.combining_class_for(0x303).should == 230 # combining tilde
12
+ TwitterCldr::Normalization::Base.combining_class_for(0x6E).should == 0 # latin letter n
15
13
  end
16
14
  end
17
15
  end
@@ -85,4 +85,25 @@ describe Languages do
85
85
  langs[:de].should == "alemán"
86
86
  end
87
87
  end
88
+
89
+ describe "#is_rtl?" do
90
+ it "should return true for certain locales" do
91
+ [:ar, :he, :ur, :fa].each do |locale|
92
+ Languages.is_rtl?(locale).should be_true
93
+ end
94
+ end
95
+
96
+ it "should return false for certain locales" do
97
+ [:en, :es, :hu, :ja].each do |locale|
98
+ Languages.is_rtl?(locale).should be_false
99
+ end
100
+ end
101
+
102
+ it "should not raise errors for any locale" do
103
+ TwitterCldr.supported_locales.each do |locale|
104
+ lambda { Languages.is_rtl?(locale) }.should_not raise_error
105
+ end
106
+ end
107
+ end
108
+
88
109
  end
@@ -14,22 +14,22 @@ describe Numbers do
14
14
  it 'returns numerical symbols for default locale' do
15
15
  stub(TwitterCldr).get_locale { :jp }
16
16
  stub(TwitterCldr).get_locale_resource(:jp, :numbers) { { :jp => { :numbers => { :symbols => symbols } } } }
17
- Numbers.symbols.should == symbols
17
+ TwitterCldr::Shared::Numbers.symbols.should == symbols
18
18
  end
19
19
 
20
20
  it 'returns numerical symbols for default locale' do
21
21
  stub(TwitterCldr).get_locale_resource(:np, :numbers) { { :np => { :numbers => { :symbols => symbols } } } }
22
- Numbers.symbols(:np).should == symbols
22
+ TwitterCldr::Shared::Numbers.symbols(:np).should == symbols
23
23
  end
24
24
 
25
25
  it 'converts locale' do
26
26
  stub(TwitterCldr).get_locale_resource(:'zh-Hant', :numbers) { { :'zh-Hant' => { :numbers => { :symbols => symbols } } } }
27
- Numbers.symbols('zh-tw').should == symbols
27
+ TwitterCldr::Shared::Numbers.symbols('zh-tw').should == symbols
28
28
  end
29
29
 
30
30
  it 'returns nil if the resource is missing' do
31
31
  stub(TwitterCldr).get_locale_resource(:nop, :numbers) { nil }
32
- Numbers.symbols(:nop).should be_nil
32
+ TwitterCldr::Shared::Numbers.symbols(:nop).should be_nil
33
33
  end
34
34
  end
35
35
  end
data/spec/spec_helper.rb CHANGED
@@ -8,8 +8,10 @@ require 'twitter_cldr'
8
8
 
9
9
  class FastGettext
10
10
  class << self
11
+ @@locale = :en
12
+
11
13
  def locale
12
- @@locale || :en
14
+ @@locale
13
15
  end
14
16
 
15
17
  def locale=(value)
Binary file
@@ -0,0 +1,5 @@
1
+ ---
2
+ list:
3
+ - perl
4
+ - ruby
5
+ - python