tr8n_core 4.0.1 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +163 -33
  3. data/lib/tr8n/application.rb +29 -27
  4. data/lib/tr8n/base.rb +2 -22
  5. data/lib/tr8n/cache.rb +9 -9
  6. data/lib/tr8n/cache_adapters/cdb.rb +2 -2
  7. data/lib/tr8n/cache_adapters/file.rb +2 -2
  8. data/lib/tr8n/cache_adapters/memcache.rb +3 -3
  9. data/lib/tr8n/cache_adapters/redis.rb +3 -3
  10. data/lib/tr8n/component.rb +1 -1
  11. data/lib/tr8n/config.rb +256 -202
  12. data/lib/tr8n/decorators/base.rb +1 -1
  13. data/lib/tr8n/decorators/default.rb +1 -1
  14. data/lib/tr8n/decorators/html.rb +4 -4
  15. data/lib/tr8n/exception.rb +1 -1
  16. data/lib/tr8n/language.rb +17 -27
  17. data/lib/tr8n/language_case.rb +4 -3
  18. data/lib/tr8n/language_case_rule.rb +1 -1
  19. data/lib/tr8n/language_context.rb +4 -2
  20. data/lib/tr8n/language_context_rule.rb +1 -1
  21. data/lib/tr8n/logger.rb +8 -3
  22. data/lib/tr8n/rules_engine/evaluator.rb +4 -7
  23. data/lib/tr8n/rules_engine/parser.rb +1 -28
  24. data/lib/tr8n/session.rb +87 -0
  25. data/lib/tr8n/source.rb +1 -1
  26. data/lib/tr8n/tokens/data.rb +2 -2
  27. data/lib/tr8n/tokens/data_tokenizer.rb +1 -1
  28. data/lib/tr8n/tokens/decoration_tokenizer.rb +1 -1
  29. data/lib/tr8n/tokens/hidden.rb +1 -1
  30. data/lib/tr8n/tokens/method.rb +1 -1
  31. data/lib/tr8n/tokens/transform.rb +2 -2
  32. data/lib/tr8n/translation.rb +2 -2
  33. data/lib/tr8n/translation_key.rb +4 -4
  34. data/lib/tr8n/translator.rb +1 -1
  35. data/lib/tr8n/utils.rb +1 -1
  36. data/lib/tr8n_core/ext/array.rb +4 -4
  37. data/lib/tr8n_core/ext/date.rb +38 -13
  38. data/lib/tr8n_core/ext/fixnum.rb +3 -3
  39. data/lib/tr8n_core/ext/hash.rb +1 -1
  40. data/lib/tr8n_core/ext/string.rb +3 -3
  41. data/lib/tr8n_core/ext/time.rb +30 -24
  42. data/lib/tr8n_core/generators/cache/base.rb +4 -4
  43. data/lib/tr8n_core/generators/cache/cdb.rb +1 -1
  44. data/lib/tr8n_core/generators/cache/file.rb +4 -3
  45. data/lib/tr8n_core/version.rb +2 -2
  46. data/lib/tr8n_core.rb +1 -1
  47. data/spec/application_spec.rb +5 -192
  48. data/spec/base_spec.rb +1 -1
  49. data/spec/config_spec.rb +21 -5
  50. data/spec/decorator_spec.rb +1 -1
  51. data/spec/decorators/base_spec.rb +1 -1
  52. data/spec/decorators/default_spec.rb +1 -1
  53. data/spec/decorators/html_spec.rb +8 -8
  54. data/spec/fixtures/languages/ru.json +36 -4
  55. data/spec/language_case_rule_spec.rb +1 -1
  56. data/spec/language_case_spec.rb +1 -1
  57. data/spec/language_context_rule_spec.rb +1 -1
  58. data/spec/language_context_spec.rb +1 -1
  59. data/spec/language_spec.rb +603 -4
  60. data/spec/rules_engine/evaluator_spec.rb +1 -1
  61. data/spec/rules_engine/parser_spec.rb +1 -1
  62. data/spec/{helper.rb → spec_helper.rb} +15 -7
  63. data/spec/tokens/data_spec.rb +2 -2
  64. data/spec/tokens/data_tokenizer_spec.rb +1 -1
  65. data/spec/tokens/decoration_tokenizer_spec.rb +1 -1
  66. data/spec/tokens/hidden_spec.rb +1 -1
  67. data/spec/tokens/method_spec.rb +1 -1
  68. data/spec/tokens/transform_spec.rb +1 -1
  69. data/spec/translation_key_spec.rb +1 -1
  70. data/spec/translation_spec.rb +1 -1
  71. data/spec/utils_spec.rb +1 -3
  72. metadata +5 -8
  73. data/config/config.yml +0 -34
  74. data/config/tokens/data.yml +0 -45
  75. data/config/tokens/decorations.yml +0 -37
  76. data/lib/tr8n_core/modules/logger.rb +0 -43
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2013 Michael Berkovich, tr8nhub.com
2
+ # Copyright (c) 2014 Michael Berkovich, tr8nhub.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -23,16 +23,22 @@
23
23
 
24
24
  class Time
25
25
 
26
- def translate(format = :default, language = Tr8n.config.current_language, options = {})
26
+ def translate(format = :default, language = Tr8n.session.current_language, options = {})
27
27
  label = (format.is_a?(String) ? format.clone : Tr8n.config.default_date_formats[format].clone)
28
28
  symbols = label.scan(/(%\w)/).flatten.uniq
29
29
 
30
30
  selected_tokens = []
31
- symbols.each do |symbol|
32
- token = Tr8n.config.strftime_symbol_to_token(symbol)
33
- next unless token
34
- selected_tokens << token
35
- label.gsub!(symbol, token)
31
+ using_tokens = label.index('{')
32
+
33
+ if using_tokens
34
+ selected_tokens = Tr8n::Tokens::Data.parse(label).collect{ |token| token.name(:parens => true) }
35
+ else
36
+ symbols.each do |symbol|
37
+ token = Tr8n.config.strftime_symbol_to_token(symbol)
38
+ next unless token
39
+ selected_tokens << token
40
+ label.gsub!(symbol, token)
41
+ end
36
42
  end
37
43
 
38
44
  tokens = {}
@@ -41,22 +47,22 @@ class Time
41
47
  when "{days}" then tokens[:days] = options[:with_leading_zero] ? day.with_leading_zero : day.to_s
42
48
  when "{year_days}" then tokens[:year_days] = options[:with_leading_zero] ? yday.with_leading_zero : yday.to_s
43
49
  when "{months}" then tokens[:months] = options[:with_leading_zero] ? month.with_leading_zero : month.to_s
44
- when "{week_num}" then tokens[:week_num] = wday
45
- when "{week_days}" then tokens[:week_days] = strftime("%w")
46
- when "{short_years}" then tokens[:short_years] = strftime("%y")
47
- when "{years}" then tokens[:years] = year
48
- when "{short_week_day_name}" then tokens[:short_week_day_name] = language.tr(Tr8n.config.default_abbr_day_names[wday], "Short name for a day of a week", {}, options)
49
- when "{week_day_name}" then tokens[:week_day_name] = language.tr(Tr8n.config.default_day_names[wday], "Day of a week", {}, options)
50
- when "{short_month_name}" then tokens[:short_month_name] = language.tr(Tr8n.config.default_abbr_month_names[month - 1], "Short month name", {}, options)
51
- when "{month_name}" then tokens[:month_name] = language.tr(Tr8n.config.default_month_names[month - 1], "Month name", {}, options)
52
- when "{am_pm}" then tokens[:am_pm] = language.tr(strftime("%p"), "Meridian indicator", {}, options)
53
- when "{full_hours}" then tokens[:full_hours] = hour
54
- when "{short_hours}" then tokens[:short_hours] = strftime("%I")
55
- when "{trimed_hour}" then tokens[:trimed_hour] = strftime("%l")
56
- when "{minutes}" then tokens[:minutes] = strftime("%M")
57
- when "{seconds}" then tokens[:seconds] = strftime("%S")
58
- when "{since_epoch}" then tokens[:since_epoch] = strftime("%s")
59
- when "{day_of_month}" then tokens[:day_of_month] = strftime("%e")
50
+ when "{week_num}" then tokens[:week_num] = wday
51
+ when "{week_days}" then tokens[:week_days] = strftime("%w")
52
+ when "{short_years}" then tokens[:short_years] = strftime("%y")
53
+ when "{years}" then tokens[:years] = year
54
+ when "{short_week_day_name}" then tokens[:short_week_day_name] = language.tr(Tr8n.config.default_abbr_day_name(wday), "Short name for a day of a week", {}, options)
55
+ when "{week_day_name}" then tokens[:week_day_name] = language.tr(Tr8n.config.default_day_name(wday), "Day of a week", {}, options)
56
+ when "{short_month_name}" then tokens[:short_month_name] = language.tr(Tr8n.config.default_abbr_month_name(month - 1), "Short month name", {}, options)
57
+ when "{month_name}" then tokens[:month_name] = language.tr(Tr8n.config.default_month_name(month - 1), "Month name", {}, options)
58
+ when "{am_pm}" then tokens[:am_pm] = language.tr(strftime("%p"), "Meridian indicator", {}, options)
59
+ when "{full_hours}" then tokens[:full_hours] = hour
60
+ when "{short_hours}" then tokens[:short_hours] = strftime("%I")
61
+ when "{trimed_hour}" then tokens[:trimed_hour] = strftime("%l")
62
+ when "{minutes}" then tokens[:minutes] = strftime("%M")
63
+ when "{seconds}" then tokens[:seconds] = strftime("%S")
64
+ when "{since_epoch}" then tokens[:since_epoch] = strftime("%s")
65
+ when "{day_of_month}" then tokens[:day_of_month] = strftime("%e")
60
66
  end
61
67
  end
62
68
 
@@ -64,7 +70,7 @@ class Time
64
70
  end
65
71
  alias :tr :translate
66
72
 
67
- def trl(format = :default, language = Tr8n.config.current_language, options = {})
73
+ def trl(format = :default, language = Tr8n.session.current_language, options = {})
68
74
  tr(format, language, options.merge!(:skip_decorations => true))
69
75
  end
70
76
 
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2013 Michael Berkovich, tr8nhub.com
2
+ # Copyright (c) 2014 Michael Berkovich, tr8nhub.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -24,7 +24,7 @@
24
24
  class Tr8nCore::Generators::Cache::Base
25
25
 
26
26
  def log(msg)
27
- puts("#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}: #{msg}\n")
27
+ puts("#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}: #{msg}\n")
28
28
  end
29
29
 
30
30
  def cache_path
@@ -58,7 +58,7 @@ class Tr8nCore::Generators::Cache::Base
58
58
 
59
59
  def cache_application
60
60
  log("Downloading application...")
61
- app = Tr8n.config.application.get("application", :definition => true)
61
+ app = Tr8n.session.application.get("application", :definition => true)
62
62
  cache(Tr8n::Application.cache_key(app["key"]), app)
63
63
  log("Application has been cached.")
64
64
  app
@@ -66,7 +66,7 @@ class Tr8nCore::Generators::Cache::Base
66
66
 
67
67
  def cache_languages
68
68
  log("Downloading languages...")
69
- languages = Tr8n.config.application.get("application/languages", :definition => true)
69
+ languages = Tr8n.session.application.get("application/languages", :definition => true)
70
70
  languages.each do |lang|
71
71
  cache(Tr8n::Language.cache_key(lang["locale"]), lang)
72
72
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2013 Michael Berkovich, tr8nhub.com
2
+ # Copyright (c) 2014 Michael Berkovich, tr8nhub.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2013 Michael Berkovich, tr8nhub.com
2
+ # Copyright (c) 2014 Michael Berkovich, tr8nhub.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -25,7 +25,7 @@ class Tr8nCore::Generators::Cache::File < Tr8nCore::Generators::Cache::Base
25
25
 
26
26
  def cache_path
27
27
  @cache_path ||= begin
28
- path = "#{Tr8n.config.cache_path}/files/tr8n_#{Tr8n.config.application.key}_#{@started_at.strftime('%Y_%m_%d_%H_%M_%S')}"
28
+ path = "#{Tr8n.config.cache[:path]}/files/tr8n_#{Tr8n.session.application.key}_#{@started_at.strftime('%Y_%m_%d_%H_%M_%S')}"
29
29
  pp "Cache will be stored in #{path}"
30
30
  FileUtils.mkdir_p(path)
31
31
  FileUtils.chmod(0777, path)
@@ -43,6 +43,7 @@ class Tr8nCore::Generators::Cache::File < Tr8nCore::Generators::Cache::Base
43
43
  end
44
44
 
45
45
  def execute
46
+ Tr8n.session.init_application
46
47
  cache_application
47
48
  @languages = cache_languages
48
49
  cache_translations
@@ -59,7 +60,7 @@ class Tr8nCore::Generators::Cache::File < Tr8nCore::Generators::Cache::Base
59
60
 
60
61
  sources.each do |source|
61
62
  log("Downloading #{source["source"]} in #{language["locale"]}...")
62
- translation_keys = Tr8n.config.application.get("source/translations", {:source => source["source"], :locale => language["locale"]})
63
+ translation_keys = Tr8n.session.application.get("source/translations", {:source => source["source"], :locale => language["locale"]})
63
64
  data = {:source => source["source"], :translation_keys => translation_keys}
64
65
  cache(Tr8n::Source.cache_key(source["source"], language["locale"]), data)
65
66
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2013 Michael Berkovich, tr8nhub.com
2
+ # Copyright (c) 2014 Michael Berkovich, tr8nhub.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -23,5 +23,5 @@
23
23
 
24
24
 
25
25
  module Tr8nCore
26
- VERSION = "4.0.1"
26
+ VERSION = "4.0.2"
27
27
  end
data/lib/tr8n_core.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2013 Michael Berkovich, tr8nhub.com
2
+ # Copyright (c) 2014 Michael Berkovich, tr8nhub.com
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,11 +1,14 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::Application do
6
6
  describe "#configuration" do
7
7
  it "sets class attributes" do
8
- expect(Tr8n::Application.attributes).to eq([:host, :key, :secret, :access_token, :name, :description, :threshold, :default_locale, :default_level, :features, :languages, :sources, :components, :tokens])
8
+ expect(Tr8n::Application.attributes).to eq([:host, :key, :secret, :access_token,
9
+ :name, :description, :threshold, :default_locale, :default_level,
10
+ :features, :languages, :featured_locales, :sources, :components, :tokens,
11
+ :css, :shortcuts])
9
12
  end
10
13
  end
11
14
 
@@ -35,194 +38,4 @@ describe Tr8n::Application do
35
38
  end
36
39
  end
37
40
 
38
- describe "#translation" do
39
- before do
40
- @app = init_application
41
- @english = @app.language('en-US')
42
- @russian = @app.language('ru')
43
- end
44
-
45
- it "translates with fallback to English" do
46
- Tr8n.config.with_block_options(:dry => true) do
47
- #expect(@russian.translate("{count||message}", {:count => 1})).to eq("1 message")
48
- #expect(@russian.translate("{count||message}", {:count => 5})).to eq("5 messages")
49
- #expect(@russian.translate("{count||message}", {:count => 0})).to eq("0 messages")
50
- end
51
- end
52
-
53
- # it "translates basic phrases to Russian" do
54
- # load_translation_keys_from_file(@app, 'translations/ru/basic.json')
55
- # Tr8n.config.with_block_options(:dry => true) do
56
- # expect(@russian.translate("Hello World")).to eq("Привет Мир")
57
- # expect(@russian.translate("Hello World", "Wrong context")).to eq("Hello World")
58
- # expect(@russian.translate("Hello World", "Greeting context")).to eq("Привет Мир")
59
- # expect(@russian.translate("Hello world")).to eq("Hello world")
60
- # expect(@russian.translate("Hello {user}", nil, :user => "Михаил")).to eq("Привет Михаил")
61
- # end
62
- # end
63
- #
64
- # it "translates basic phrases with data tokens to Russian" do
65
- # load_translation_keys_from_file(@app, 'translations/ru/basic.json')
66
- # Tr8n.config.with_block_options(:dry => true) do
67
- # expect(@russian.translate("Hello {user}", nil, :user => "Михаил")).to eq("Привет Михаил")
68
- # end
69
- # end
70
- #
71
- # it "uses default data tokens" do
72
- # Tr8n.config.with_block_options(:dry => true) do
73
- # expect(@english.translate("He said: {quot}Hello{quot}", nil)).to eq("He said: &quot;Hello&quot;")
74
- # expect(@english.translate("Code sample: {lbrace}a:'b'{rbrace}", nil)).to eq("Code sample: {a:'b'}")
75
- # end
76
- # end
77
- #
78
- # it "uses basic decoration tokens" do
79
- # Tr8n.config.with_block_options(:dry => true) do
80
- # expect(@english.translate("Hello [decor: World]", nil, :decor => lambda{|text| "''#{text}''"})).to eq("Hello ''World''")
81
- # end
82
- # end
83
- #
84
- # it "uses default decoration tokens" do
85
- # load_translation_keys_from_file(@app, 'translations/ru/basic.json')
86
- # Tr8n.config.with_block_options(:dry => true) do
87
- # expect(@english.translate("Hello [i: World]")).to eq("Hello <i>World</i>")
88
- # expect(@russian.translate("Hello [i: World]")).to eq("Привет <i>Мир</i>")
89
- # end
90
- # end
91
- #
92
- # it "uses mixed tokens" do
93
- # load_translation_keys_from_file(@app, 'translations/ru/basic.json')
94
- # Tr8n.config.with_block_options(:dry => true) do
95
- # expect(@english.translate("Hello [i: {user}]", nil, :user => "Michael")).to eq("Hello <i>Michael</i>")
96
- # expect(@russian.translate("Hello [i: {user}]", nil, :user => "Michael")).to eq("Привет <i>Michael</i>")
97
- # end
98
- # end
99
- #
100
- # it "uses method tokens" do
101
- # load_translation_keys_from_file(@app, 'translations/ru/basic.json')
102
- # Tr8n.config.with_block_options(:dry => true) do
103
- # expect(@russian.translate("Hello {user.first_name} [i: {user.last_name}]", nil,
104
- # :user => stub_object({:first_name => "Tom", :last_name => "Anderson"}))).to eq("Привет Tom <i>Anderson</i>")
105
- # end
106
- # end
107
- #
108
- # it "translates phrases with numeric rules to Russian" do
109
- # load_translation_keys_from_file(@app, 'translations/ru/counters.json')
110
- # trn = @russian.translate("{count||message}", nil, {:count => 1})
111
- # expect(trn).to eq("1 сообщение")
112
- # trn = @russian.translate("{count||message}", nil, {:count => 2})
113
- # expect(trn).to eq("2 сообщения")
114
- # trn = @russian.translate("{count||message}", nil, {:count => 5})
115
- # expect(trn).to eq("5 сообщений")
116
- # trn = @russian.translate("{count||message}", nil, {:count => 15})
117
- # expect(trn).to eq("15 сообщений")
118
- # end
119
- #
120
- # it "translates phrases with gender rules to Russian" do
121
- # #load_translation_key_from_hash(@app, {
122
- # # "label" => "{actor} sent {target} a gift.",
123
- # # "translations" => {
124
- # # "ru" => [
125
- # # {
126
- # # "label"=> "{actor} послал подарок {target::dat}.",
127
- # # "locale"=> "ru",
128
- # # "context"=> {
129
- # # "actor"=> [{ "type"=> "gender", "key"=> "male"}]
130
- # # }
131
- # # },
132
- # # {
133
- # # "label"=> "{actor} послала подарок {target::dat}.",
134
- # # "locale"=> "ru",
135
- # # "context"=> {
136
- # # "actor"=> [{ "type"=> "gender", "key"=> "female"}]
137
- # # },
138
- # # },
139
- # # {
140
- # # "label"=> "{actor} послал/а подарок {target::dat}.",
141
- # # "locale"=> "ru",
142
- # # "context"=> {
143
- # # "actor"=> [{ "type"=> "gender", "key"=> "unknown"}]
144
- # # },
145
- # # }
146
- # # ]
147
- # # }
148
- # #});
149
- #
150
- # load_translation_keys_from_file(@app, "translations/ru/genders.json")
151
- #
152
- # actor = {'gender' => 'female', 'name' => 'Таня'}
153
- # target = {'gender' => 'male', 'name' => 'Михаил'}
154
- #
155
- # Tr8n.config.with_block_options(:dry => true) do
156
- # expect(@russian.translate(
157
- # '{actor} sent {target} a gift.', nil,
158
- # :actor => {:object => actor, :attribute => 'name'},
159
- # :target => {:object => target, :attribute => 'name'})
160
- # ).to eq("Таня послала подарок Михаилу.")
161
- #
162
- # expect(@russian.translate(
163
- # '{actor} sent {target} a gift.', nil,
164
- # :actor => {:object => target, :attribute => 'name'},
165
- # :target => {:object => actor, :attribute => 'name'})
166
- # ).to eq("Михаил послал подарок Тане.")
167
- #
168
- # expect(@russian.translate(
169
- # '{actor} loves {target}.', nil,
170
- # :actor => {:object => actor, :attribute => 'name'},
171
- # :target => {:object => target, :attribute => 'name'})
172
- # ).to eq("Таня любит Михаила.")
173
- #
174
- # expect(@russian.translate(
175
- # '{actor} saw {target} {count||day} ago.', nil,
176
- # :actor => {:object => actor, :attribute => 'name'},
177
- # :target => {:object => target, :attribute => 'name'},
178
- # :count => 2)
179
- # ).to eq("Таня видела Михаила 2 дня назад.")
180
- #
181
- # expect(@russian.translate(
182
- # '{actor} saw {target} {count||day} ago.', nil,
183
- # :actor => {:object => target, :attribute => 'name'},
184
- # :target => {:object => actor, :attribute => 'name'},
185
- # :count => 2)
186
- # ).to eq("Михаил видел Таню 2 дня назад.")
187
- #
188
- # end
189
- #
190
- # # trn = @russian.translate("{count||message}", nil, {:count => 1})
191
- # # expect(trn).to eq("1 сообщение")
192
- # end
193
- #
194
- end
195
-
196
- #describe "#integration" do
197
- # # before do
198
- # # # @app = Tr8n::Application.init("http://geni.berkovich.net", "29adc3257b6960703", "abcdefg")
199
- # # end
200
- #
201
- # # it "returns cached language by locale" do
202
- # # # russian = @app.language("ru")
203
- # # # pp russian.translate("{count||message,messages}", nil, :count => 3)
204
- # # end
205
- #
206
- # # it "returns new language by locale" do
207
- # # # french = @app.language("fr")
208
- # # # pp french
209
- # # end
210
- #
211
- # # it "returns translators" do
212
- # # # translators = @app.translators
213
- # # # pp french
214
- # # end
215
- #
216
- # # it "returns featured languages" do
217
- # # # featured_languages = @app.featured_languages
218
- # # # pp french
219
- # # end
220
- #
221
- # # it "returns source by key" do
222
- # # # source = @app.source_by_key("/")
223
- # # # pp source.to_api_hash
224
- # # end
225
- #
226
- #end
227
-
228
41
  end
data/spec/base_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::Base do
6
6
  describe "hash value method" do
data/spec/config_spec.rb CHANGED
@@ -1,16 +1,32 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::Config do
6
6
  describe "loading defaults" do
7
7
  it "should load correct values" do
8
- expect(Tr8n.config.logger_enabled?).to be_true
8
+ expect(Tr8n.config.logger[:enabled]).to be_false
9
9
  expect(Tr8n.config.enabled?).to be_true
10
10
  expect(Tr8n.config.default_locale).to eq("en-US")
11
- expect(Tr8n.config.cache_enabled?).to be_false
12
- expect(Tr8n.config.log_path).to eq("./log/tr8n.log")
13
- expect(Tr8n.config.cache_adapter).to eq("file")
11
+ expect(Tr8n.config.cache[:enabled]).to be_false
12
+ expect(Tr8n.config.logger[:path]).to eq("./log/tr8n.log")
13
+ expect(Tr8n.config.cache[:adapter]).to eq("memcache")
14
14
  end
15
15
  end
16
+
17
+ describe "configuring settings" do
18
+ it "should preserve changes" do
19
+ expect(Tr8n.config.default_locale).to eq("en-US")
20
+ Tr8n.configure do |config|
21
+ config.default_locale= 'ru'
22
+ end
23
+ expect(Tr8n.config.default_locale).to eq("ru")
24
+
25
+ Tr8n.configure do |config|
26
+ config.default_locale= 'en-US'
27
+ end
28
+ expect(Tr8n.config.default_locale).to eq("en-US")
29
+ end
30
+ end
31
+
16
32
  end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Tr8n::Decorators::Default do
4
4
  describe "#initialize" do
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::Decorators::Base do
6
6
  describe "creating new decorator" do
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::Decorators::Default do
6
6
  describe "default decorator" do
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::Decorators::Html do
6
6
  describe "html decorator" do
@@ -19,16 +19,16 @@ describe Tr8n::Decorators::Html do
19
19
  })
20
20
 
21
21
  expect(decor.decorate("Hello World", en, en, tkey, {:skip_decorations => true})).to eq("Hello World")
22
- Tr8n.config.current_translator = nil
22
+ Tr8n.session.current_translator = nil
23
23
  expect(decor.decorate("Hello World", en, en, tkey)).to eq("Hello World")
24
24
 
25
- Tr8n.config.current_translator = Tr8n::Translator.new
25
+ Tr8n.session.current_translator = Tr8n::Translator.new
26
26
  expect(decor.decorate("Hello World", en, en, tkey)).to eq("Hello World")
27
27
 
28
- Tr8n.config.current_translator = Tr8n::Translator.new
29
- Tr8n.config.current_translator.inline = false
28
+ Tr8n.session.current_translator = Tr8n::Translator.new
29
+ Tr8n.session.current_translator.inline = false
30
30
  expect(decor.decorate("Hello World", en, en, tkey)).to eq("Hello World")
31
- Tr8n.config.current_translator.inline = true
31
+ Tr8n.session.current_translator.inline = true
32
32
  expect(decor.decorate("Hello World", en, en, tkey)).to eq("Hello World")
33
33
  expect(decor.decorate("Privet Mir", ru, ru, tkey)).to eq("<span class='tr8n_pending'>Privet Mir</span>")
34
34
  expect(decor.decorate("Privet Mir", ru, ru, tkey, {:use_div => true})).to eq("<div class='tr8n_pending'>Privet Mir</div>")
@@ -42,8 +42,8 @@ describe Tr8n::Decorators::Html do
42
42
  tkey.locked = true
43
43
  expect(decor.decorate("Privet Mir", ru, ru, tkey)).to eq("Privet Mir")
44
44
 
45
- Tr8n.config.current_translator.features = {"show_locked_keys" => true}
46
- Tr8n.config.current_translator.manager = true
45
+ Tr8n.session.current_translator.features = {"show_locked_keys" => true}
46
+ Tr8n.session.current_translator.manager = true
47
47
  expect(decor.decorate("Privet Mir", ru, ru, tkey)).to eq("<span class='tr8n_translatable tr8n_locked' data-translation_key_id='5'>Privet Mir</span>")
48
48
  end
49
49
  end
@@ -268,13 +268,13 @@
268
268
  {
269
269
  "one":"{$0}",
270
270
  "few":"{$1}",
271
- "many":"${2}",
271
+ "many":"{$2}",
272
272
  "other":"{$2}"
273
273
  },
274
274
  {
275
275
  "one":"{$0}",
276
276
  "few":"{$1}",
277
- "many":"${2}",
277
+ "many":"{$2}",
278
278
  "other":"{$3}"
279
279
  }
280
280
  ],
@@ -496,10 +496,42 @@
496
496
  "operations":"(append 'a' @value)",
497
497
  "operations_expression":[
498
498
  "append",
499
- "a",
499
+ "а",
500
500
  "@value"
501
501
  ]
502
- }
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
+ }
503
535
  ]
504
536
  },
505
537
  "ins":{
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::LanguageCaseRule do
6
6
  describe "initialize" do
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'helper'
3
+ require 'spec_helper'
4
4
 
5
5
  describe Tr8n::LanguageCase do
6
6
  before do
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Tr8n::LanguageContextRule do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Tr8n::LanguageContext do
4
4