tml 5.5.4 → 5.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tml.rb +24 -0
- data/lib/tml/application.rb +1 -1
- data/lib/tml/config.rb +53 -10
- data/lib/tml/ext/string.rb +1 -1
- data/lib/tml/language.rb +3 -2
- data/lib/tml/session.rb +29 -0
- data/lib/tml/tokenizers/decoration.rb +2 -0
- data/lib/tml/utils.rb +3 -3
- data/lib/tml/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5346ec2d7d296d5fda202794dde03edb2fac349e
|
4
|
+
data.tar.gz: e97d96c35d07372e8cb0188c38b44758ca460a90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17559b2cd7a8b668a81de85d96f3315643587352084f8f367fe34a27989c951a965d12ab482483483f558a161a3127f785689161097d2701025304e080aa375c
|
7
|
+
data.tar.gz: 37ea474a9f2502c584c5f87672261bf77587370dfddce5571b402c59a287ab37a7f30affe4f02205440d902b544b03978a16bc204233bf395f33d5a630332cec
|
data/lib/tml.rb
CHANGED
@@ -38,6 +38,30 @@ module Tml
|
|
38
38
|
module Decorators end
|
39
39
|
module CacheAdapters end
|
40
40
|
module Generators end
|
41
|
+
|
42
|
+
def self.default_language
|
43
|
+
Tml.config.default_language
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.current_language
|
47
|
+
Tml.session.current_language
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.language(locale)
|
51
|
+
Tml.session.application.language(locale)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.translate(label, description = '', tokens = {}, options = {})
|
55
|
+
Tml.session.translate(label, description, tokens, options)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.with_options(opts)
|
59
|
+
Tml.session.with_options(opts) do
|
60
|
+
if block_given?
|
61
|
+
yield
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
41
65
|
end
|
42
66
|
|
43
67
|
%w(tml/base.rb tml tml/api tml/rules_engine tml/tokens tml/tokenizers tml/decorators tml/cache_adapters tml/cache tml/ext).each do |f|
|
data/lib/tml/application.rb
CHANGED
@@ -194,7 +194,7 @@ class Tml::Application < Tml::Base
|
|
194
194
|
# Returns source by key
|
195
195
|
def source(key, locale)
|
196
196
|
self.sources ||= {}
|
197
|
-
self.sources[key] ||= Tml::Source.new(
|
197
|
+
self.sources["#{locale}/#{key}"] ||= Tml::Source.new(
|
198
198
|
:application => self,
|
199
199
|
:source => key
|
200
200
|
).fetch_translations(locale)
|
data/lib/tml/config.rb
CHANGED
@@ -76,7 +76,7 @@ module Tml
|
|
76
76
|
class Config
|
77
77
|
# Configuration Attributes
|
78
78
|
attr_accessor :enabled, :locale, :default_level, :format, :application, :postoffice, :context_rules, :logger, :cache, :default_tokens, :localization
|
79
|
-
attr_accessor :auto_init, :source_separator
|
79
|
+
attr_accessor :auto_init, :source_separator, :domain
|
80
80
|
|
81
81
|
# Used by Rails and Sinatra extensions
|
82
82
|
attr_accessor :current_locale_method, :current_user_method, :translator_options, :i18n_backend
|
@@ -89,21 +89,29 @@ module Tml
|
|
89
89
|
@enabled = true
|
90
90
|
@default_level = 0
|
91
91
|
@format = :html
|
92
|
-
@subdomains = false
|
93
92
|
@auto_init = true
|
94
93
|
@source_separator = '@:@'
|
95
94
|
|
96
95
|
@api_client = {
|
97
|
-
|
98
|
-
|
99
|
-
|
96
|
+
class: Tml::Api::Client,
|
97
|
+
timeout: 5,
|
98
|
+
open_timeout: 2
|
100
99
|
}
|
101
100
|
|
102
101
|
@locale = {
|
103
|
-
default:
|
104
|
-
method:
|
105
|
-
|
106
|
-
|
102
|
+
default: 'en', # default locale
|
103
|
+
method: 'current_locale', # method to use for user selected locale, if nil, the rest will be a fallback
|
104
|
+
param: 'locale', # the way to name the param
|
105
|
+
strategy: 'param', # approach param, pre-path, pre-domain, custom-domain
|
106
|
+
redirect: true, # if TML should handle locale logic redirects
|
107
|
+
skip_default: false, # if the default locales should not be visible
|
108
|
+
browser: true, # if you want to use a browser header to determine the locale
|
109
|
+
cookie: true, # if you want to store user selected locale in the cookie
|
110
|
+
# default_host: '', # if user wants to not display default locale, we need to know the default host
|
111
|
+
# mapping: { # domain to locale mapping
|
112
|
+
# en: '',
|
113
|
+
# ru: '',
|
114
|
+
# }
|
107
115
|
}
|
108
116
|
|
109
117
|
@agent = {
|
@@ -240,7 +248,7 @@ module Tml
|
|
240
248
|
:em => '<em>{$0}</em>',
|
241
249
|
:italic => '<i>{$0}</i>',
|
242
250
|
:i => '<i>{$0}</i>',
|
243
|
-
:link => "<a href='{$href}'>{$0}</a>",
|
251
|
+
:link => "<a href='{$href}' class='{$class}' style='{$style}' title='{$title}'>{$0}</a>",
|
244
252
|
:br => '<br>{$0}',
|
245
253
|
:strike => '<strike>{$0}</strike>',
|
246
254
|
:div => "<div id='{$id}' class='{$class}' style='{$style}'>{$0}</div>",
|
@@ -339,6 +347,41 @@ module Tml
|
|
339
347
|
not enabled?
|
340
348
|
end
|
341
349
|
|
350
|
+
def locale_expression
|
351
|
+
/^[a-z]{2}(-[A-Z]{2,3})?$/
|
352
|
+
end
|
353
|
+
|
354
|
+
def locale_strategy
|
355
|
+
locale[:strategy] || 'param'
|
356
|
+
end
|
357
|
+
|
358
|
+
def agent_locale_strategy
|
359
|
+
locale.merge(param: locale_param)
|
360
|
+
end
|
361
|
+
|
362
|
+
def locale_param
|
363
|
+
locale[:param] || 'locale'
|
364
|
+
end
|
365
|
+
|
366
|
+
def current_locale_method
|
367
|
+
locale[:method] || @current_locale_method
|
368
|
+
end
|
369
|
+
|
370
|
+
def locale_cookie_enabled?
|
371
|
+
if %w(pre-domain custom-domain).include?(locale[:strategy])
|
372
|
+
return false
|
373
|
+
end
|
374
|
+
locale[:cookie].nil? || locale[:cookie]
|
375
|
+
end
|
376
|
+
|
377
|
+
def locale_browser_enabled?
|
378
|
+
locale[:browser].nil? || locale[:browser]
|
379
|
+
end
|
380
|
+
|
381
|
+
def locale_redirect_enabled?
|
382
|
+
locale[:redirect].nil? || locale[:redirect]
|
383
|
+
end
|
384
|
+
|
342
385
|
def nested_value(hash, key, default_value = nil)
|
343
386
|
parts = key.split('.')
|
344
387
|
parts.each do |part|
|
data/lib/tml/ext/string.rb
CHANGED
data/lib/tml/language.rb
CHANGED
@@ -118,7 +118,8 @@ class Tml::Language < Tml::Base
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def current_source(options)
|
121
|
-
|
121
|
+
return options[:source] if options and options[:source]
|
122
|
+
(Tml.session.block_option(:source) || Tml.session.current_source || 'undefined').to_s
|
122
123
|
end
|
123
124
|
|
124
125
|
#######################################################################################################
|
@@ -181,7 +182,7 @@ class Tml::Language < Tml::Base
|
|
181
182
|
end
|
182
183
|
|
183
184
|
# fetch translations grouped by source
|
184
|
-
source_key = current_source(options)
|
185
|
+
source_key = current_source(params[:options])
|
185
186
|
current_source_path = source_path
|
186
187
|
|
187
188
|
# Dynamic sources are never registered under the parent source for fast retrieval
|
data/lib/tml/session.rb
CHANGED
@@ -121,6 +121,34 @@ module Tml
|
|
121
121
|
current_translator and current_translator.inline?
|
122
122
|
end
|
123
123
|
|
124
|
+
def translate(label, description = '', tokens = {}, options = {})
|
125
|
+
params = Tml::Utils.normalize_tr_params(label, description, tokens, options)
|
126
|
+
return params[:label] if params[:label].tml_translated?
|
127
|
+
|
128
|
+
params[:options][:caller] ||= caller
|
129
|
+
|
130
|
+
if Tml.config.disabled?
|
131
|
+
return Tml.config.default_language.translate(params[:label], params[:tokens], params[:options]).tml_translated
|
132
|
+
end
|
133
|
+
|
134
|
+
# Translate individual sentences
|
135
|
+
if params[:options][:split]
|
136
|
+
text = params[:label]
|
137
|
+
sentences = Tml::Utils.split_sentences(text)
|
138
|
+
sentences.each do |sentence|
|
139
|
+
text = text.gsub(sentence, target_language.translate(sentence, params[:description], params[:tokens], params[:options]))
|
140
|
+
end
|
141
|
+
return text.tml_translated
|
142
|
+
end
|
143
|
+
|
144
|
+
target_language.translate(params).tml_translated
|
145
|
+
rescue Tml::Exception => ex
|
146
|
+
#pp ex, ex.backtrace
|
147
|
+
Tml.logger.error(ex.message)
|
148
|
+
#Tml.logger.error(ex.message + "\n=> " + ex.backtrace.join("\n=> "))
|
149
|
+
label
|
150
|
+
end
|
151
|
+
|
124
152
|
#########################################################
|
125
153
|
## Block Options
|
126
154
|
#########################################################
|
@@ -161,6 +189,7 @@ module Tml
|
|
161
189
|
pop_block_options
|
162
190
|
ret
|
163
191
|
end
|
192
|
+
alias_method :with_options, :with_block_options
|
164
193
|
|
165
194
|
end
|
166
195
|
end
|
data/lib/tml/utils.rb
CHANGED
@@ -46,15 +46,15 @@ module Tml
|
|
46
46
|
:label => label,
|
47
47
|
:description => nil,
|
48
48
|
:tokens => description,
|
49
|
-
:options => tokens
|
49
|
+
:options => tokens || {}
|
50
50
|
}
|
51
51
|
end
|
52
52
|
|
53
53
|
{
|
54
54
|
:label => label,
|
55
55
|
:description => description,
|
56
|
-
:tokens => tokens,
|
57
|
-
:options => options
|
56
|
+
:tokens => tokens || {},
|
57
|
+
:options => options || {}
|
58
58
|
}
|
59
59
|
end
|
60
60
|
|
data/lib/tml/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Berkovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|