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.
- checksums.yaml +4 -4
- data/README.md +163 -33
- data/lib/tr8n/application.rb +29 -27
- data/lib/tr8n/base.rb +2 -22
- data/lib/tr8n/cache.rb +9 -9
- data/lib/tr8n/cache_adapters/cdb.rb +2 -2
- data/lib/tr8n/cache_adapters/file.rb +2 -2
- data/lib/tr8n/cache_adapters/memcache.rb +3 -3
- data/lib/tr8n/cache_adapters/redis.rb +3 -3
- data/lib/tr8n/component.rb +1 -1
- data/lib/tr8n/config.rb +256 -202
- data/lib/tr8n/decorators/base.rb +1 -1
- data/lib/tr8n/decorators/default.rb +1 -1
- data/lib/tr8n/decorators/html.rb +4 -4
- data/lib/tr8n/exception.rb +1 -1
- data/lib/tr8n/language.rb +17 -27
- data/lib/tr8n/language_case.rb +4 -3
- data/lib/tr8n/language_case_rule.rb +1 -1
- data/lib/tr8n/language_context.rb +4 -2
- data/lib/tr8n/language_context_rule.rb +1 -1
- data/lib/tr8n/logger.rb +8 -3
- data/lib/tr8n/rules_engine/evaluator.rb +4 -7
- data/lib/tr8n/rules_engine/parser.rb +1 -28
- data/lib/tr8n/session.rb +87 -0
- data/lib/tr8n/source.rb +1 -1
- data/lib/tr8n/tokens/data.rb +2 -2
- data/lib/tr8n/tokens/data_tokenizer.rb +1 -1
- data/lib/tr8n/tokens/decoration_tokenizer.rb +1 -1
- data/lib/tr8n/tokens/hidden.rb +1 -1
- data/lib/tr8n/tokens/method.rb +1 -1
- data/lib/tr8n/tokens/transform.rb +2 -2
- data/lib/tr8n/translation.rb +2 -2
- data/lib/tr8n/translation_key.rb +4 -4
- data/lib/tr8n/translator.rb +1 -1
- data/lib/tr8n/utils.rb +1 -1
- data/lib/tr8n_core/ext/array.rb +4 -4
- data/lib/tr8n_core/ext/date.rb +38 -13
- data/lib/tr8n_core/ext/fixnum.rb +3 -3
- data/lib/tr8n_core/ext/hash.rb +1 -1
- data/lib/tr8n_core/ext/string.rb +3 -3
- data/lib/tr8n_core/ext/time.rb +30 -24
- data/lib/tr8n_core/generators/cache/base.rb +4 -4
- data/lib/tr8n_core/generators/cache/cdb.rb +1 -1
- data/lib/tr8n_core/generators/cache/file.rb +4 -3
- data/lib/tr8n_core/version.rb +2 -2
- data/lib/tr8n_core.rb +1 -1
- data/spec/application_spec.rb +5 -192
- data/spec/base_spec.rb +1 -1
- data/spec/config_spec.rb +21 -5
- data/spec/decorator_spec.rb +1 -1
- data/spec/decorators/base_spec.rb +1 -1
- data/spec/decorators/default_spec.rb +1 -1
- data/spec/decorators/html_spec.rb +8 -8
- data/spec/fixtures/languages/ru.json +36 -4
- data/spec/language_case_rule_spec.rb +1 -1
- data/spec/language_case_spec.rb +1 -1
- data/spec/language_context_rule_spec.rb +1 -1
- data/spec/language_context_spec.rb +1 -1
- data/spec/language_spec.rb +603 -4
- data/spec/rules_engine/evaluator_spec.rb +1 -1
- data/spec/rules_engine/parser_spec.rb +1 -1
- data/spec/{helper.rb → spec_helper.rb} +15 -7
- data/spec/tokens/data_spec.rb +2 -2
- data/spec/tokens/data_tokenizer_spec.rb +1 -1
- data/spec/tokens/decoration_tokenizer_spec.rb +1 -1
- data/spec/tokens/hidden_spec.rb +1 -1
- data/spec/tokens/method_spec.rb +1 -1
- data/spec/tokens/transform_spec.rb +1 -1
- data/spec/translation_key_spec.rb +1 -1
- data/spec/translation_spec.rb +1 -1
- data/spec/utils_spec.rb +1 -3
- metadata +5 -8
- data/config/config.yml +0 -34
- data/config/tokens/data.yml +0 -45
- data/config/tokens/decorations.yml +0 -37
- data/lib/tr8n_core/modules/logger.rb +0 -43
data/lib/tr8n/config.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
#!ruby19
|
2
|
+
# encoding: utf-8
|
1
3
|
#--
|
2
|
-
# Copyright (c)
|
4
|
+
# Copyright (c) 2014 Michael Berkovich, tr8nhub.com
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
7
|
# a copy of this software and associated documentation files (the
|
@@ -23,268 +25,320 @@
|
|
23
25
|
|
24
26
|
module Tr8n
|
25
27
|
|
28
|
+
class << self
|
29
|
+
attr_accessor :config
|
30
|
+
end
|
31
|
+
|
32
|
+
# Initializes default config
|
33
|
+
|
26
34
|
def self.config
|
27
35
|
@config ||= Tr8n::Config.new
|
28
36
|
end
|
29
37
|
|
30
|
-
#
|
31
|
-
|
32
|
-
|
38
|
+
# Allows you to configure Tr8n
|
39
|
+
#
|
40
|
+
# Tr8n.configure do |config|
|
41
|
+
# config.application = {:key => "", :secret => ""}
|
42
|
+
#
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
|
46
|
+
def self.configure
|
47
|
+
yield(self.config)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Allows you to create a block to perform something on adjusted config settings
|
51
|
+
# Once the block exists, the config will be reset back to what it was before:
|
52
|
+
#
|
53
|
+
# Tr8n.with_config_settings do |config|
|
54
|
+
# config.format = :text
|
55
|
+
#
|
56
|
+
# Do something....
|
57
|
+
#
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
|
61
|
+
def with_config_settings
|
62
|
+
old_config = @config.dup
|
63
|
+
yield(@config)
|
64
|
+
@config = old_config
|
33
65
|
end
|
34
66
|
|
35
67
|
# Acts as a global singleton that holds all Tr8n configuration
|
36
68
|
# The class can be extended with a different implementation, as long as the interface is supported
|
37
|
-
class Config
|
38
|
-
|
39
|
-
|
69
|
+
class Config
|
70
|
+
# Configuration Attributes
|
71
|
+
attr_accessor :enabled, :default_locale, :default_level, :format, :application, :context_rules, :logger, :cache, :default_tokens, :localization
|
40
72
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
73
|
+
# Used by Rails and Sinatra extensions
|
74
|
+
attr_accessor :current_locale_method, :current_user_method
|
44
75
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
76
|
+
# Used for IRB only
|
77
|
+
attr_accessor :submit_missing_keys_realtime
|
48
78
|
|
49
|
-
def
|
50
|
-
@
|
51
|
-
|
79
|
+
def initialize
|
80
|
+
@enabled = true
|
81
|
+
@default_locale = 'en-US'
|
82
|
+
@default_level = 0
|
83
|
+
@format = :html
|
52
84
|
|
53
|
-
|
54
|
-
|
55
|
-
end
|
85
|
+
# if running from IRB, make it default to TRUE
|
86
|
+
@submit_missing_keys_realtime = (['irb', 'pry'].include?($0 || ''))
|
56
87
|
|
57
|
-
|
58
|
-
|
59
|
-
end
|
88
|
+
@current_locale_method = :current_locale
|
89
|
+
@current_user_method = :current_user
|
60
90
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
hash_value(defaults, "application.host")
|
67
|
-
end
|
91
|
+
@application = {
|
92
|
+
:host => 'http://localhost:3000',
|
93
|
+
:key => 'default',
|
94
|
+
:secret => '12345',
|
95
|
+
}
|
68
96
|
|
69
|
-
|
70
|
-
|
71
|
-
|
97
|
+
@context_rules = {
|
98
|
+
:number => {
|
99
|
+
:variables => {
|
100
|
+
}
|
101
|
+
},
|
102
|
+
:gender => {
|
103
|
+
:variables => {
|
104
|
+
"@gender" => "gender",
|
105
|
+
}
|
106
|
+
},
|
107
|
+
:genders => {
|
108
|
+
:variables => {
|
109
|
+
"@genders" => lambda{|list| list.collect do |u|
|
110
|
+
u.is_a?(Hash) ? (u["gender"] || u[:gender]) : u.gender
|
111
|
+
end
|
112
|
+
},
|
113
|
+
"@size" => lambda{|list| list.size}
|
114
|
+
}
|
115
|
+
},
|
116
|
+
:date => {
|
117
|
+
:variables => {
|
118
|
+
}
|
119
|
+
},
|
120
|
+
:time => {
|
121
|
+
:variables => {
|
122
|
+
}
|
123
|
+
},
|
124
|
+
:list => {
|
125
|
+
:variables => {
|
126
|
+
"@count" => lambda{|list| list.size}
|
127
|
+
}
|
128
|
+
},
|
129
|
+
}
|
72
130
|
|
73
|
-
|
74
|
-
|
75
|
-
|
131
|
+
@logger = {
|
132
|
+
:enabled => false,
|
133
|
+
:path => './log/tr8n.log',
|
134
|
+
:level => 'debug'
|
135
|
+
}
|
76
136
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
137
|
+
@cache = {
|
138
|
+
:enabled => false,
|
139
|
+
:host => 'localhost:11211',
|
140
|
+
:adapter => 'memcache',
|
141
|
+
:version => 1,
|
142
|
+
:timeout => 3600
|
143
|
+
}
|
81
144
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
145
|
+
@default_tokens = {
|
146
|
+
:html => {
|
147
|
+
:data => {
|
148
|
+
:ndash => "–", # –
|
149
|
+
:mdash => "—", # —
|
150
|
+
:iexcl => "¡", # ¡
|
151
|
+
:iquest => "¿", # ¿
|
152
|
+
:quot => """, # "
|
153
|
+
:ldquo => "“", # “
|
154
|
+
:rdquo => "”", # ”
|
155
|
+
:lsquo => "‘", # ‘
|
156
|
+
:rsquo => "’", # ’
|
157
|
+
:laquo => "«", # «
|
158
|
+
:raquo => "»", # »
|
159
|
+
:nbsp => " ", # space
|
160
|
+
:lsaquo => "‹", # ‹
|
161
|
+
:rsaquo => "›", # ›
|
162
|
+
:br => "<br/>", # line break
|
163
|
+
:lbrace => "{",
|
164
|
+
:rbrace => "}",
|
165
|
+
:trade => "™", # TM
|
166
|
+
},
|
167
|
+
:decoration => {
|
168
|
+
:strong => "<strong>{$0}</strong>",
|
169
|
+
:bold => "<strong>{$0}</strong>",
|
170
|
+
:b => "<strong>{$0}</strong>",
|
171
|
+
:em => "<em>{$0}</em>",
|
172
|
+
:italic => "<i>{$0}</i>",
|
173
|
+
:i => "<i>{$0}</i>",
|
174
|
+
:link => "<a href='{$href}'>{$0}</a>",
|
175
|
+
:br => "<br>{$0}",
|
176
|
+
:strike => "<strike>{$0}</strike>",
|
177
|
+
:div => "<div id='{$id}' class='{$class}' style='{$style}'>{$0}</div>",
|
178
|
+
:span => "<span id='{$id}' class='{$class}' style='{$style}'>{$0}</span>",
|
179
|
+
:h1 => "<h1>{$0}</h1>",
|
180
|
+
:h2 => "<h2>{$0}</h2>",
|
181
|
+
:h3 => "<h3>{$0}</h3>",
|
182
|
+
}
|
183
|
+
},
|
184
|
+
:text => {
|
185
|
+
:data => {
|
186
|
+
:ndash => "–",
|
187
|
+
:mdash => "-",
|
188
|
+
:iexcl => "¡",
|
189
|
+
:iquest => "¿",
|
190
|
+
:quot => '"',
|
191
|
+
:ldquo => "“",
|
192
|
+
:rdquo => "”",
|
193
|
+
:lsquo => "‘",
|
194
|
+
:rsquo => "’",
|
195
|
+
:laquo => "«",
|
196
|
+
:raquo => "»",
|
197
|
+
:nbsp => " ",
|
198
|
+
:lsaquo => "‹",
|
199
|
+
:rsaquo => "›",
|
200
|
+
:br => "\n",
|
201
|
+
:lbrace => "{",
|
202
|
+
:rbrace => "}",
|
203
|
+
:trade => "™",
|
204
|
+
},
|
205
|
+
:decoration => {
|
206
|
+
:strong => "{$0}",
|
207
|
+
:bold => "{$0}",
|
208
|
+
:b => "{$0}",
|
209
|
+
:em => "{$0}",
|
210
|
+
:italic => "{$0}",
|
211
|
+
:i => "{$0}",
|
212
|
+
:link => "{$0}:{$1}",
|
213
|
+
:br => "\n{$0}",
|
214
|
+
:strike => "{$0}",
|
215
|
+
:div => "{$0}",
|
216
|
+
:span => "{$0}",
|
217
|
+
:h1 => "{$0}",
|
218
|
+
:h2 => "{$0}",
|
219
|
+
:h3 => "{$0}",
|
220
|
+
}
|
221
|
+
}
|
222
|
+
}
|
86
223
|
|
87
|
-
|
88
|
-
|
89
|
-
|
224
|
+
@localization = {
|
225
|
+
:default_day_names => ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
226
|
+
:default_abbr_day_names => ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
227
|
+
:default_month_names => ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
228
|
+
:default_abbr_month_names => ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
|
229
|
+
:custom_date_formats => {
|
230
|
+
:default => '%m/%d/%Y', # 07/4/2008
|
231
|
+
:short_numeric => '%m/%d', # 07/4
|
232
|
+
:short_numeric_year => '%m/%d/%y', # 07/4/08
|
233
|
+
:long_numeric => '%m/%d/%Y', # 07/4/2008
|
234
|
+
:verbose => '%A, %B %d, %Y', # Friday, July 4, 2008
|
235
|
+
:monthname => '%B %d', # July 4
|
236
|
+
:monthname_year => '%B %d, %Y', # July 4, 2008
|
237
|
+
:monthname_abbr => '%b %d', # Jul 4
|
238
|
+
:monthname_abbr_year => '%b %d, %Y', # Jul 4, 2008
|
239
|
+
:date_time => '%m/%d/%Y at %H:%M', # 01/03/1010 at 5:30
|
240
|
+
},
|
241
|
+
:token_mapping => {
|
242
|
+
"%a" => "{short_week_day_name}",
|
243
|
+
"%A" => "{week_day_name}",
|
244
|
+
"%b" => "{short_month_name}",
|
245
|
+
"%B" => "{month_name}",
|
246
|
+
"%p" => "{am_pm}",
|
247
|
+
"%d" => "{days}",
|
248
|
+
"%e" => "{day_of_month}",
|
249
|
+
"%j" => "{year_days}",
|
250
|
+
"%m" => "{months}",
|
251
|
+
"%W" => "{week_num}",
|
252
|
+
"%w" => "{week_days}",
|
253
|
+
"%y" => "{short_years}",
|
254
|
+
"%Y" => "{years}",
|
255
|
+
"%l" => "{trimed_hour}",
|
256
|
+
"%H" => "{full_hours}",
|
257
|
+
"%I" => "{short_hours}",
|
258
|
+
"%M" => "{minutes}",
|
259
|
+
"%S" => "{seconds}",
|
260
|
+
"%s" => "{since_epoch}"
|
261
|
+
}
|
262
|
+
}
|
90
263
|
end
|
91
264
|
|
92
|
-
def
|
93
|
-
|
94
|
-
hash_value(defaults, "default_level")
|
265
|
+
def enabled?
|
266
|
+
enabled
|
95
267
|
end
|
96
268
|
|
97
|
-
def
|
98
|
-
|
99
|
-
self.current_user = nil
|
100
|
-
self.current_language = nil
|
101
|
-
self.current_translator = nil
|
102
|
-
self.current_source = nil
|
103
|
-
self.current_component = nil
|
104
|
-
self.block_options = nil
|
269
|
+
def disabled?
|
270
|
+
not enabled?
|
105
271
|
end
|
106
272
|
|
107
273
|
#########################################################
|
108
|
-
##
|
274
|
+
## Application
|
109
275
|
#########################################################
|
110
276
|
|
111
|
-
def
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
277
|
+
#def default_locale
|
278
|
+
# return Tr8n.session.application.default_locale if Tr8n.session.application
|
279
|
+
# @default_locale
|
280
|
+
#end
|
281
|
+
#
|
282
|
+
#def default_level
|
283
|
+
# return Tr8n.session.application.default_level if Tr8n.session.application
|
284
|
+
# @default_level
|
285
|
+
#end
|
118
286
|
|
119
287
|
#########################################################
|
120
|
-
##
|
288
|
+
## Decorations
|
121
289
|
#########################################################
|
122
290
|
|
123
|
-
def cache_enabled?
|
124
|
-
hash_value(defaults, "cache.enabled")
|
125
|
-
end
|
126
|
-
|
127
|
-
def cache_path
|
128
|
-
"#{root}#{hash_value(defaults, "cache.path")}"
|
129
|
-
end
|
130
|
-
|
131
|
-
def cache_adapter
|
132
|
-
hash_value(defaults, "cache.adapter")
|
133
|
-
end
|
134
|
-
|
135
|
-
def cache_version
|
136
|
-
hash_value(defaults, "cache.version")
|
137
|
-
end
|
138
|
-
|
139
|
-
def cache_host
|
140
|
-
hash_value(defaults, "cache.host")
|
141
|
-
end
|
142
|
-
|
143
|
-
def cache_timeout
|
144
|
-
hash_value(defaults, 'cache.timeout')
|
145
|
-
end
|
146
|
-
|
147
|
-
#########################################################
|
148
|
-
## Rules Engine
|
149
|
-
#########################################################
|
150
|
-
|
151
|
-
def context_rules
|
152
|
-
@context_rules ||= {
|
153
|
-
"number" => {
|
154
|
-
"variables" => {
|
155
|
-
}
|
156
|
-
},
|
157
|
-
"gender" => {
|
158
|
-
"variables" => {
|
159
|
-
"@gender" => "gender",
|
160
|
-
}
|
161
|
-
},
|
162
|
-
"genders" => {
|
163
|
-
"variables" => {
|
164
|
-
"@genders" => lambda{|list| list.collect do |u|
|
165
|
-
u.is_a?(Hash) ? (u["gender"] || u[:gender]) : u.gender
|
166
|
-
end
|
167
|
-
},
|
168
|
-
"@size" => lambda{|list| list.size}
|
169
|
-
}
|
170
|
-
},
|
171
|
-
"date" => {
|
172
|
-
"variables" => {
|
173
|
-
}
|
174
|
-
},
|
175
|
-
"time" => {
|
176
|
-
"variables" => {
|
177
|
-
}
|
178
|
-
},
|
179
|
-
"list" => {
|
180
|
-
"variables" => {
|
181
|
-
"@count" => lambda{|list| list.size}
|
182
|
-
}
|
183
|
-
},
|
184
|
-
}
|
185
|
-
end
|
186
|
-
|
187
291
|
def decorator_class
|
292
|
+
return Tr8n::Decorators::Html if @format == :html
|
188
293
|
Tr8n::Decorators::Default
|
189
294
|
end
|
190
295
|
|
191
|
-
def default_data_tokens
|
192
|
-
@default_data_tokens ||= Tr8n::Utils.load_yaml("#{root}/config/tokens/data.yml")
|
193
|
-
end
|
194
|
-
|
195
|
-
def default_decoration_tokens
|
196
|
-
@default_decoration_tokens ||= Tr8n::Utils.load_yaml("#{root}/config/tokens/decorations.yml")
|
197
|
-
end
|
198
|
-
|
199
296
|
def default_token_value(token_name, type = :data, format = :html)
|
200
|
-
|
201
|
-
return default_decoration_tokens[format.to_s][token_name.to_s] if type.to_sym == :decoration
|
297
|
+
default_tokens[format.to_sym][type.to_sym][token_name.to_sym]
|
202
298
|
end
|
203
299
|
|
204
300
|
#########################################################
|
205
|
-
##
|
301
|
+
## Localization
|
206
302
|
#########################################################
|
207
303
|
|
208
|
-
def
|
209
|
-
|
210
|
-
end
|
211
|
-
|
212
|
-
def with_block_options(opts)
|
213
|
-
Thread.current[:block_options] ||= []
|
214
|
-
Thread.current[:block_options].push(opts)
|
215
|
-
if block_given?
|
216
|
-
ret = yield
|
217
|
-
end
|
218
|
-
Thread.current[:block_options].pop
|
219
|
-
ret
|
304
|
+
def strftime_symbol_to_token(symbol)
|
305
|
+
localization[:token_mapping][symbol]
|
220
306
|
end
|
221
307
|
|
222
|
-
def
|
223
|
-
|
224
|
-
arr.reverse.each do |opts|
|
225
|
-
return application.source_by_key(opts[:source]) unless opts[:source].blank?
|
226
|
-
end
|
227
|
-
nil
|
308
|
+
def default_day_names
|
309
|
+
localization[:default_day_names]
|
228
310
|
end
|
229
311
|
|
230
|
-
def
|
231
|
-
|
232
|
-
arr.reverse.each do |opts|
|
233
|
-
return application.component_by_key(opts[:component]) unless opts[:component].blank?
|
234
|
-
end
|
235
|
-
Tr8n.config.current_component
|
312
|
+
def default_day_name(index)
|
313
|
+
"" + default_day_names[index]
|
236
314
|
end
|
237
315
|
|
238
|
-
|
239
|
-
|
240
|
-
#########################################################
|
241
|
-
|
242
|
-
def localization
|
243
|
-
hash_value(defaults, "localization")
|
316
|
+
def default_abbr_day_names
|
317
|
+
localization[:default_abbr_day_names]
|
244
318
|
end
|
245
319
|
|
246
|
-
def
|
247
|
-
|
248
|
-
"%a" => "{short_week_day_name}",
|
249
|
-
"%A" => "{week_day_name}",
|
250
|
-
"%b" => "{short_month_name}",
|
251
|
-
"%B" => "{month_name}",
|
252
|
-
"%p" => "{am_pm}",
|
253
|
-
"%d" => "{days}",
|
254
|
-
"%e" => "{day_of_month}",
|
255
|
-
"%j" => "{year_days}",
|
256
|
-
"%m" => "{months}",
|
257
|
-
"%W" => "{week_num}",
|
258
|
-
"%w" => "{week_days}",
|
259
|
-
"%y" => "{short_years}",
|
260
|
-
"%Y" => "{years}",
|
261
|
-
"%l" => "{trimed_hour}",
|
262
|
-
"%H" => "{full_hours}",
|
263
|
-
"%I" => "{short_hours}",
|
264
|
-
"%M" => "{minutes}",
|
265
|
-
"%S" => "{seconds}",
|
266
|
-
"%s" => "{since_epoch}"
|
267
|
-
}[symbol]
|
320
|
+
def default_abbr_day_name(index)
|
321
|
+
"" + default_abbr_day_names[index]
|
268
322
|
end
|
269
323
|
|
270
|
-
def
|
271
|
-
|
324
|
+
def default_month_names
|
325
|
+
localization[:default_month_names]
|
272
326
|
end
|
273
327
|
|
274
|
-
def
|
275
|
-
|
328
|
+
def default_month_name(index)
|
329
|
+
"" + default_month_names[index]
|
276
330
|
end
|
277
331
|
|
278
|
-
def
|
279
|
-
|
332
|
+
def default_abbr_month_names
|
333
|
+
localization[:default_abbr_month_names]
|
280
334
|
end
|
281
335
|
|
282
|
-
def
|
283
|
-
|
336
|
+
def default_abbr_month_name(index)
|
337
|
+
"" + default_abbr_month_names[index]
|
284
338
|
end
|
285
339
|
|
286
340
|
def default_date_formats
|
287
|
-
|
341
|
+
localization[:custom_date_formats]
|
288
342
|
end
|
289
343
|
|
290
344
|
end
|
data/lib/tr8n/decorators/base.rb
CHANGED
data/lib/tr8n/decorators/html.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c)
|
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
|
@@ -28,8 +28,8 @@ class Tr8n::Decorators::Html < Tr8n::Decorators::Base
|
|
28
28
|
return translated_label if options[:skip_decorations]
|
29
29
|
# if translation key language is the same as target language - skip decorations
|
30
30
|
return translated_label if translation_key.language == target_language
|
31
|
-
return translated_label unless Tr8n.
|
32
|
-
return translated_label if translation_key.locked? and not Tr8n.
|
31
|
+
return translated_label unless Tr8n.session.current_translator and Tr8n.session.current_translator.inline?
|
32
|
+
return translated_label if translation_key.locked? and not Tr8n.session.current_translator.manager?
|
33
33
|
|
34
34
|
element = 'span'
|
35
35
|
if options[:use_div]
|
@@ -44,7 +44,7 @@ class Tr8n::Decorators::Html < Tr8n::Decorators::Base
|
|
44
44
|
|
45
45
|
if translation_key.locked?
|
46
46
|
# must be a manager and enabling locking feature
|
47
|
-
return translated_label unless Tr8n.
|
47
|
+
return translated_label unless Tr8n.session.current_translator.feature_enabled?(:show_locked_keys)
|
48
48
|
classes << 'tr8n_locked'
|
49
49
|
elsif translation_language == translation_key.language
|
50
50
|
classes << 'tr8n_not_translated'
|
data/lib/tr8n/exception.rb
CHANGED
data/lib/tr8n/language.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c)
|
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
|
@@ -80,7 +80,7 @@ class Tr8n::Language < Tr8n::Base
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def current_source(options)
|
83
|
-
options[:source] || Tr8n.
|
83
|
+
options[:source] || Tr8n.session.block_options[:source] || Tr8n.session.current_source || 'undefined'
|
84
84
|
end
|
85
85
|
|
86
86
|
#######################################################################################################
|
@@ -104,8 +104,8 @@ class Tr8n::Language < Tr8n::Base
|
|
104
104
|
return label if label.tr8n_translated?
|
105
105
|
|
106
106
|
params = Tr8n::Utils.normalize_tr_params(label, description, tokens, options)
|
107
|
-
key_locale = hash_value(params[:options], :locale) || hash_value(Tr8n.
|
108
|
-
key_level = hash_value(params[:options], :level) || hash_value(Tr8n.
|
107
|
+
key_locale = hash_value(params[:options], :locale) || hash_value(Tr8n.session.block_options, :locale) || Tr8n.config.default_locale
|
108
|
+
key_level = hash_value(params[:options], :level) || hash_value(Tr8n.session.block_options, :level) || Tr8n.config.default_level
|
109
109
|
|
110
110
|
temp_key = Tr8n::TranslationKey.new({
|
111
111
|
:application => application,
|
@@ -118,7 +118,7 @@ class Tr8n::Language < Tr8n::Base
|
|
118
118
|
|
119
119
|
#Tr8n.logger.info("Translating " + params[:label] + " from: " + key_locale.inspect + " to " + locale.inspect)
|
120
120
|
|
121
|
-
params[:tokens].merge!(:viewing_user => Tr8n.
|
121
|
+
params[:tokens].merge!(:viewing_user => Tr8n.session.current_user)
|
122
122
|
|
123
123
|
if Tr8n.config.disabled? or locale == key_locale
|
124
124
|
return temp_key.substitute_tokens(params[:label], params[:tokens], self, params[:options]).tr8n_translated
|
@@ -130,15 +130,15 @@ class Tr8n::Language < Tr8n::Base
|
|
130
130
|
end
|
131
131
|
|
132
132
|
# no cache or translator is using inline mode - use service, otherwise load from cache
|
133
|
-
if not Tr8n.config.
|
133
|
+
if not Tr8n.config.cache[:enabled] or (Tr8n.session.current_translator and Tr8n.session.current_translator.inline?)
|
134
134
|
return translate_from_service(temp_key, params[:tokens], params[:options]).tr8n_translated
|
135
135
|
end
|
136
136
|
|
137
137
|
translate_from_cache(temp_key, params[:tokens], params[:options]).tr8n_translated
|
138
|
-
rescue Exception => ex
|
139
|
-
|
140
|
-
|
141
|
-
|
138
|
+
#rescue Exception => ex
|
139
|
+
# Tr8n.logger.error("Failed to translate: #{params[:label]} : #{ex.message}")
|
140
|
+
# Tr8n.logger.error(ex.backtrace)
|
141
|
+
# params[:label]
|
142
142
|
end
|
143
143
|
alias :tr :translate
|
144
144
|
|
@@ -199,24 +199,14 @@ class Tr8n::Language < Tr8n::Base
|
|
199
199
|
def translate_from_service(translation_key, tokens, options)
|
200
200
|
source_key = current_source(options)
|
201
201
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
translation_key = source_translation_keys[translation_key.key]
|
207
|
-
else
|
208
|
-
application.register_missing_key(translation_key, source)
|
209
|
-
end
|
210
|
-
|
211
|
-
return translation_key.translate(self, tokens, options)
|
212
|
-
end
|
213
|
-
|
214
|
-
# all translations are cached in memory as the second level cache
|
215
|
-
memory_cached_translation_key = application.translation_key(translation_key.key)
|
216
|
-
if memory_cached_translation_key
|
217
|
-
translation_key = memory_cached_translation_key
|
202
|
+
source = application.source(source_key)
|
203
|
+
source_translation_keys = source.fetch_translations_for_language(self, options)
|
204
|
+
if source_translation_keys[translation_key.key]
|
205
|
+
translation_key = source_translation_keys[translation_key.key]
|
218
206
|
else
|
219
|
-
|
207
|
+
application.register_missing_key(translation_key, source)
|
208
|
+
memory_cached_translation_key = application.translation_key(translation_key.key)
|
209
|
+
translation_key = memory_cached_translation_key if memory_cached_translation_key
|
220
210
|
end
|
221
211
|
|
222
212
|
translation_key.translate(self, tokens, options)
|