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
@@ -0,0 +1,390 @@
1
+ # encoding: UTF-8
2
+
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ # This code was adapted from the ya2yaml gem, maintained by Akira Funai.
7
+ # https://github.com/afunai/ya2yaml
8
+
9
+ # Copyright (c) 2006 Akira FUNAI <funai.akira@gmail.com>
10
+ #
11
+ # Permission is hereby granted, free of charge, to any person obtaining a
12
+ # copy of this software and associated documentation files (the "Software"),
13
+ # to deal in the Software without restriction, including without limitation
14
+ # the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
+ # and/or sell copies of the Software, and to permit persons to whom the
16
+ # Software is furnished to do so, subject to the following conditions:
17
+ #
18
+ # The above copyright notice and this permission notice shall be included in
19
+ # all copies or substantial portions of the Software.
20
+ #
21
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
+ # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
+ # DEALINGS IN THE SOFTWARE.
28
+
29
+
30
+ module TwitterCldr
31
+ module Utils
32
+
33
+ class YAML
34
+
35
+ UCS_0X85 = [0x85].pack('U') # c285@UTF8 Unicode next line
36
+ UCS_0XA0 = [0xa0].pack('U') # c2a0@UTF8 Unicode non-breaking space
37
+ UCS_0X2028 = [0x2028].pack('U') # e280a8@UTF8 Unicode line separator
38
+ UCS_0X2029 = [0x2029].pack('U') # e280a9@UTF8 Unicode paragraph separator
39
+
40
+ # non-break characters
41
+ ESCAPE_SEQ = {
42
+ "\x00" => '\\0',
43
+ "\x07" => '\\a',
44
+ "\x08" => '\\b',
45
+ "\x0b" => '\\v',
46
+ "\x0c" => '\\f',
47
+ "\x1b" => '\\e',
48
+ "\"" => '\\"',
49
+ "\\" => '\\\\',
50
+ }
51
+
52
+ # non-breaking space
53
+ ESCAPE_SEQ_NS = {
54
+ UCS_0XA0 => '\\_',
55
+ }
56
+
57
+ # white spaces
58
+ ESCAPE_SEQ_WS = {
59
+ "\x09" => '\\t',
60
+ " " => '\\x20',
61
+ }
62
+
63
+ # line breaks
64
+ ESCAPE_SEQ_LB ={
65
+ "\x0a" => '\\n',
66
+ "\x0d" => '\\r',
67
+ UCS_0X85 => '\\N',
68
+ UCS_0X2028 => '\\L',
69
+ UCS_0X2029 => '\\P',
70
+ }
71
+
72
+ # regexps for line breaks
73
+ REX_LF = Regexp.escape("\x0a")
74
+ REX_CR = Regexp.escape("\x0d")
75
+ REX_CRLF = Regexp.escape("\x0d\x0a")
76
+ REX_NEL = Regexp.escape(UCS_0X85)
77
+ REX_LS = Regexp.escape(UCS_0X2028)
78
+ REX_PS = Regexp.escape(UCS_0X2029)
79
+
80
+ REX_ANY_LB = /(#{REX_LF}|#{REX_CR}|#{REX_NEL}|#{REX_LS}|#{REX_PS})/
81
+ REX_NORMAL_LB = /(#{REX_LF}|#{REX_LS}|#{REX_PS})/
82
+
83
+ # regexps for language-Independent types for YAML1.1
84
+ REX_BOOL = /
85
+ y|Y|yes|Yes|YES|n|N|no|No|NO
86
+ |true|True|TRUE|false|False|FALSE
87
+ |on|On|ON|off|Off|OFF
88
+ /x
89
+ REX_FLOAT = /
90
+ [-+]?([0-9][0-9_]*)?\.[0-9.]*([eE][-+][0-9]+)? # (base 10)
91
+ |[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+\.[0-9_]* # (base 60)
92
+ |[-+]?\.(inf|Inf|INF) # (infinity)
93
+ |\.(nan|NaN|NAN) # (not a number)
94
+ /x
95
+ REX_INT = /
96
+ [-+]?0b[0-1_]+ # (base 2)
97
+ |[-+]?0[0-7_]+ # (base 8)
98
+ |[-+]?(0|[1-9][0-9_]*) # (base 10)
99
+ |[-+]?0x[0-9a-fA-F_]+ # (base 16)
100
+ |[-+]?[1-9][0-9_]*(:[0-5]?[0-9])+ # (base 60)
101
+ /x
102
+ REX_MERGE = /
103
+ <<
104
+ /x
105
+ REX_NULL = /
106
+ ~ # (canonical)
107
+ |null|Null|NULL # (English)
108
+ | # (Empty)
109
+ /x
110
+ REX_TIMESTAMP = /
111
+ [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] # (ymd)
112
+ |[0-9][0-9][0-9][0-9] # (year)
113
+ -[0-9][0-9]? # (month)
114
+ -[0-9][0-9]? # (day)
115
+ ([Tt]|[ \t]+)[0-9][0-9]? # (hour)
116
+ :[0-9][0-9] # (minute)
117
+ :[0-9][0-9] # (second)
118
+ (\.[0-9]*)? # (fraction)
119
+ (([ \t]*)Z|[-+][0-9][0-9]?(:[0-9][0-9])?)? # (time zone)
120
+ /x
121
+ REX_VALUE = /
122
+ =
123
+ /x
124
+ REX_SYMBOL = /
125
+ \A:.*
126
+ /x
127
+
128
+ class << self
129
+
130
+ def dump(obj, opts = {})
131
+ raise 'set $KCODE to "UTF8".' if (RUBY_VERSION < '1.9.0') && ($KCODE != 'UTF8')
132
+
133
+ @options = opts.dup
134
+ @options[:indent_size] = 2 if @options[:indent_size].to_i <= 0
135
+ @options[:minimum_block_length] = 0 if @options[:minimum_block_length].to_i <= 0
136
+ @options.update(
137
+ {
138
+ :printable_with_syck => true,
139
+ :escape_b_specific => true,
140
+ :escape_as_utf8 => true,
141
+ }
142
+ ) if @options[:syck_compatible]
143
+
144
+ "--- #{emit(obj, 1)}\n"
145
+ rescue SystemStackError
146
+ raise ArgumentError, "TwitterCLDR yaml dumper can't handle circular references"
147
+ end
148
+
149
+ private
150
+
151
+ def emit(obj, level)
152
+ case obj
153
+ when Array
154
+ if (obj.length == 0)
155
+ '[]'
156
+ else
157
+ indent = "\n#{s_indent(level - 1)}"
158
+ obj.collect do |o|
159
+ "#{indent}- #{emit(o, level + 1)}"
160
+ end.join('')
161
+ end
162
+ when Hash
163
+ if (obj.length == 0)
164
+ '{}'
165
+ else
166
+ indent = "\n#{s_indent(level - 1)}"
167
+ hash_order = @options[:hash_order]
168
+ if (hash_order && level == 1)
169
+ hash_keys = obj.keys.sort do |x, y|
170
+ x_order = hash_order.index(x) ? hash_order.index(x) : Float::MAX
171
+ y_order = hash_order.index(y) ? hash_order.index(y) : Float::MAX
172
+ o = (x_order <=> y_order)
173
+ (o != 0) ? o : (x.to_s <=> y.to_s)
174
+ end
175
+ elsif @options[:preserve_order]
176
+ hash_keys = obj.keys
177
+ else
178
+ hash_keys = obj.keys.sort { |x, y| x.to_s <=> y.to_s }
179
+ end
180
+ hash_keys.collect do |k|
181
+ key = emit(k, level + 1)
182
+ if (
183
+ is_one_plain_line?(key) ||
184
+ key =~ /\A(#{REX_BOOL}|#{REX_FLOAT}|#{REX_INT}|#{REX_NULL}|#{REX_SYMBOL})\z/x
185
+ )
186
+ "#{indent}#{key}: #{emit(obj[k], level + 1)}"
187
+ else
188
+ "#{indent}? #{key}#{indent}: #{emit(obj[k], level + 1)}"
189
+ end
190
+ end.join('')
191
+ end
192
+ when NilClass
193
+ '~'
194
+ when String
195
+ emit_string(obj, level)
196
+ when TrueClass, FalseClass
197
+ obj.to_s
198
+ when Fixnum, Bignum, Float
199
+ obj.to_s
200
+ when Date
201
+ obj.to_s
202
+ when Time
203
+ offset = obj.gmtoff
204
+ off_hm = sprintf(
205
+ '%+.2d:%.2d',
206
+ (offset / 3600.0).to_i,
207
+ (offset % 3600.0) / 60
208
+ )
209
+ u_sec = (obj.usec != 0) ? sprintf(".%.6d", obj.usec) : ''
210
+ obj.strftime("%Y-%m-%d %H:%M:%S#{u_sec} #{off_hm}")
211
+ when Symbol
212
+ prefix = @options[:use_natural_symbols] && is_one_plain_line?(obj.to_s) ? ":" : "!ruby/symbol "
213
+ "#{prefix}#{emit_string(obj.to_s, level)}"
214
+ when Range
215
+ '!ruby/range ' + obj.to_s
216
+ when Regexp
217
+ '!ruby/regexp ' + obj.inspect
218
+ else
219
+ case
220
+ when obj.is_a?(Struct)
221
+ struct_members = {}
222
+ obj.each_pair { |k, v| struct_members[k.to_s] = v }
223
+ "!ruby/struct:#{obj.class.to_s.sub(/^(Struct::(.+)|.*)$/, '\2')} #{emit(struct_members, level + 1)}"
224
+ else
225
+ # serialized as a generic object
226
+ object_members = {}
227
+ obj.instance_variables.each do |k, v|
228
+ object_members[k.to_s.sub(/^@/, '')] = obj.instance_variable_get(k)
229
+ end
230
+ "!ruby/object:#{obj.class.to_s} #{emit(object_members, level + 1)}"
231
+ end
232
+ end
233
+ end
234
+
235
+ def emit_string(str, level)
236
+ (is_string, is_printable, is_one_line, is_one_plain_line) = string_type(str)
237
+ if is_string
238
+ if is_printable
239
+ if is_one_plain_line
240
+ emit_simple_string(str, level)
241
+ else
242
+ (is_one_line || str.length < @options[:minimum_block_length]) ?
243
+ emit_quoted_string(str, level) :
244
+ emit_block_string(str, level)
245
+ end
246
+ else
247
+ emit_quoted_string(str, level)
248
+ end
249
+ else
250
+ emit_base64_binary(str, level)
251
+ end
252
+ end
253
+
254
+ def emit_simple_string(str, level)
255
+ str
256
+ end
257
+
258
+ def emit_block_string(str, level)
259
+ str = normalize_line_break(str)
260
+
261
+ indent = s_indent(level)
262
+ indentation_indicator = (str =~ /\A /) ? indent.size.to_s : ''
263
+ str =~ /(#{REX_NORMAL_LB}*)\z/
264
+ chomping_indicator = case $1.length
265
+ when 0
266
+ '-'
267
+ when 1
268
+ ''
269
+ else
270
+ '+'
271
+ end
272
+
273
+ str.chomp!
274
+ str.gsub!(/#{REX_NORMAL_LB}/) { $1 + indent }
275
+ "|#{indentation_indicator}#{chomping_indicator}\n#{indent}#{str}"
276
+ end
277
+
278
+ def emit_quoted_string(str, level)
279
+ str = yaml_escape(normalize_line_break(str))
280
+ if (str.length < @options[:minimum_block_length])
281
+ str.gsub!(/#{REX_NORMAL_LB}/) { ESCAPE_SEQ_LB[$1] }
282
+ else
283
+ str.gsub!(/#{REX_NORMAL_LB}$/) { ESCAPE_SEQ_LB[$1] }
284
+ str.gsub!(/(#{REX_NORMAL_LB}+)(.)/) do
285
+ trail_c = $3
286
+ $1 + trail_c.sub(/([\t ])/) { ESCAPE_SEQ_WS[$1] }
287
+ end
288
+ indent = s_indent(level)
289
+ str.gsub!(/#{REX_NORMAL_LB}/) { "#{ESCAPE_SEQ_LB[$1]}\\\n#{indent}" }
290
+ end
291
+ %Q("#{str}")
292
+ end
293
+
294
+ def emit_base64_binary(str, level)
295
+ indent = "\n#{s_indent(level)}"
296
+ base64 = [str].pack('m')
297
+ "!binary |#{indent}#{base64.gsub(/\n(?!\z)/, indent)}"
298
+ end
299
+
300
+ def string_type(str)
301
+ if str.respond_to?(:encoding) && (!str.valid_encoding? || str.encoding == Encoding::ASCII_8BIT)
302
+ return false, false, false, false
303
+ end
304
+ (ucs_codes = str.unpack('U*')) rescue (
305
+ # ArgumentError -> binary data
306
+ return false, false, false, false
307
+ )
308
+ if (
309
+ @options[:printable_with_syck] &&
310
+ str =~ /\A#{REX_ANY_LB}* | #{REX_ANY_LB}*\z|#{REX_ANY_LB}{2}\z/
311
+ )
312
+ # detour Syck bug
313
+ return true, false, nil, false
314
+ end
315
+ ucs_codes.each {|ucs_code|
316
+ return true, false, nil, false unless is_printable?(ucs_code)
317
+ }
318
+ return true, true, is_one_line?(str), is_one_plain_line?(str)
319
+ end
320
+
321
+ def is_printable?(ucs_code)
322
+ # YAML 1.1 / 4.1.1.
323
+ (
324
+ [0x09, 0x0a, 0x0d, 0x85].include?(ucs_code) ||
325
+ (ucs_code <= 0x7e && ucs_code >= 0x20) ||
326
+ (ucs_code <= 0xd7ff && ucs_code >= 0xa0) ||
327
+ (ucs_code <= 0xfffd && ucs_code >= 0xe000) ||
328
+ (ucs_code <= 0x10ffff && ucs_code >= 0x10000)
329
+ ) &&
330
+ !(
331
+ # treat LS/PS as non-printable characters
332
+ @options[:escape_b_specific] &&
333
+ (ucs_code == 0x2028 || ucs_code == 0x2029)
334
+ )
335
+ end
336
+
337
+ def is_one_line?(str)
338
+ str !~ /#{REX_ANY_LB}(?!\z)/
339
+ end
340
+
341
+ def is_one_plain_line?(str)
342
+ # YAML 1.1 / 4.6.11.
343
+ str !~ /^([\-\?:,\[\]\{\}\#&\*!\|>'"%@`\s]|---|\.\.\.)/ &&
344
+ str !~ /[:\#\s\[\]\{\},]/ &&
345
+ str !~ /#{REX_ANY_LB}/ &&
346
+ str !~ /^(#{REX_BOOL}|#{REX_FLOAT}|#{REX_INT}|#{REX_MERGE}
347
+ |#{REX_NULL}|#{REX_TIMESTAMP}|#{REX_VALUE})$/x
348
+ end
349
+
350
+ def s_indent(level)
351
+ # YAML 1.1 / 4.2.2.
352
+ ' ' * (level * @options[:indent_size])
353
+ end
354
+
355
+ def normalize_line_break(str)
356
+ # YAML 1.1 / 4.1.4.
357
+ str.gsub(/(#{REX_CRLF}|#{REX_CR}|#{REX_NEL})/, "\n")
358
+ end
359
+
360
+ def yaml_escape(str)
361
+ # YAML 1.1 / 4.1.6.
362
+ str.gsub(/[^a-zA-Z0-9]/u) do |c|
363
+ ucs_code, = (c.unpack('U') rescue [??])
364
+ case
365
+ when ESCAPE_SEQ[c]
366
+ ESCAPE_SEQ[c]
367
+ when is_printable?(ucs_code)
368
+ c
369
+ when @options[:escape_as_utf8]
370
+ c.respond_to?(:bytes) ?
371
+ c.bytes.collect { |b| '\\x%.2x' % b }.join :
372
+ '\\x' + c.unpack('H2' * c.size).join('\\x')
373
+ when ucs_code == 0x2028 || ucs_code == 0x2029
374
+ ESCAPE_SEQ_LB[c]
375
+ when ucs_code <= 0x7f
376
+ sprintf('\\x%.2x', ucs_code)
377
+ when ucs_code <= 0xffff
378
+ sprintf('\\u%.4x', ucs_code)
379
+ else
380
+ sprintf('\\U%.8x', ucs_code)
381
+ end
382
+ end
383
+ end
384
+
385
+ end
386
+
387
+ end
388
+
389
+ end
390
+ end
@@ -7,6 +7,7 @@ module TwitterCldr
7
7
  module Utils
8
8
 
9
9
  autoload :CodePoints, 'twitter_cldr/utils/code_points'
10
+ autoload :YAML, 'twitter_cldr/utils/yaml'
10
11
 
11
12
  class << self
12
13
 
@@ -4,5 +4,5 @@
4
4
  # http://www.apache.org/licenses/LICENSE-2.0
5
5
 
6
6
  module TwitterCldr
7
- VERSION = "1.8.1"
7
+ VERSION = "1.9.0"
8
8
  end
data/lib/twitter_cldr.rb CHANGED
@@ -15,6 +15,8 @@ require 'forwardable'
15
15
 
16
16
  require 'twitter_cldr/version'
17
17
 
18
+ Enumerator = Enumerable::Enumerator unless defined?(Enumerator)
19
+
18
20
  module TwitterCldr
19
21
 
20
22
  autoload :Formatters, 'twitter_cldr/formatters'
@@ -1,18 +1,19 @@
1
- en:
2
- units:
3
- day:
4
- abbreviated:
5
- one: "{0}d"
6
- other: "{0}d"
7
- hour:
8
- abbreviated:
9
- one: "{0}h"
10
- other: "{0}h"
11
- minute:
12
- abbreviated:
13
- one: "{0}m"
14
- other: "{0}m"
15
- second:
16
- abbreviated:
17
- one: "{0}s"
18
- other: "{0}s"
1
+ ---
2
+ :en:
3
+ :units:
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'
@@ -1,10 +1,10 @@
1
- ---
2
- :af:
3
- :calendars:
4
- :gregorian:
5
- :days:
6
- :format:
7
- :abbreviated:
1
+ ---
2
+ :af:
3
+ :calendars:
4
+ :gregorian:
5
+ :days:
6
+ :format:
7
+ :abbreviated:
8
8
  :fri: Vr
9
9
  :mon: Ma
10
10
  :sat: Sa
@@ -12,8 +12,8 @@
12
12
  :thu: Do
13
13
  :tue: Di
14
14
  :wed: Wo
15
- :narrow: :calendars.gregorian.days.stand-alone.narrow
16
- :wide:
15
+ :narrow: :"calendars.gregorian.days.stand-alone.narrow"
16
+ :wide:
17
17
  :fri: Vrydag
18
18
  :mon: Maandag
19
19
  :sat: Saterdag
@@ -21,9 +21,9 @@
21
21
  :thu: Donderdag
22
22
  :tue: Dinsdag
23
23
  :wed: Woensdag
24
- :stand-alone:
25
- :abbreviated: :calendars.gregorian.days.format.abbreviated
26
- :narrow:
24
+ :"stand-alone":
25
+ :abbreviated: :"calendars.gregorian.days.format.abbreviated"
26
+ :narrow:
27
27
  :fri: V
28
28
  :mon: M
29
29
  :sat: S
@@ -31,17 +31,17 @@
31
31
  :thu: D
32
32
  :tue: D
33
33
  :wed: W
34
- :wide: :calendars.gregorian.days.format.wide
35
- :eras:
36
- :abbr:
34
+ :wide: :"calendars.gregorian.days.format.wide"
35
+ :eras:
36
+ :abbr:
37
37
  0: v.C.
38
38
  1: n.C.
39
- :name:
39
+ :name:
40
40
  0: voor Christus
41
41
  1: na Christus
42
- :narrow:
43
- 0: ''
44
- :fields:
42
+ :narrow:
43
+ 0: ""
44
+ :fields:
45
45
  :day: Dag
46
46
  :dayperiod: AM/PM
47
47
  :era: Era
@@ -53,40 +53,40 @@
53
53
  :weekday: Weeksdag
54
54
  :year: Jaar
55
55
  :zone: Tydsone
56
- :formats:
57
- :date:
58
- :default: :calendars.gregorian.formats.date.medium
59
- :full:
56
+ :formats:
57
+ :date:
58
+ :default: :"calendars.gregorian.formats.date.medium"
59
+ :full:
60
60
  :pattern: EEEE dd MMMM y
61
- :long:
61
+ :long:
62
62
  :pattern: dd MMMM y
63
- :medium:
63
+ :medium:
64
64
  :pattern: dd MMM y
65
- :short:
65
+ :short:
66
66
  :pattern: yyyy-MM-dd
67
- :datetime:
68
- :default: :calendars.gregorian.formats.datetime.medium
69
- :full:
70
- :pattern: ! '{{date}} {{time}}'
71
- :long:
72
- :pattern: ! '{{date}} {{time}}'
73
- :medium:
74
- :pattern: ! '{{date}} {{time}}'
75
- :short:
76
- :pattern: ! '{{date}} {{time}}'
77
- :time:
78
- :default: :calendars.gregorian.formats.time.medium
79
- :full:
67
+ :datetime:
68
+ :default: :"calendars.gregorian.formats.datetime.medium"
69
+ :full:
70
+ :pattern: "{{date}} {{time}}"
71
+ :long:
72
+ :pattern: "{{date}} {{time}}"
73
+ :medium:
74
+ :pattern: "{{date}} {{time}}"
75
+ :short:
76
+ :pattern: "{{date}} {{time}}"
77
+ :time:
78
+ :default: :"calendars.gregorian.formats.time.medium"
79
+ :full:
80
80
  :pattern: h:mm:ss a zzzz
81
- :long:
81
+ :long:
82
82
  :pattern: h:mm:ss a z
83
- :medium:
83
+ :medium:
84
84
  :pattern: h:mm:ss a
85
- :short:
85
+ :short:
86
86
  :pattern: h:mm a
87
- :months:
88
- :format:
89
- :abbreviated:
87
+ :months:
88
+ :format:
89
+ :abbreviated:
90
90
  1: Jan
91
91
  10: Okt
92
92
  11: Nov
@@ -99,8 +99,8 @@
99
99
  7: Jul
100
100
  8: Aug
101
101
  9: Sep
102
- :narrow: :calendars.gregorian.months.stand-alone.narrow
103
- :wide:
102
+ :narrow: :"calendars.gregorian.months.stand-alone.narrow"
103
+ :wide:
104
104
  1: Januarie
105
105
  10: Oktober
106
106
  11: November
@@ -113,9 +113,9 @@
113
113
  7: Julie
114
114
  8: Augustus
115
115
  9: September
116
- :stand-alone:
117
- :abbreviated: :calendars.gregorian.months.format.abbreviated
118
- :narrow:
116
+ :"stand-alone":
117
+ :abbreviated: :"calendars.gregorian.months.format.abbreviated"
118
+ :narrow:
119
119
  1: J
120
120
  10: O
121
121
  11: N
@@ -128,38 +128,39 @@
128
128
  7: J
129
129
  8: A
130
130
  9: S
131
- :wide:
131
+ :wide:
132
132
  4: April
133
- :periods:
134
- :format:
135
- :abbreviated: :calendars.gregorian.dayPeriods.format.wide
136
- :narrow: :calendars.gregorian.dayPeriods.format.abbreviated
137
- :wide:
133
+ :periods:
134
+ :format:
135
+ :abbreviated: :"calendars.gregorian.dayPeriods.format.wide"
136
+ :narrow: :"calendars.gregorian.dayPeriods.format.abbreviated"
137
+ :wide:
138
138
  :am: vm.
139
139
  :pm: nm.
140
- :stand-alone: {}
141
- :quarters:
142
- :format:
143
- :abbreviated:
140
+ :"stand-alone": {}
141
+
142
+ :quarters:
143
+ :format:
144
+ :abbreviated:
144
145
  1: K1
145
146
  2: K2
146
147
  3: K3
147
148
  4: K4
148
- :narrow:
149
+ :narrow:
149
150
  1: 1
150
151
  2: 2
151
152
  3: 3
152
153
  4: 4
153
- :wide:
154
+ :wide:
154
155
  1: 1ste kwartaal
155
156
  2: 2de kwartaal
156
157
  3: 3de kwartaal
157
158
  4: 4de kwartaal
158
- :stand-alone:
159
- :abbreviated: :calendars.gregorian.quarters.format.abbreviated
160
- :narrow:
159
+ :"stand-alone":
160
+ :abbreviated: :"calendars.gregorian.quarters.format.abbreviated"
161
+ :narrow:
161
162
  1: 1
162
163
  2: 2
163
164
  3: 3
164
165
  4: 4
165
- :wide: :calendars.gregorian.quarters.format.wide
166
+ :wide: :"calendars.gregorian.quarters.format.wide"