tr8n_core 4.0.7 → 4.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,615 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Tr8n::Language do
6
- describe "#initialize" do
7
- it "sets language attributes" do
8
- @russian = Tr8n::Language.new(load_json('languages/ru.json'))
9
- expect(@russian.locale).to eq('ru')
10
- expect(@russian.full_name).to eq("Russian - Русский")
11
- expect(@russian.dir).to eq("ltr")
12
-
13
- expect(@russian.align("left")).to eq("left")
14
-
15
- expect(@russian.current_source(:source => "custom")).to eq("custom")
16
- expect(@russian.current_source({})).to eq("undefined")
17
-
18
- expect(@russian.class.cache_key("ru")).to eq("l@_[ru]")
19
- expect(@russian.class.cache_prefix).to eq("l@")
20
-
21
- expect(@russian.has_definition?).to be_truthy
22
-
23
- end
24
- end
25
-
26
-
27
- describe "testing translations" do
28
- before do
29
- Tr8n.session.current_translator = nil
30
-
31
- @app = init_application
32
- @english = @app.language('en-US')
33
- @russian = @app.language('ru')
34
- end
35
-
36
- describe "basic translations" do
37
- it "should return correct translations" do
38
- Tr8n.session.with_block_options(:dry => true) do
39
- load_translation_key_from_hash(@app, {
40
- "label" => "Hello World",
41
- "translations" => {
42
- "ru" => [
43
- {
44
- "label"=> "Привет Мир"
45
- }
46
- ]
47
- }
48
- })
49
-
50
- expect(@english.translate('Hello World')).to eq("Hello World")
51
- expect(@russian.translate('Hello World')).to eq("Привет Мир")
52
-
53
- load_translation_key_from_array(@app, [{
54
- "label" => "Invite",
55
- "description" => "An invitation",
56
- "translations" => {
57
- "ru" => [
58
- {
59
- "label"=> "Приглашение"
60
- }
61
- ]
62
- }
63
- }, {
64
- "label" => "Invite",
65
- "description" => "An action to invite",
66
- "translations" => {
67
- "ru" => [
68
- {
69
- "label"=> "Приглашать"
70
- }
71
- ]
72
- }
73
- }])
74
-
75
- expect(@english.translate('Invite', 'An invitation')).to eq("Invite")
76
- expect(@english.translate('Invite', 'An action to invite')).to eq("Invite")
77
- expect(@russian.translate('Invite', 'An invitation')).to eq("Приглашение")
78
- expect(@russian.translate('Invite', 'An action to invite')).to eq("Приглашать")
79
- end
80
- end
81
- end
82
-
83
- describe "numeric tokens" do
84
- it "should return correct translations" do
85
- Tr8n.session.with_block_options(:dry => true) do
86
-
87
- expect(@english.translate('You have {count||message}.', :count => 0)).to eq("You have 0 messages.")
88
- expect(@english.translate('You have {count||message}.', :count => 1)).to eq("You have 1 message.")
89
- expect(@english.translate('You have {count||message}.', :count => 5)).to eq("You have 5 messages.")
90
-
91
- load_translation_key_from_hash(@app, {
92
- "label" => "You have {count||message}.",
93
- "translations" => {
94
- "ru" => [
95
- {
96
- "label"=> "У вас есть {count|| one: сообщение, few: сообщения, other: сообщений}."
97
- }
98
- ]
99
- }
100
- })
101
-
102
- expect(@russian.translate('You have {count||message}.', :count => 0)).to eq("У вас есть 0 сообщений.")
103
- expect(@russian.translate('You have {count||message}.', :count => 1)).to eq("У вас есть 1 сообщение.")
104
- expect(@russian.translate('You have {count||message}.', :count => 2)).to eq("У вас есть 2 сообщения.")
105
- expect(@russian.translate('You have {count||message}.', :count => 23)).to eq("У вас есть 23 сообщения.")
106
- expect(@russian.translate('You have {count||message}.', :count => 5)).to eq("У вас есть 5 сообщений.")
107
- expect(@russian.translate('You have {count||message}.', :count => 15)).to eq("У вас есть 15 сообщений.")
108
-
109
-
110
- # Shorter form
111
-
112
- load_translation_key_from_hash(@app, {
113
- "label" => "You have {count||message}.",
114
- "translations" => {
115
- "ru" => [
116
- {
117
- "label"=> "У вас есть {count|| сообщение, сообщения, сообщений}."
118
- }
119
- ]
120
- }
121
- })
122
-
123
- expect(@russian.translate('You have {count||message}.', :count => 0)).to eq("У вас есть 0 сообщений.")
124
- expect(@russian.translate('You have {count||message}.', :count => 1)).to eq("У вас есть 1 сообщение.")
125
- expect(@russian.translate('You have {count||message}.', :count => 2)).to eq("У вас есть 2 сообщения.")
126
- expect(@russian.translate('You have {count||message}.', :count => 23)).to eq("У вас есть 23 сообщения.")
127
- expect(@russian.translate('You have {count||message}.', :count => 5)).to eq("У вас есть 5 сообщений.")
128
- expect(@russian.translate('You have {count||message}.', :count => 15)).to eq("У вас есть 15 сообщений.")
129
-
130
- # Alternative form
131
-
132
- load_translation_key_from_hash(@app, {
133
- "label" => "You have {count||message}.",
134
- "translations" => {
135
- "ru" => [
136
- {
137
- "label"=> "У вас есть {count} сообщение.",
138
- "context"=> {
139
- "count"=> { "number" => "one"}
140
- }
141
- },
142
- {
143
- "label"=> "У вас есть {count} сообщения.",
144
- "context"=> {
145
- "count"=> { "number" => "few"}
146
- }
147
- },
148
- {
149
- "label"=> "У вас есть {count} сообщений.",
150
- "context"=> {
151
- "count"=> { "number" => "many"}
152
- }
153
- }
154
- ]
155
- }
156
- })
157
-
158
- expect(@russian.translate('You have {count||message}.', :count => 0)).to eq("У вас есть 0 сообщений.")
159
- expect(@russian.translate('You have {count||message}.', :count => 1)).to eq("У вас есть 1 сообщение.")
160
- expect(@russian.translate('You have {count||message}.', :count => 2)).to eq("У вас есть 2 сообщения.")
161
- expect(@russian.translate('You have {count||message}.', :count => 23)).to eq("У вас есть 23 сообщения.")
162
- expect(@russian.translate('You have {count||message}.', :count => 5)).to eq("У вас есть 5 сообщений.")
163
- expect(@russian.translate('You have {count||message}.', :count => 15)).to eq("У вас есть 15 сообщений.")
164
-
165
- end
166
- end
167
- end
168
-
169
- describe "gender tokens" do
170
- it "should return correct translations" do
171
- Tr8n.session.with_block_options(:dry => true) do
172
-
173
- female = {:gender => :female, :name => "Anna"}
174
- male = {:gender => :male, :name => "Michael"}
175
-
176
- expect(@english.translate('{user} updated {user| male: his, female: her} profile.', :user => {:object => female, :attribute => :name})).to eq("Anna updated her profile.")
177
- expect(@english.translate('{user} updated {user| his, her} profile.', :user => {:object => female, :attribute => :name})).to eq("Anna updated her profile.")
178
-
179
- expect(@english.translate('{user} updated {user| male: his, female: her} profile.', :user => {:object => male, :attribute => :name})).to eq("Michael updated his profile.")
180
- expect(@english.translate('{user} updated {user| his, her} profile.', :user => {:object => male, :attribute => :name})).to eq("Michael updated his profile.")
181
-
182
- load_translation_key_from_hash(@app, {
183
- "label" => "{user} updated {user| his, her} profile.",
184
- "translations" => {
185
- "ru" => [
186
- {
187
- "label"=> "{user|| male: обновил, female: обновила} свой профиль."
188
- }
189
- ]
190
- }
191
- })
192
-
193
- expect(@russian.translate('{user} updated {user| his, her} profile.', :user => {:object => female, :attribute => :name})).to eq("Anna обновила свой профиль.")
194
- expect(@russian.translate('{user} updated {user| his, her} profile.', :user => {:object => male, :attribute => :name})).to eq("Michael обновил свой профиль.")
195
-
196
- load_translation_key_from_hash(@app, {
197
- "label" => "{user} updated {user| his, her} profile.",
198
- "translations" => {
199
- "ru" => [
200
- {
201
- "label"=> "{user|| обновил, обновила} свой профиль."
202
- }
203
- ]
204
- }
205
- })
206
-
207
- expect(@russian.translate('{user} updated {user| his, her} profile.', :user => {:object => female, :attribute => :name})).to eq("Anna обновила свой профиль.")
208
- expect(@russian.translate('{user} updated {user| his, her} profile.', :user => {:object => male, :attribute => :name})).to eq("Michael обновил свой профиль.")
209
- end
210
- end
211
- end
212
-
213
- describe "gender tokens with language cases" do
214
- it "should return correct translations" do
215
- Tr8n.session.with_block_options(:dry => true) do
216
-
217
- female = {:gender => :female, :name => "Anna"}
218
- male = {:gender => :male, :name => "Michael"}
219
-
220
- expect(@english.translate('You like {user::pos} post.', :user => {:object => male, :attribute => :name})).to eq("You like Michael's post.")
221
-
222
- expect(@english.translate('{actor} liked {target::pos} post.', :actor => {:object => female, :attribute => :name}, :target => {:object => male, :attribute => :name})).to eq("Anna liked Michael's post.")
223
-
224
- female = {:gender => :female, :name => "Анна"}
225
- male = {:gender => :male, :name => "Михаил"}
226
-
227
-
228
- load_translation_key_from_hash(@app, {
229
- "label" => "{actor} liked {target::pos} post.",
230
- "translations" => {
231
- "ru" => [
232
- {
233
- "label"=> "{actor::dat} понравилось сообщение {target::gen}."
234
- }
235
- ]
236
- }
237
- })
238
-
239
- expect(@russian.translate('{actor} liked {target::pos} post.', :actor => {:object => female, :attribute => :name}, :target => {:object => male, :attribute => :name})).to eq("Анне понравилось сообщение Михаила.")
240
- expect(@russian.translate('{actor} liked {target::pos} post.', :actor => {:object => male, :attribute => :name}, :target => {:object => female, :attribute => :name})).to eq("Михаилу понравилось сообщение Анны.")
241
-
242
- end
243
- end
244
- end
245
-
246
- describe "decoration tokens" do
247
- it "should return correct translations" do
248
- Tr8n.session.with_block_options(:dry => true) do
249
-
250
- expect(@english.translate("[bold: This text] should be bold", :bold => lambda{|text| "<strong>#{text}</strong>"})).to eq("<strong>This text</strong> should be bold")
251
-
252
- load_translation_key_from_hash(@app, {
253
- "label" => "[bold: This text] should be bold",
254
- "translations" => {
255
- "ru" => [
256
- {
257
- "label"=> "[bold: Этот текст] должны быть жирным"
258
- }
259
- ]
260
- }
261
- })
262
-
263
- expect(@russian.translate("[bold: This text] should be bold", :bold => lambda{|text| "<strong>#{text}</strong>"})).to eq("<strong>Этот текст</strong> должны быть жирным")
264
-
265
- end
266
- end
267
- end
268
-
269
- describe "nested decoration tokens" do
270
- it "should return correct translations" do
271
- Tr8n.session.with_block_options(:dry => true) do
272
-
273
- expect(@english.translate("[bold: Bold text [italic: with italic text]] together", :bold => "<b>{$0}</b>", :italic => "<i>{$0}</i>")).to eq("<b>Bold text <i>with italic text</i></b> together")
274
-
275
- load_translation_key_from_hash(@app, {
276
- "label" => "[bold: Bold text [italic: with italic text]] together",
277
- "translations" => {
278
- "ru" => [
279
- {
280
- "label"=> "[bold: Жирный текст [italic: с курсив]] вместе"
281
- }
282
- ]
283
- }
284
- })
285
-
286
- expect(@russian.translate("[bold: Bold text [italic: with italic text]] together", :bold => "<b>{$0}</b>", :italic => "<i>{$0}</i>")).to eq("<b>Жирный текст <i>с курсив</i></b> вместе")
287
-
288
- end
289
- end
290
- end
291
-
292
-
293
- describe "nested decoration tokens with data tokens" do
294
- it "should return correct translations" do
295
- Tr8n.session.with_block_options(:dry => true) do
296
-
297
- user = {:gender => :male, :name => "Michael"}
298
-
299
- expect(@english.translate("[bold: {user}] received [link: [bold: {count}] {count|message}]", :user => {:object => user, :attribute => :name}, :bold => "<b>{$0}</b>", :count => 1, :link => "<a href='url'>{$0}</a>")).to eq("<b>Michael</b> received <a href='url'><b>1</b> message</a>")
300
- expect(@english.translate("[bold: {user}] received [link: [bold: {count}] {count|message}]", :user => {:object => user, :attribute => :name}, :bold => "<b>{$0}</b>", :count => 5, :link => "<a href='url'>{$0}</a>")).to eq("<b>Michael</b> received <a href='url'><b>5</b> messages</a>")
301
-
302
- load_translation_key_from_hash(@app, {
303
- "label" => "[bold: {user}] received [link: [bold: {count}] {count|message}]",
304
- "translations" => {
305
- "ru" => [
306
- {
307
- "label"=> "[bold: {user}] {user| получил, получила} <a href='url'><b>{count}</b> {count| сообщение, сообщения, сообщений}</a>"
308
- }
309
- ]
310
- }
311
- })
312
-
313
- expect(@russian.translate("[bold: {user}] received [link: [bold: {count}] {count|message}]", :user => {:object => user, :attribute => :name}, :bold => "<b>{$0}</b>", :count => 1, :link => "<a href='url'>{$0}</a>")).to eq("<b>Michael</b> получил <a href='url'><b>1</b> сообщение</a>")
314
- expect(@russian.translate("[bold: {user}] received [link: [bold: {count}] {count|message}]", :user => {:object => user, :attribute => :name}, :bold => "<b>{$0}</b>", :count => 2, :link => "<a href='url'>{$0}</a>")).to eq("<b>Michael</b> получил <a href='url'><b>2</b> сообщения</a>")
315
- expect(@russian.translate("[bold: {user}] received [link: [bold: {count}] {count|message}]", :user => {:object => user, :attribute => :name}, :bold => "<b>{$0}</b>", :count => 5, :link => "<a href='url'>{$0}</a>")).to eq("<b>Michael</b> получил <a href='url'><b>5</b> сообщений</a>")
316
-
317
- user = {:gender => :female, :name => "Anna"}
318
-
319
- expect(@russian.translate("[bold: {user}] received [link: [bold: {count}] {count|message}]", :user => {:object => user, :attribute => :name}, :bold => "<b>{$0}</b>", :count => 1, :link => "<a href='url'>{$0}</a>")).to eq("<b>Anna</b> получила <a href='url'><b>1</b> сообщение</a>")
320
- expect(@russian.translate("[bold: {user}] received [link: [bold: {count}] {count|message}]", :user => {:object => user, :attribute => :name}, :bold => "<b>{$0}</b>", :count => 2, :link => "<a href='url'>{$0}</a>")).to eq("<b>Anna</b> получила <a href='url'><b>2</b> сообщения</a>")
321
- expect(@russian.translate("[bold: {user}] received [link: [bold: {count}] {count|message}]", :user => {:object => user, :attribute => :name}, :bold => "<b>{$0}</b>", :count => 5, :link => "<a href='url'>{$0}</a>")).to eq("<b>Anna</b> получила <a href='url'><b>5</b> сообщений</a>")
322
-
323
- end
324
- end
325
- end
326
-
327
-
328
- describe "date translations" do
329
- it "should return correct translations" do
330
- Tr8n.session.with_block_options(:dry => true) do
331
-
332
- date = Date.new(2011, 01, 01)
333
- expect(@english.translate("This message was received on {date}", :date => date)).to eq("This message was received on 2011-01-01")
334
-
335
- expect(date.translate()).to eq("1/1/2011")
336
- expect(date.tr()).to eq("1/1/2011")
337
- expect(@english.translate("This message was received on {date}", :date => date.tr())).to eq("This message was received on 1/1/2011")
338
-
339
- expect(date.tr(:verbose)).to eq("Saturday, January 1, 2011")
340
- expect(@english.translate("This message was received on {date}", :date => date.tr(:verbose))).to eq("This message was received on Saturday, January 1, 2011")
341
-
342
- Tr8n.config.localization[:custom_date_formats][:short_numeric] = '%m/%d'
343
- expect(@english.translate("This message was received on {date}", :date => date.tr(:short_numeric))).to eq("This message was received on 1/1")
344
- expect(@english.translate("This message was received on {date}", :date => date.tr("%B %d"))).to eq("This message was received on January 1")
345
- expect(@english.translate("This message was received on {date}", :date => date.tr("{month_name} {days::ord}"))).to eq("This message was received on January 1st")
346
-
347
- expect(@english.translate("This message was received on {date}", :date => date.tr("{month_name} {days}"))).to eq("This message was received on January 1")
348
-
349
- load_translation_key_from_array(@app, [{
350
- "label" => "{month_name} {days}",
351
- "translations" => {
352
- "ru" => [
353
- {
354
- "label"=> "{days}ого {month_name::gen}"
355
- }
356
- ]
357
- }
358
- }, {
359
- "label" => "This message was received on {date}",
360
- "translations" => {
361
- "ru" => [
362
- {
363
- "label"=> "Это сообщение было получено {date}"
364
- }
365
- ]
366
- }
367
- }, {
368
- "label" => "January",
369
- "description" => "Month name",
370
- "translations" => {
371
- "ru" => [
372
- {
373
- "label"=> "Январь"
374
- }
375
- ]
376
- }
377
- }])
378
-
379
- expect(@russian.translate("January", "Month name")).to eq("Январь")
380
- expect(@russian.translate(Tr8n.config.default_month_name(0), "Month name")).to eq("Январь")
381
- expect(@russian.translate("This message was received on {date}", :date => date.tr("{month_name} {days}", @russian))).to eq("Это сообщение было получено 1ого Января")
382
- end
383
- end
384
- end
385
-
386
-
387
- describe "time translations" do
388
- it "should return correct translations" do
389
- Tr8n.session.with_block_options(:dry => true) do
390
-
391
- time = Time.new(2014, 01, 02, 11, 12, 13)
392
-
393
- expect(time.translate()).to eq("1/2/2014")
394
- expect(time.tr()).to eq("1/2/2014")
395
- expect(@english.translate("This message was received on {time}", :time => time.tr(:date_time))).to eq("This message was received on 1/2/2014 at 11:12")
396
-
397
- expect(@english.translate("This message was received on {time}", :time => time.tr("{month_name} {days::ord} at {short_hours}:{minutes} {am_pm}"))).to eq("This message was received on January 2nd at 11:12 AM")
398
-
399
- load_translation_key_from_array(@app, [{
400
- "label" => "{month_name} {days::ord} at {short_hours}:{minutes} {am_pm}",
401
- "translations" => {
402
- "ru" => [
403
- {
404
- "label"=> "{days}ого {month_name::gen} в {short_hours}:{minutes} {am_pm}"
405
- }
406
- ]
407
- }
408
- }, {
409
- "label" => "This message was received on {time}",
410
- "translations" => {
411
- "ru" => [
412
- {
413
- "label"=> "Это сообщение было получено {time}"
414
- }
415
- ]
416
- }
417
- }, {
418
- "label" => "January",
419
- "description" => "Month name",
420
- "translations" => {
421
- "ru" => [
422
- {
423
- "label"=> "Январь"
424
- }
425
- ]
426
- }
427
- }, {
428
- "label" => "AM",
429
- "description" => "Meridian indicator",
430
- "translations" => {
431
- "ru" => [
432
- {
433
- "label"=> "бп"
434
- }
435
- ]
436
- }
437
- } , {
438
- "label" => "PM",
439
- "description" => "Meridian indicator",
440
- "translations" => {
441
- "ru" => [
442
- {
443
- "label"=> "пп"
444
- }
445
- ]
446
- }
447
- }])
448
-
449
- expect(@russian.translate("This message was received on {time}", :time => time.tr("{month_name} {days::ord} at {short_hours}:{minutes} {am_pm}", @russian))).to eq("Это сообщение было получено 2ого Января в 11:12 бп")
450
- end
451
- end
452
- end
453
-
454
-
455
- end
456
-
457
-
458
- describe "#translation" do
459
- #before do
460
- # @@app = init_application
461
- # @@english = @app.language('en-US')
462
- # @@russian = @app.language('ru')
463
- #end
464
- #
465
- #it "translates with fallback to English" do
466
- # Tr8n.session.with_block_options(:dry => true) do
467
- # #expect(@@russian.translate("{count||message}", {:count => 1})).to eq("1 message")
468
- # #expect(@@russian.translate("{count||message}", {:count => 5})).to eq("5 messages")
469
- # #expect(@@russian.translate("{count||message}", {:count => 0})).to eq("0 messages")
470
- # end
471
- #end
472
-
473
- # it "translates basic phrases to Russian" do
474
- # load_translation_keys_from_file(@app, 'translations/ru/basic.json')
475
- # Tr8n.config.with_block_options(:dry => true) do
476
- # expect(@@russian.translate("Hello World")).to eq("Привет Мир")
477
- # expect(@@russian.translate("Hello World", "Wrong context")).to eq("Hello World")
478
- # expect(@@russian.translate("Hello World", "Greeting context")).to eq("Привет Мир")
479
- # expect(@@russian.translate("Hello world")).to eq("Hello world")
480
- # expect(@@russian.translate("Hello {user}", nil, :user => "Михаил")).to eq("Привет Михаил")
481
- # end
482
- # end
483
- #
484
- # it "translates basic phrases with data tokens to Russian" do
485
- # load_translation_keys_from_file(@app, 'translations/ru/basic.json')
486
- # Tr8n.config.with_block_options(:dry => true) do
487
- # expect(@@russian.translate("Hello {user}", nil, :user => "Михаил")).to eq("Привет Михаил")
488
- # end
489
- # end
490
- #
491
- # it "uses default data tokens" do
492
- # Tr8n.config.with_block_options(:dry => true) do
493
- # expect(@english.translate("He said: {quot}Hello{quot}", nil)).to eq("He said: &quot;Hello&quot;")
494
- # expect(@english.translate("Code sample: {lbrace}a:'b'{rbrace}", nil)).to eq("Code sample: {a:'b'}")
495
- # end
496
- # end
497
- #
498
- # it "uses basic decoration tokens" do
499
- # Tr8n.config.with_block_options(:dry => true) do
500
- # expect(@english.translate("Hello [decor: World]", nil, :decor => lambda{|text| "''#{text}''"})).to eq("Hello ''World''")
501
- # end
502
- # end
503
- #
504
- # it "uses default decoration tokens" do
505
- # load_translation_keys_from_file(@app, 'translations/ru/basic.json')
506
- # Tr8n.config.with_block_options(:dry => true) do
507
- # expect(@english.translate("Hello [i: World]")).to eq("Hello <i>World</i>")
508
- # expect(@@russian.translate("Hello [i: World]")).to eq("Привет <i>Мир</i>")
509
- # end
510
- # end
511
- #
512
- # it "uses mixed tokens" do
513
- # load_translation_keys_from_file(@app, 'translations/ru/basic.json')
514
- # Tr8n.config.with_block_options(:dry => true) do
515
- # expect(@english.translate("Hello [i: {user}]", nil, :user => "Michael")).to eq("Hello <i>Michael</i>")
516
- # expect(@@russian.translate("Hello [i: {user}]", nil, :user => "Michael")).to eq("Привет <i>Michael</i>")
517
- # end
518
- # end
519
- #
520
- # it "uses method tokens" do
521
- # load_translation_keys_from_file(@app, 'translations/ru/basic.json')
522
- # Tr8n.config.with_block_options(:dry => true) do
523
- # expect(@@russian.translate("Hello {user.first_name} [i: {user.last_name}]", nil,
524
- # :user => stub_object({:first_name => "Tom", :last_name => "Anderson"}))).to eq("Привет Tom <i>Anderson</i>")
525
- # end
526
- # end
527
- #
528
- # it "translates phrases with numeric rules to Russian" do
529
- # load_translation_keys_from_file(@app, 'translations/ru/counters.json')
530
- # trn = @@russian.translate("{count||message}", nil, {:count => 1})
531
- # expect(trn).to eq("1 сообщение")
532
- # trn = @@russian.translate("{count||message}", nil, {:count => 2})
533
- # expect(trn).to eq("2 сообщения")
534
- # trn = @@russian.translate("{count||message}", nil, {:count => 5})
535
- # expect(trn).to eq("5 сообщений")
536
- # trn = @@russian.translate("{count||message}", nil, {:count => 15})
537
- # expect(trn).to eq("15 сообщений")
538
- # end
539
- #
540
- # it "translates phrases with gender rules to Russian" do
541
- # #load_translation_key_from_hash(@app, {
542
- # # "label" => "{actor} sent {target} a gift.",
543
- # # "translations" => {
544
- # # "ru" => [
545
- # # {
546
- # # "label"=> "{actor} послал подарок {target::dat}.",
547
- # # "locale"=> "ru",
548
- # # "context"=> {
549
- # # "actor"=> [{ "type"=> "gender", "key"=> "male"}]
550
- # # }
551
- # # },
552
- # # {
553
- # # "label"=> "{actor} послала подарок {target::dat}.",
554
- # # "locale"=> "ru",
555
- # # "context"=> {
556
- # # "actor"=> [{ "type"=> "gender", "key"=> "female"}]
557
- # # },
558
- # # },
559
- # # {
560
- # # "label"=> "{actor} послал/а подарок {target::dat}.",
561
- # # "locale"=> "ru",
562
- # # "context"=> {
563
- # # "actor"=> [{ "type"=> "gender", "key"=> "unknown"}]
564
- # # },
565
- # # }
566
- # # ]
567
- # # }
568
- # #});
569
- #
570
- # load_translation_keys_from_file(@app, "translations/ru/genders.json")
571
- #
572
- # actor = {'gender' => 'female', 'name' => 'Таня'}
573
- # target = {'gender' => 'male', 'name' => 'Михаил'}
574
- #
575
- # Tr8n.config.with_block_options(:dry => true) do
576
- # expect(@@russian.translate(
577
- # '{actor} sent {target} a gift.', nil,
578
- # :actor => {:object => actor, :attribute => 'name'},
579
- # :target => {:object => target, :attribute => 'name'})
580
- # ).to eq("Таня послала подарок Михаилу.")
581
- #
582
- # expect(@@russian.translate(
583
- # '{actor} sent {target} a gift.', nil,
584
- # :actor => {:object => target, :attribute => 'name'},
585
- # :target => {:object => actor, :attribute => 'name'})
586
- # ).to eq("Михаил послал подарок Тане.")
587
- #
588
- # expect(@@russian.translate(
589
- # '{actor} loves {target}.', nil,
590
- # :actor => {:object => actor, :attribute => 'name'},
591
- # :target => {:object => target, :attribute => 'name'})
592
- # ).to eq("Таня любит Михаила.")
593
- #
594
- # expect(@@russian.translate(
595
- # '{actor} saw {target} {count||day} ago.', nil,
596
- # :actor => {:object => actor, :attribute => 'name'},
597
- # :target => {:object => target, :attribute => 'name'},
598
- # :count => 2)
599
- # ).to eq("Таня видела Михаила 2 дня назад.")
600
- #
601
- # expect(@@russian.translate(
602
- # '{actor} saw {target} {count||day} ago.', nil,
603
- # :actor => {:object => target, :attribute => 'name'},
604
- # :target => {:object => actor, :attribute => 'name'},
605
- # :count => 2)
606
- # ).to eq("Михаил видел Таню 2 дня назад.")
607
- #
608
- # end
609
- #
610
- # # trn = @@russian.translate("{count||message}", nil, {:count => 1})
611
- # # expect(trn).to eq("1 сообщение")
612
- # end
613
- #
614
- end
615
- end
data/spec/logger_spec.rb DELETED
@@ -1,15 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Tr8n::Logger do
6
- it "must provide correct data" do
7
- Tr8n.logger.trace_api_call("/test", {}) do
8
- # do nothing
9
- end
10
-
11
- Tr8n.logger.trace("Testing code") do
12
- # do nothing
13
- end
14
- end
15
- end