tr8n_core 4.0.7 → 4.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/lib/tr8n/api_client.rb +28 -18
  4. data/lib/tr8n/application.rb +37 -64
  5. data/lib/tr8n/cache.rb +8 -41
  6. data/lib/tr8n/cache_adapters/file.rb +1 -2
  7. data/lib/tr8n/cache_adapters/memcache.rb +2 -2
  8. data/lib/tr8n/cache_adapters/redis.rb +2 -2
  9. data/lib/tr8n/config.rb +48 -13
  10. data/lib/tr8n/decorators/html.rb +3 -10
  11. data/lib/tr8n/language.rb +25 -112
  12. data/lib/tr8n/language_case.rb +1 -1
  13. data/lib/tr8n/session.rb +2 -9
  14. data/lib/tr8n/source.rb +12 -44
  15. data/lib/tr8n/{tokens/data_tokenizer.rb → tokenizers/data.rb} +4 -3
  16. data/lib/tr8n/{tokens/decoration_tokenizer.rb → tokenizers/decoration.rb} +6 -5
  17. data/lib/tr8n/tokenizers/dom.rb +346 -0
  18. data/lib/tr8n/tokens/data.rb +15 -22
  19. data/lib/tr8n/tokens/transform.rb +24 -12
  20. data/lib/tr8n/translation_key.rb +6 -29
  21. data/lib/tr8n/utils.rb +5 -0
  22. data/lib/tr8n_core/version.rb +1 -1
  23. data/lib/tr8n_core.rb +7 -26
  24. metadata +30 -100
  25. data/lib/tr8n/cache_adapters/cdb.rb +0 -87
  26. data/lib/tr8n/tokens/hidden.rb +0 -57
  27. data/spec/application_spec.rb +0 -52
  28. data/spec/base_spec.rb +0 -19
  29. data/spec/cache/adapters/file_spec.rb +0 -32
  30. data/spec/cache/adapters/memcache_spec.rb +0 -15
  31. data/spec/cache/generators/file_generator_spec.rb +0 -30
  32. data/spec/config_spec.rb +0 -32
  33. data/spec/decorator_spec.rb +0 -12
  34. data/spec/decorators/base_spec.rb +0 -14
  35. data/spec/decorators/default_spec.rb +0 -12
  36. data/spec/decorators/html_spec.rb +0 -50
  37. data/spec/ext/array_spec.rb +0 -12
  38. data/spec/ext/hash_spec.rb +0 -15
  39. data/spec/ext/string_spec.rb +0 -10
  40. data/spec/fixtures/application.json +0 -112
  41. data/spec/fixtures/languages/en-US.json +0 -1424
  42. data/spec/fixtures/languages/es.json +0 -291
  43. data/spec/fixtures/languages/ru.json +0 -582
  44. data/spec/fixtures/translations/ru/basic.json +0 -56
  45. data/spec/fixtures/translations/ru/counters.json +0 -43
  46. data/spec/fixtures/translations/ru/genders.json +0 -171
  47. data/spec/fixtures/translations/ru/last_names.txt +0 -200
  48. data/spec/fixtures/translations/ru/names.json +0 -1
  49. data/spec/fixtures/translations/ru/names.txt +0 -458
  50. data/spec/language_case_rule_spec.rb +0 -57
  51. data/spec/language_case_spec.rb +0 -58
  52. data/spec/language_context_rule_spec.rb +0 -75
  53. data/spec/language_context_spec.rb +0 -333
  54. data/spec/language_spec.rb +0 -615
  55. data/spec/logger_spec.rb +0 -15
  56. data/spec/rules_engine/evaluator_spec.rb +0 -150
  57. data/spec/rules_engine/parser_spec.rb +0 -31
  58. data/spec/source_spec.rb +0 -13
  59. data/spec/spec_helper.rb +0 -101
  60. data/spec/tokens/data_spec.rb +0 -114
  61. data/spec/tokens/data_tokenizer_spec.rb +0 -29
  62. data/spec/tokens/decoration_tokenizer_spec.rb +0 -81
  63. data/spec/tokens/hidden_spec.rb +0 -24
  64. data/spec/tokens/method_spec.rb +0 -84
  65. data/spec/tokens/transform_spec.rb +0 -50
  66. data/spec/translation_key_spec.rb +0 -96
  67. data/spec/translation_spec.rb +0 -24
  68. data/spec/utils_spec.rb +0 -62
@@ -1,582 +0,0 @@
1
- {
2
- "locale":"ru",
3
- "name":"Русский",
4
- "english_name":"Russian",
5
- "native_name":"Русский",
6
- "flag_url":"http://localhost:3000/media/54/39/11/49/cb768f030bde97f97.png",
7
- "curse_words":"блядь",
8
- "contexts":{
9
- "date":{
10
- "keyword":"date",
11
- "keys":[
12
- "past",
13
- "present",
14
- "future"
15
- ],
16
- "default_key":"present",
17
- "token_expression":"/.*(date|time)(\\d)*$/",
18
- "variables":[
19
- "@date"
20
- ],
21
- "token_mapping":[
22
- "unsupported",
23
- "unsupported",
24
- {
25
- "past":"{$0}",
26
- "present":"{$1}",
27
- "future":"{$2}"
28
- }
29
- ],
30
- "rules":{
31
- "future":{
32
- "keyword":"future",
33
- "description":"{token} is in the past",
34
- "conditions":"(< @date (today))",
35
- "conditions_expression":[
36
- "<",
37
- "@date",
38
- [
39
- "today"
40
- ]
41
- ]
42
- },
43
- "past":{
44
- "keyword":"past",
45
- "description":"{token} is in the future",
46
- "conditions":"(> @date (today))",
47
- "conditions_expression":[
48
- ">",
49
- "@date",
50
- [
51
- "today"
52
- ]
53
- ]
54
- },
55
- "present":{
56
- "keyword":"present",
57
- "description":"{token} is in the present",
58
- "conditions":"(= @date (today))",
59
- "conditions_expression":[
60
- "=",
61
- "@date",
62
- [
63
- "today"
64
- ]
65
- ]
66
- }
67
- }
68
- },
69
- "gender":{
70
- "keyword":"gender",
71
- "keys":[
72
- "male",
73
- "female",
74
- "other"
75
- ],
76
- "default_key":"other",
77
- "token_expression":"/.*(user|translator|profile|actor|target)(\\d)*$/",
78
- "variables":[
79
- "@gender"
80
- ],
81
- "token_mapping":[
82
- {
83
- "other":"{$0}"
84
- },
85
- {
86
- "male":"{$0}",
87
- "female":"{$1}",
88
- "other":"{$0}/{$1}"
89
- },
90
- {
91
- "male":"{$0}",
92
- "female":"{$1}",
93
- "other":"{$2}"
94
- }
95
- ],
96
- "rules":{
97
- "female":{
98
- "keyword":"female",
99
- "description":"{token} is a female",
100
- "conditions":"(= 'female' @gender)",
101
- "conditions_expression":[
102
- "=",
103
- "female",
104
- "@gender"
105
- ]
106
- },
107
- "male":{
108
- "keyword":"male",
109
- "description":"{token} is a male",
110
- "conditions":"(= 'male' @gender)",
111
- "conditions_expression":[
112
- "=",
113
- "male",
114
- "@gender"
115
- ]
116
- },
117
- "other":{
118
- "keyword":"other",
119
- "description":"{token}'s gender is unknown"
120
- }
121
- }
122
- },
123
- "genders":{
124
- "keyword":"genders",
125
- "keys":[
126
- "male",
127
- "female",
128
- "unknown",
129
- "other"
130
- ],
131
- "default_key":"other",
132
- "token_expression":"/.*(users|profiles|actors|targets)(\\d)*$/",
133
- "variables":[
134
- "@genders"
135
- ],
136
- "token_mapping":[
137
- "unsupported",
138
- "unsupported",
139
- "unsupported",
140
- {
141
- "male":"{$0}",
142
- "female":"{$1}",
143
- "unknown":"{$2}",
144
- "other":"{$3}"
145
- }
146
- ],
147
- "rules":{
148
- "female":{
149
- "keyword":"female",
150
- "description":"{token} contains 1 female",
151
- "conditions":"(&& (= 1 (count @genders)) (all @genders 'female'))",
152
- "conditions_expression":[
153
- "&&",
154
- [
155
- "=",
156
- 1,
157
- [
158
- "count",
159
- "@genders"
160
- ]
161
- ],
162
- [
163
- "all",
164
- "@genders",
165
- "female"
166
- ]
167
- ]
168
- },
169
- "male":{
170
- "keyword":"male",
171
- "description":"{token} contains 1 male",
172
- "conditions":"(&& (= 1 (count @genders)) (all @genders 'male'))",
173
- "conditions_expression":[
174
- "&&",
175
- [
176
- "=",
177
- 1,
178
- [
179
- "count",
180
- "@genders"
181
- ]
182
- ],
183
- [
184
- "all",
185
- "@genders",
186
- "male"
187
- ]
188
- ]
189
- },
190
- "other":{
191
- "keyword":"other",
192
- "description":"{token} contains at least 2 people"
193
- },
194
- "unknown":{
195
- "keyword":"unknown",
196
- "description":"{token} contains 1 person with unknown gender",
197
- "conditions":"(&& (= 1 (count @genders)) (all @genders 'unknown'))",
198
- "conditions_expression":[
199
- "&&",
200
- [
201
- "=",
202
- 1,
203
- [
204
- "count",
205
- "@genders"
206
- ]
207
- ],
208
- [
209
- "all",
210
- "@genders",
211
- "unknown"
212
- ]
213
- ]
214
- }
215
- }
216
- },
217
- "list":{
218
- "keyword":"list",
219
- "keys":[
220
- "one",
221
- "other"
222
- ],
223
- "default_key":"other",
224
- "token_expression":"/.*(items|list)(\\d)*$/",
225
- "variables":[
226
- "@count"
227
- ],
228
- "token_mapping":[
229
- "unsupported",
230
- {
231
- "one":"{$0}",
232
- "other":"{$1}"
233
- }
234
- ],
235
- "rules":{
236
- "one":{
237
- "keyword":"one",
238
- "description":"{token} contains 1 element",
239
- "conditions":"(= 1 @count)",
240
- "conditions_expression":[
241
- "=",
242
- 1,
243
- "@count"
244
- ]
245
- },
246
- "other":{
247
- "keyword":"other",
248
- "description":"{token} contains at least 2 elements"
249
- }
250
- }
251
- },
252
- "number":{
253
- "keyword":"number",
254
- "keys":[
255
- "one",
256
- "few",
257
- "many",
258
- "other"
259
- ],
260
- "default_key":"many",
261
- "token_expression":"/.*(count|num|minutes|seconds|hours|sum|total)(\\d)*$/",
262
- "variables":[
263
- "@n"
264
- ],
265
- "token_mapping":[
266
- "unsupported",
267
- "unsupported",
268
- {
269
- "one":"{$0}",
270
- "few":"{$1}",
271
- "many":"{$2}",
272
- "other":"{$2}"
273
- },
274
- {
275
- "one":"{$0}",
276
- "few":"{$1}",
277
- "many":"{$2}",
278
- "other":"{$3}"
279
- }
280
- ],
281
- "rules":{
282
- "few":{
283
- "keyword":"few",
284
- "description":"{token} mod 10 in 2..4 and {token} mod 100 not in 12..14",
285
- "examples":"2-4, 22-24, 32-34...",
286
- "conditions":"(&& (in '2..4' (mod @n 10)) (not (in '12..14' (mod @n 100))))",
287
- "conditions_expression":[
288
- "&&",
289
- [
290
- "in",
291
- "2..4",
292
- [
293
- "mod",
294
- "@n",
295
- 10
296
- ]
297
- ],
298
- [
299
- "not",
300
- [
301
- "in",
302
- "12..14",
303
- [
304
- "mod",
305
- "@n",
306
- 100
307
- ]
308
- ]
309
- ]
310
- ]
311
- },
312
- "many":{
313
- "keyword":"many",
314
- "description":"{token} mod 10 is 0 or {token} mod 10 in 5..9 or {token} mod 100 in 11..14",
315
- "examples":"0, 5-20, 25-30, 35-40...",
316
- "conditions":"(|| (= 0 (mod @n 10)) (in '5..9' (mod @n 10)) (in '11..14' (mod @n 100)))",
317
- "conditions_expression":[
318
- "||",
319
- [
320
- "=",
321
- 0,
322
- [
323
- "mod",
324
- "@n",
325
- 10
326
- ]
327
- ],
328
- [
329
- "in",
330
- "5..9",
331
- [
332
- "mod",
333
- "@n",
334
- 10
335
- ]
336
- ],
337
- [
338
- "in",
339
- "11..14",
340
- [
341
- "mod",
342
- "@n",
343
- 100
344
- ]
345
- ]
346
- ]
347
- },
348
- "one":{
349
- "keyword":"one",
350
- "description":"{token} mod 10 is 1 and {token} mod 100 is not 11",
351
- "examples":"1, 21, 31, 41, 51, 61...",
352
- "conditions":"(&& (= 1 (mod @n 10)) (!= 11 (mod @n 100)))",
353
- "conditions_expression":[
354
- "&&",
355
- [
356
- "=",
357
- 1,
358
- [
359
- "mod",
360
- "@n",
361
- 10
362
- ]
363
- ],
364
- [
365
- "!=",
366
- 11,
367
- [
368
- "mod",
369
- "@n",
370
- 100
371
- ]
372
- ]
373
- ]
374
- },
375
- "other":{
376
- "keyword":"other",
377
- "examples":"1.2, 2.07, 5.94..."
378
- }
379
- }
380
- },
381
- "value":{
382
- "keyword":"value",
383
- "keys":[
384
- "vowel",
385
- "other"
386
- ],
387
- "default_key":"vowel",
388
- "token_expression":"/.*$/",
389
- "variables":[
390
- "@value"
391
- ],
392
- "token_mapping":[
393
- "unsupported",
394
- {
395
- "vowel":"{$0}",
396
- "con":"{$1}"
397
- }
398
- ],
399
- "rules":{
400
- "other":{
401
- "keyword":"other",
402
- "description":"{token} starts with a consonant",
403
- "examples":"б, в, г, д, к..."
404
- },
405
- "vowel":{
406
- "keyword":"vowel",
407
- "description":"{token} starts with a vowel",
408
- "examples":"а, и, о, у, ы, э",
409
- "conditions":[
410
- "match",
411
- "/^[аиоуыэАИОУЭ]/",
412
- "@value"
413
- ],
414
- "conditions_expression":[
415
- "match",
416
- "/^[аиоуыэАИОУЭ]/",
417
- "@value"
418
- ]
419
- }
420
- }
421
- }
422
- },
423
- "cases":{
424
- "acc":{
425
- "id":85,
426
- "keyword":"acc",
427
- "latin_name":"Accusativus",
428
- "native_name":"Винительный падеж",
429
- "description":"Вижу - Кого? Что?",
430
- "application":"words",
431
- "rules":[
432
-
433
- ]
434
- },
435
- "dat":{
436
- "id":86,
437
- "keyword":"dat",
438
- "latin_name":"Dativus",
439
- "native_name":"Дательный падеж",
440
- "description":"Рад - Кому? Чему?",
441
- "application":"words",
442
- "rules":[
443
- {
444
- "id":927,
445
- "description":"If ends in 'л', append 'у'.",
446
- "examples":"Михаил => Михаилу",
447
- "conditions":"(match '/л$/' @value)",
448
- "conditions_expression":[
449
- "match",
450
- "/л$/",
451
- "@value"
452
- ],
453
- "operations":"(append 'у' @value)",
454
- "operations_expression":[
455
- "append",
456
- "у",
457
- "@value"
458
- ]
459
- },
460
- {
461
- "id":926,
462
- "description":"If ends in 'a', replace with 'e'",
463
- "examples":"Анна => Анне",
464
- "conditions":"(match '/а$/' @value)",
465
- "conditions_expression":[
466
- "match",
467
- "/а$/",
468
- "@value"
469
- ],
470
- "operations":"(replace '/а$/' 'е' @value)",
471
- "operations_expression":[
472
- "replace",
473
- "/а$/",
474
- "е",
475
- "@value"
476
- ]
477
- }
478
- ]
479
- },
480
- "gen":{
481
- "id":87,
482
- "keyword":"gen",
483
- "latin_name":"Genitivus",
484
- "native_name":"Родительный падеж",
485
- "description":"Нет - Кого? Чего?",
486
- "application":"words",
487
- "rules":[
488
- {
489
- "id":925,
490
- "conditions":"(match '/[бвгджзклмнпрстфхцчшщ]$/' @value)",
491
- "conditions_expression":[
492
- "match",
493
- "/[бвгджзклмнпрстфхцчшщ]$/",
494
- "@value"
495
- ],
496
- "operations":"(append 'a' @value)",
497
- "operations_expression":[
498
- "append",
499
- "а",
500
- "@value"
501
- ]
502
- },
503
- {
504
- "id":929,
505
- "conditions":"(match '/[а]$/' @value)",
506
- "conditions_expression":[
507
- "match",
508
- "/[а]$/",
509
- "@value"
510
- ],
511
- "operations":"(replace 'a' 'ы' @value)",
512
- "operations_expression":[
513
- "replace",
514
- "а",
515
- "ы",
516
- "@value"
517
- ]
518
- },
519
- {
520
- "id":930,
521
- "conditions":"(match '/[ь]$/' @value)",
522
- "conditions_expression":[
523
- "match",
524
- "/[ь]$/",
525
- "@value"
526
- ],
527
- "operations":"(replace 'ь' 'я' @value)",
528
- "operations_expression":[
529
- "replace",
530
- "ь",
531
- "я",
532
- "@value"
533
- ]
534
- }
535
- ]
536
- },
537
- "ins":{
538
- "id":88,
539
- "keyword":"ins",
540
- "latin_name":"Instrumentalis",
541
- "native_name":"Творительный падеж",
542
- "description":"Доволен - Кем? Чем?",
543
- "application":"words",
544
- "rules":[
545
-
546
- ]
547
- },
548
- "nom":{
549
- "id":89,
550
- "keyword":"nom",
551
- "latin_name":"Nominativus",
552
- "native_name":"Именительный падеж",
553
- "description":"Есть - Кто? Что?",
554
- "application":"words",
555
- "rules":[
556
-
557
- ]
558
- },
559
- "pos":{
560
- "id":90,
561
- "keyword":"pos",
562
- "latin_name":"Possessive",
563
- "native_name":"Притяжательный падеж",
564
- "description":"Чей?",
565
- "application":"words",
566
- "rules":[
567
-
568
- ]
569
- },
570
- "pre":{
571
- "id":91,
572
- "keyword":"pre",
573
- "latin_name":"Prepositivus",
574
- "native_name":"Предложный падеж",
575
- "description":"Думаю - О ком? О чём?",
576
- "application":"words",
577
- "rules":[
578
-
579
- ]
580
- }
581
- }
582
- }
@@ -1,56 +0,0 @@
1
- [{
2
- "label": "Hello World",
3
- "translations": {
4
- "ru": [
5
- {
6
- "label": "Привет Мир"
7
- }
8
- ]
9
- }
10
- }, {
11
- "label": "Hello World",
12
- "description": "Greeting context",
13
- "translations": {
14
- "ru": [
15
- {
16
- "label": "Привет Мир"
17
- }
18
- ]
19
- }
20
- }, {
21
- "label": "Hello [i: World]",
22
- "translations": {
23
- "ru": [
24
- {
25
- "label": "Привет [i: Мир]"
26
- }
27
- ]
28
- }
29
- }, {
30
- "label": "Hello [i: {user}]",
31
- "translations": {
32
- "ru": [
33
- {
34
- "label": "Привет [i: {user}]"
35
- }
36
- ]
37
- }
38
- }, {
39
- "label": "Hello {user.first_name} [i: {user.last_name}]",
40
- "translations": {
41
- "ru": [
42
- {
43
- "label": "Привет {user.first_name} [i: {user.last_name}]"
44
- }
45
- ]
46
- }
47
- }, {
48
- "label": "Hello {user}",
49
- "translations": {
50
- "ru": [
51
- {
52
- "label": "Привет {user}"
53
- }
54
- ]
55
- }
56
- }]
@@ -1,43 +0,0 @@
1
- [{
2
- "label": "{count||message}",
3
- "translations": {
4
- "ru": [
5
- {
6
- "label": "{count} сообщение",
7
- "locale": "ru",
8
- "context": {
9
- "count": [
10
- {
11
- "type": "number",
12
- "key": "one"
13
- }
14
- ]
15
- }
16
- },
17
- {
18
- "label": "{count} сообщения",
19
- "locale": "ru",
20
- "context": {
21
- "count": [
22
- {
23
- "type": "number",
24
- "key": "few"
25
- }
26
- ]
27
- }
28
- },
29
- {
30
- "label": "{count} сообщений",
31
- "locale": "ru",
32
- "context": {
33
- "count": [
34
- {
35
- "type": "number",
36
- "key": "many"
37
- }
38
- ]
39
- }
40
- }
41
- ]
42
- }
43
- }]