tr8n_core 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +69 -0
  4. data/Rakefile +9 -0
  5. data/config/config.yml +34 -0
  6. data/config/tokens/data.yml +45 -0
  7. data/config/tokens/decorations.yml +37 -0
  8. data/lib/tr8n/application.rb +320 -0
  9. data/lib/tr8n/base.rb +123 -0
  10. data/lib/tr8n/cache.rb +144 -0
  11. data/lib/tr8n/cache_adapters/cdb.rb +74 -0
  12. data/lib/tr8n/cache_adapters/file.rb +70 -0
  13. data/lib/tr8n/cache_adapters/memcache.rb +91 -0
  14. data/lib/tr8n/cache_adapters/redis.rb +94 -0
  15. data/lib/tr8n/component.rb +68 -0
  16. data/lib/tr8n/config.rb +291 -0
  17. data/lib/tr8n/decorators/base.rb +35 -0
  18. data/lib/tr8n/decorators/default.rb +30 -0
  19. data/lib/tr8n/decorators/html.rb +63 -0
  20. data/lib/tr8n/exception.rb +26 -0
  21. data/lib/tr8n/language.rb +250 -0
  22. data/lib/tr8n/language_case.rb +116 -0
  23. data/lib/tr8n/language_case_rule.rb +85 -0
  24. data/lib/tr8n/language_context.rb +115 -0
  25. data/lib/tr8n/language_context_rule.rb +62 -0
  26. data/lib/tr8n/logger.rb +83 -0
  27. data/lib/tr8n/rules_engine/evaluator.rb +156 -0
  28. data/lib/tr8n/rules_engine/parser.rb +83 -0
  29. data/lib/tr8n/source.rb +95 -0
  30. data/lib/tr8n/tokens/data.rb +410 -0
  31. data/lib/tr8n/tokens/data_tokenizer.rb +82 -0
  32. data/lib/tr8n/tokens/decoration_tokenizer.rb +200 -0
  33. data/lib/tr8n/tokens/hidden.rb +48 -0
  34. data/lib/tr8n/tokens/method.rb +52 -0
  35. data/lib/tr8n/tokens/transform.rb +191 -0
  36. data/lib/tr8n/translation.rb +104 -0
  37. data/lib/tr8n/translation_key.rb +205 -0
  38. data/lib/tr8n/translator.rb +62 -0
  39. data/lib/tr8n/utils.rb +124 -0
  40. data/lib/tr8n_core/ext/array.rb +74 -0
  41. data/lib/tr8n_core/ext/date.rb +63 -0
  42. data/lib/tr8n_core/ext/fixnum.rb +39 -0
  43. data/lib/tr8n_core/ext/hash.rb +126 -0
  44. data/lib/tr8n_core/ext/string.rb +44 -0
  45. data/lib/tr8n_core/ext/time.rb +71 -0
  46. data/lib/tr8n_core/generators/cache/base.rb +85 -0
  47. data/lib/tr8n_core/generators/cache/cdb.rb +27 -0
  48. data/lib/tr8n_core/generators/cache/file.rb +69 -0
  49. data/lib/tr8n_core/modules/logger.rb +43 -0
  50. data/lib/tr8n_core/version.rb +27 -0
  51. data/lib/tr8n_core.rb +68 -0
  52. data/spec/application_spec.rb +228 -0
  53. data/spec/base_spec.rb +19 -0
  54. data/spec/config_spec.rb +16 -0
  55. data/spec/decorator_spec.rb +10 -0
  56. data/spec/decorators/base_spec.rb +14 -0
  57. data/spec/decorators/default_spec.rb +12 -0
  58. data/spec/decorators/html_spec.rb +50 -0
  59. data/spec/fixtures/application.json +112 -0
  60. data/spec/fixtures/languages/en-US.json +1424 -0
  61. data/spec/fixtures/languages/es.json +291 -0
  62. data/spec/fixtures/languages/ru.json +550 -0
  63. data/spec/fixtures/translations/ru/basic.json +56 -0
  64. data/spec/fixtures/translations/ru/counters.json +43 -0
  65. data/spec/fixtures/translations/ru/genders.json +171 -0
  66. data/spec/fixtures/translations/ru/last_names.txt +200 -0
  67. data/spec/fixtures/translations/ru/names.json +1 -0
  68. data/spec/fixtures/translations/ru/names.txt +458 -0
  69. data/spec/helper.rb +84 -0
  70. data/spec/language_case_rule_spec.rb +57 -0
  71. data/spec/language_case_spec.rb +58 -0
  72. data/spec/language_context_rule_spec.rb +73 -0
  73. data/spec/language_context_spec.rb +331 -0
  74. data/spec/language_spec.rb +16 -0
  75. data/spec/rules_engine/evaluator_spec.rb +148 -0
  76. data/spec/rules_engine/parser_spec.rb +29 -0
  77. data/spec/tokens/data_spec.rb +160 -0
  78. data/spec/tokens/data_tokenizer_spec.rb +29 -0
  79. data/spec/tokens/decoration_tokenizer_spec.rb +81 -0
  80. data/spec/tokens/hidden_spec.rb +24 -0
  81. data/spec/tokens/method_spec.rb +84 -0
  82. data/spec/tokens/transform_spec.rb +50 -0
  83. data/spec/translation_key_spec.rb +96 -0
  84. data/spec/translation_spec.rb +24 -0
  85. data/spec/utils_spec.rb +64 -0
  86. metadata +176 -0
@@ -0,0 +1,291 @@
1
+ {
2
+ "locale":"es",
3
+ "name":"Español",
4
+ "english_name":"Spanish",
5
+ "native_name":"Español",
6
+ "flag_url":"http://localhost:3000/media/52/47/56/19/6594b760c14053ef4.png",
7
+ "contexts":{
8
+ "date":{
9
+ "keyword":"date",
10
+ "keys":[
11
+ "past",
12
+ "present",
13
+ "future"
14
+ ],
15
+ "default_key":"present",
16
+ "token_expression":"/.*(date|time)(\\d)*$/",
17
+ "variables":[
18
+ "@date"
19
+ ],
20
+ "token_mapping":[
21
+ "unsupported",
22
+ "unsupported",
23
+ {
24
+ "past":"{$0}",
25
+ "present":"{$1}",
26
+ "future":"{$2}"
27
+ }
28
+ ],
29
+ "rules":{
30
+ "future":{
31
+ "keyword":"future",
32
+ "description":"{token} is in the past",
33
+ "conditions":"(< @date (today))",
34
+ "conditions_expression":[
35
+ "<",
36
+ "@date",
37
+ [
38
+ "today"
39
+ ]
40
+ ]
41
+ },
42
+ "past":{
43
+ "keyword":"past",
44
+ "description":"{token} is in the future",
45
+ "conditions":"(> @date (today))",
46
+ "conditions_expression":[
47
+ ">",
48
+ "@date",
49
+ [
50
+ "today"
51
+ ]
52
+ ]
53
+ },
54
+ "present":{
55
+ "keyword":"present",
56
+ "description":"{token} is in the present",
57
+ "conditions":"(= @date (today))",
58
+ "conditions_expression":[
59
+ "=",
60
+ "@date",
61
+ [
62
+ "today"
63
+ ]
64
+ ]
65
+ }
66
+ }
67
+ },
68
+ "gender":{
69
+ "keyword":"gender",
70
+ "keys":[
71
+ "male",
72
+ "female",
73
+ "unknown"
74
+ ],
75
+ "default_key":"other",
76
+ "token_expression":"/.*(user|translator|profile|actor|target)(\\d)*$/",
77
+ "variables":[
78
+ "@gender"
79
+ ],
80
+ "token_mapping":[
81
+ {
82
+ "other":"{$0}"
83
+ },
84
+ {
85
+ "male":"{$0}",
86
+ "female":"{$1}",
87
+ "other":"{$0}/{$1}"
88
+ },
89
+ {
90
+ "male":"{$0}",
91
+ "female":"{$1}",
92
+ "other":"{$2}"
93
+ }
94
+ ],
95
+ "rules":{
96
+ "female":{
97
+ "keyword":"female",
98
+ "description":"{token} is a female",
99
+ "conditions":"(= 'female' @gender)",
100
+ "conditions_expression":[
101
+ "=",
102
+ "female",
103
+ "@gender"
104
+ ]
105
+ },
106
+ "male":{
107
+ "keyword":"male",
108
+ "description":"{token} is a male",
109
+ "conditions":"(= 'male' @gender)",
110
+ "conditions_expression":[
111
+ "=",
112
+ "male",
113
+ "@gender"
114
+ ]
115
+ },
116
+ "other":{
117
+ "keyword":"other",
118
+ "description":"{token}'s gender is unknown"
119
+ }
120
+ }
121
+ },
122
+ "genders":{
123
+ "keyword":"genders",
124
+ "keys":[
125
+ "male",
126
+ "female",
127
+ "unknown",
128
+ "other"
129
+ ],
130
+ "default_key":"other",
131
+ "token_expression":"/.*(users|profiles|actors|targets)(\\d)*$/",
132
+ "variables":[
133
+ "@genders"
134
+ ],
135
+ "token_mapping":[
136
+ "unsupported",
137
+ "unsupported",
138
+ "unsupported",
139
+ {
140
+ "male":"{$0}",
141
+ "female":"{$1}",
142
+ "unknown":"{$2}",
143
+ "other":"{$3}"
144
+ }
145
+ ],
146
+ "rules":{
147
+ "female":{
148
+ "keyword":"female",
149
+ "description":"{token} contains 1 female",
150
+ "conditions":"(&& (= 1 (count @genders)) (all @genders 'female'))",
151
+ "conditions_expression":[
152
+ "&&",
153
+ [
154
+ "=",
155
+ 1,
156
+ [
157
+ "count",
158
+ "@genders"
159
+ ]
160
+ ],
161
+ [
162
+ "all",
163
+ "@genders",
164
+ "female"
165
+ ]
166
+ ]
167
+ },
168
+ "male":{
169
+ "keyword":"male",
170
+ "description":"{token} contains 1 male",
171
+ "conditions":"(&& (= 1 (count @genders)) (all @genders 'male'))",
172
+ "conditions_expression":[
173
+ "&&",
174
+ [
175
+ "=",
176
+ 1,
177
+ [
178
+ "count",
179
+ "@genders"
180
+ ]
181
+ ],
182
+ [
183
+ "all",
184
+ "@genders",
185
+ "male"
186
+ ]
187
+ ]
188
+ },
189
+ "other":{
190
+ "keyword":"other",
191
+ "description":"{token} contains at least 2 people"
192
+ },
193
+ "unknown":{
194
+ "keyword":"unknown",
195
+ "description":"{token} contains 1 person with unknown gender",
196
+ "conditions":"(&& (= 1 (count @genders)) (all @genders 'unknown'))",
197
+ "conditions_expression":[
198
+ "&&",
199
+ [
200
+ "=",
201
+ 1,
202
+ [
203
+ "count",
204
+ "@genders"
205
+ ]
206
+ ],
207
+ [
208
+ "all",
209
+ "@genders",
210
+ "unknown"
211
+ ]
212
+ ]
213
+ }
214
+ }
215
+ },
216
+ "list":{
217
+ "keyword":"list",
218
+ "keys":[
219
+ "one",
220
+ "other"
221
+ ],
222
+ "default_key":"other",
223
+ "token_expression":"/.*(items|list)(\\d)*$/",
224
+ "variables":[
225
+ "@count"
226
+ ],
227
+ "token_mapping":[
228
+ "unsupported",
229
+ {
230
+ "one":"{$0}",
231
+ "other":"{$1}"
232
+ }
233
+ ],
234
+ "rules":{
235
+ "one":{
236
+ "keyword":"one",
237
+ "description":"{token} contains 1 element",
238
+ "conditions":"(= 1 @count)",
239
+ "conditions_expression":[
240
+ "=",
241
+ 1,
242
+ "@count"
243
+ ]
244
+ },
245
+ "other":{
246
+ "keyword":"other",
247
+ "description":"{token} contains at least 2 elements"
248
+ }
249
+ }
250
+ },
251
+ "number":{
252
+ "keyword":"number",
253
+ "keys":[
254
+ "one",
255
+ "other"
256
+ ],
257
+ "default_key":"other",
258
+ "token_expression":"/.*(count|num|minutes|seconds|hours|sum|total)(\\d)*$/",
259
+ "variables":[
260
+ "@n"
261
+ ],
262
+ "token_mapping":[
263
+ "unsupported",
264
+ {
265
+ "one":"{$0}",
266
+ "other":"{$1}"
267
+ }
268
+ ],
269
+ "rules":{
270
+ "one":{
271
+ "keyword":"one",
272
+ "description":"{n} is 1",
273
+ "examples":"1",
274
+ "conditions":"(= @n 1)",
275
+ "conditions_expression":[
276
+ "=",
277
+ "@n",
278
+ 1
279
+ ]
280
+ },
281
+ "other":{
282
+ "keyword":"other",
283
+ "examples":"0, 2-999; 1.2, 2.07..."
284
+ }
285
+ }
286
+ }
287
+ },
288
+ "cases":{
289
+
290
+ }
291
+ }