tml 5.1.4 → 5.2.1
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.
- checksums.yaml +4 -4
- data/lib/tml/api/client.rb +10 -2
- data/lib/tml/application.rb +1 -1
- data/lib/tml/config.rb +3 -2
- data/lib/tml/decorators/base.rb +10 -7
- data/lib/tml/decorators/default.rb +0 -16
- data/lib/tml/decorators/json.rb +69 -0
- data/lib/tml/ext/array.rb +10 -0
- data/lib/tml/ext/hash.rb +10 -0
- data/lib/tml/language.rb +10 -3
- data/lib/tml/translation_key.rb +38 -4
- data/lib/tml/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9015ca0a3d1822fed10c823c64a1a903cfda847
|
4
|
+
data.tar.gz: 2706039cc562814eabda1d87f962af80238615d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3faa10615d43f63cd29f05d631ce1c2c2da7c142f57b1cb9196031c0619cdc2f12af9262ca17ae89e220310e512e29b0a89e4fb92e0a0859b8d12c34b34fa917
|
7
|
+
data.tar.gz: fb89ecb8a4d7e5a268e5b3523edb61c29e7a7218e7fd4a1162387cd0dd1454468b2af8142ebe37f6670c60428804a08a554b0b1301c331fd72a5835568c294d1
|
data/lib/tml/api/client.rb
CHANGED
@@ -73,7 +73,7 @@ class Tml::Api::Client < Tml::Base
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def get_cache_version
|
76
|
-
execute_request('
|
76
|
+
execute_request('projects/current/version', {}, {:raw => true})
|
77
77
|
end
|
78
78
|
|
79
79
|
def verify_cache_version
|
@@ -128,12 +128,18 @@ class Tml::Api::Client < Tml::Base
|
|
128
128
|
data
|
129
129
|
end
|
130
130
|
|
131
|
+
def live_translations_request?(cache_key)
|
132
|
+
return if cache_key.blank?
|
133
|
+
return unless Tml.session.block_option(:live)
|
134
|
+
cache_key.index('sources') or cache_key.index('keys')
|
135
|
+
end
|
136
|
+
|
131
137
|
def enable_cache?(opts)
|
132
138
|
return false unless opts[:method] == :get
|
133
139
|
return false if opts[:cache_key].nil?
|
134
140
|
return false unless Tml.cache.enabled?
|
141
|
+
return false if live_translations_request?(opts[:cache_key])
|
135
142
|
return false if Tml.session.inline_mode?
|
136
|
-
return false if Tml.session.block_option(:live) and opts[:cache_key].index('sources')
|
137
143
|
true
|
138
144
|
end
|
139
145
|
|
@@ -290,6 +296,8 @@ class Tml::Api::Client < Tml::Base
|
|
290
296
|
# params = params.merge(param => "##filtered##") if params[param]
|
291
297
|
#end
|
292
298
|
|
299
|
+
path = "#{path[0] == '/' ? '' : '/'}#{path}"
|
300
|
+
|
293
301
|
if opts[:method] == :post
|
294
302
|
Tml.logger.debug("post: #{opts[:host]}#{path}")
|
295
303
|
else
|
data/lib/tml/application.rb
CHANGED
data/lib/tml/config.rb
CHANGED
@@ -80,13 +80,14 @@ module Tml
|
|
80
80
|
|
81
81
|
# Used by Rails and Sinatra extensions
|
82
82
|
attr_accessor :current_locale_method, :current_user_method, :translator_options, :i18n_backend
|
83
|
-
attr_accessor :invalidator, :agent
|
83
|
+
attr_accessor :invalidator, :agent, :api_client_class
|
84
84
|
|
85
85
|
# Used for IRB only
|
86
86
|
attr_accessor :submit_missing_keys_realtime
|
87
87
|
|
88
88
|
def initialize
|
89
89
|
@enabled = true
|
90
|
+
@api_client_class = Tml::Api::Client
|
90
91
|
@default_level = 0
|
91
92
|
@format = :html
|
92
93
|
@subdomains = false
|
@@ -418,7 +419,7 @@ module Tml
|
|
418
419
|
end
|
419
420
|
|
420
421
|
def default_day_name(index)
|
421
|
-
|
422
|
+
'' + default_day_names[index]
|
422
423
|
end
|
423
424
|
|
424
425
|
def default_abbr_day_names
|
data/lib/tml/decorators/base.rb
CHANGED
@@ -32,25 +32,28 @@
|
|
32
32
|
|
33
33
|
class Tml::Decorators::Base < Tml::Base
|
34
34
|
|
35
|
-
def self.decorator
|
36
|
-
|
37
|
-
|
35
|
+
def self.decorator(options = {})
|
36
|
+
decorator_klass = Tml.config.decorator_class
|
37
|
+
if options[:decorator]
|
38
|
+
decorator_klass = "Tml::Decorators::#{options[:decorator].camelcase}".constantize
|
39
|
+
end
|
40
|
+
decorator_klass.new
|
38
41
|
end
|
39
42
|
|
40
43
|
def decorate(translated_label, translation_language, target_language, translation_key, options = {})
|
41
|
-
|
44
|
+
translated_label
|
42
45
|
end
|
43
46
|
|
44
47
|
def decorate_language_case(language_case, rule, original, transformed, options = {})
|
45
|
-
|
48
|
+
transformed
|
46
49
|
end
|
47
50
|
|
48
51
|
def decorate_token(token, value, options = {})
|
49
|
-
|
52
|
+
value
|
50
53
|
end
|
51
54
|
|
52
55
|
def decorate_element(token, value, options = {})
|
53
|
-
|
56
|
+
value
|
54
57
|
end
|
55
58
|
|
56
59
|
def inline_mode?
|
@@ -32,20 +32,4 @@
|
|
32
32
|
|
33
33
|
class Tml::Decorators::Default < Tml::Decorators::Base
|
34
34
|
|
35
|
-
def decorate(translated_label, translation_language, target_language, translation_key, options = {})
|
36
|
-
translated_label
|
37
|
-
end
|
38
|
-
|
39
|
-
def decorate_language_case(language_case, rule, original, transformed, options = {})
|
40
|
-
transformed
|
41
|
-
end
|
42
|
-
|
43
|
-
def decorate_token(token, value, options = {})
|
44
|
-
value
|
45
|
-
end
|
46
|
-
|
47
|
-
def decorate_element(token, value, options = {})
|
48
|
-
value
|
49
|
-
end
|
50
|
-
|
51
35
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#--
|
3
|
+
# Copyright (c) 2015 Translation Exchange, Inc
|
4
|
+
#
|
5
|
+
# _______ _ _ _ ______ _
|
6
|
+
# |__ __| | | | | (_) | ____| | |
|
7
|
+
# | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
|
8
|
+
# | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
|
9
|
+
# | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
|
10
|
+
# |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
|
11
|
+
# __/ |
|
12
|
+
# |___/
|
13
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
14
|
+
# a copy of this software and associated documentation files (the
|
15
|
+
# "Software"), to deal in the Software without restriction, including
|
16
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
17
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
18
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
19
|
+
# the following conditions:
|
20
|
+
#
|
21
|
+
# The above copyright notice and this permission notice shall be
|
22
|
+
# included in all copies or substantial portions of the Software.
|
23
|
+
#
|
24
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
25
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
26
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
27
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
28
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
29
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
30
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
31
|
+
#++
|
32
|
+
|
33
|
+
class Tml::Decorators::Json < Tml::Decorators::Base
|
34
|
+
|
35
|
+
def decorate(translated_label, translation_language, target_language, translation_key, options = {})
|
36
|
+
#Tml.logger.info("Decorating #{translated_label} of #{translation_language.locale} to #{target_language.locale}")
|
37
|
+
|
38
|
+
data = {
|
39
|
+
original: {
|
40
|
+
label: translation_key.label,
|
41
|
+
locale: translation_key.locale
|
42
|
+
},
|
43
|
+
translation: {
|
44
|
+
label: translated_label,
|
45
|
+
locale: translation_language.locale,
|
46
|
+
},
|
47
|
+
options: options,
|
48
|
+
target_locale: target_language.locale
|
49
|
+
}
|
50
|
+
|
51
|
+
if options[:locked]
|
52
|
+
data[:status] = 'locked'
|
53
|
+
elsif translation_language == translation_key.language
|
54
|
+
if options[:pending]
|
55
|
+
data[:status] = 'pending'
|
56
|
+
else
|
57
|
+
data[:status] = 'not_translated'
|
58
|
+
end
|
59
|
+
elsif translation_language == target_language
|
60
|
+
data[:status] = 'translated'
|
61
|
+
else
|
62
|
+
data[:status] = 'fallback'
|
63
|
+
end
|
64
|
+
|
65
|
+
data
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
end
|
data/lib/tml/ext/array.rb
CHANGED
data/lib/tml/ext/hash.rb
CHANGED
data/lib/tml/language.rb
CHANGED
@@ -54,7 +54,6 @@ class Tml::Language < Tml::Base
|
|
54
54
|
self
|
55
55
|
end
|
56
56
|
|
57
|
-
|
58
57
|
def update_attributes(attrs)
|
59
58
|
super
|
60
59
|
|
@@ -142,7 +141,7 @@ class Tml::Language < Tml::Base
|
|
142
141
|
:translations => []
|
143
142
|
})
|
144
143
|
|
145
|
-
# Tml.logger.info("Translating
|
144
|
+
# Tml.logger.info("Translating #{params[:label]} from: #{translation_key.locale.inspect} to #{locale.inspect}")
|
146
145
|
|
147
146
|
params[:tokens] ||= {}
|
148
147
|
params[:tokens][:viewing_user] ||= Tml.session.current_user
|
@@ -156,16 +155,24 @@ class Tml::Language < Tml::Base
|
|
156
155
|
).tml_translated
|
157
156
|
end
|
158
157
|
|
158
|
+
# if translations have already been cached in the application, use them
|
159
159
|
cached_translations = application.cached_translations(locale, translation_key.key)
|
160
160
|
if cached_translations
|
161
161
|
translation_key.set_translations(locale, cached_translations)
|
162
162
|
return translation_key.translate(self, params[:tokens], params[:options]).tml_translated
|
163
163
|
end
|
164
164
|
|
165
|
+
# each key translations will be loaded directly from the API
|
166
|
+
if Tml.session.block_option(:by_key)
|
167
|
+
translation_key.fetch_translations(locale)
|
168
|
+
return translation_key.translate(self, params[:tokens], params[:options]).tml_translated
|
169
|
+
end
|
170
|
+
|
171
|
+
# fetch translations grouped by source
|
165
172
|
source_key = current_source(options)
|
166
173
|
current_source_path = source_path
|
167
174
|
|
168
|
-
# Dynamic sources are never registered under the parent source
|
175
|
+
# Dynamic sources are never registered under the parent source for fast retrieval
|
169
176
|
if Tml.session.block_option(:dynamic)
|
170
177
|
current_source_path = source_key
|
171
178
|
else
|
data/lib/tml/translation_key.rb
CHANGED
@@ -88,6 +88,40 @@ class Tml::TranslationKey < Tml::Base
|
|
88
88
|
self
|
89
89
|
end
|
90
90
|
|
91
|
+
def self.cache_key(locale, key)
|
92
|
+
File.join(locale, 'keys', key)
|
93
|
+
end
|
94
|
+
|
95
|
+
# update translations in the key
|
96
|
+
def update_translations(locale, data)
|
97
|
+
set_translations(locale, application.cache_translations(
|
98
|
+
locale,
|
99
|
+
key,
|
100
|
+
data.is_a?(Hash) ? data['translations'] : data
|
101
|
+
))
|
102
|
+
end
|
103
|
+
|
104
|
+
# fetch translations for a specific translation key
|
105
|
+
def fetch_translations(locale)
|
106
|
+
self.translations ||= {}
|
107
|
+
return if self.translations[locale]
|
108
|
+
|
109
|
+
# Tml.logger.debug("Fetching translations for #{label}")
|
110
|
+
|
111
|
+
results = self.application.api_client.get(
|
112
|
+
"translation_keys/#{self.key}/translations",
|
113
|
+
{:locale => locale, :per_page => 10000},
|
114
|
+
{:cache_key => Tml::TranslationKey.cache_key(locale, self.key)}
|
115
|
+
) || []
|
116
|
+
|
117
|
+
update_translations(locale, results)
|
118
|
+
|
119
|
+
self
|
120
|
+
rescue Tml::Exception => ex
|
121
|
+
self.translations = {}
|
122
|
+
self
|
123
|
+
end
|
124
|
+
|
91
125
|
###############################################################
|
92
126
|
## Translation Methods
|
93
127
|
###############################################################
|
@@ -100,12 +134,12 @@ class Tml::TranslationKey < Tml::Base
|
|
100
134
|
def find_first_valid_translation(language, token_values)
|
101
135
|
translations = translations_for_language(language)
|
102
136
|
|
103
|
-
translations.sort! { |x,y| x.precedence <=> y.precedence }
|
137
|
+
translations.sort! { |x, y| x.precedence <=> y.precedence }
|
104
138
|
|
105
139
|
translations.each do |translation|
|
106
140
|
return translation if translation.matches_rules?(token_values)
|
107
141
|
end
|
108
|
-
|
142
|
+
|
109
143
|
nil
|
110
144
|
end
|
111
145
|
|
@@ -115,7 +149,7 @@ class Tml::TranslationKey < Tml::Base
|
|
115
149
|
end
|
116
150
|
|
117
151
|
translation = find_first_valid_translation(language, token_values)
|
118
|
-
decorator = Tml::Decorators::Base.decorator
|
152
|
+
decorator = Tml::Decorators::Base.decorator(options)
|
119
153
|
|
120
154
|
if translation
|
121
155
|
options[:locked] = translation.locked
|
@@ -160,7 +194,7 @@ class Tml::TranslationKey < Tml::Base
|
|
160
194
|
|
161
195
|
# if the translations engine is disabled
|
162
196
|
def self.substitute_tokens(label, token_values, language, options = {})
|
163
|
-
return label.to_s if options[:skip_substitution]
|
197
|
+
return label.to_s if options[:skip_substitution]
|
164
198
|
Tml::TranslationKey.new(:label => label.to_s).substitute_tokens(label.to_s, token_values, language, options)
|
165
199
|
end
|
166
200
|
|
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.1
|
4
|
+
version: 5.2.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: 2015-11-
|
11
|
+
date: 2015-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/tml/decorators/base.rb
|
62
62
|
- lib/tml/decorators/default.rb
|
63
63
|
- lib/tml/decorators/html.rb
|
64
|
+
- lib/tml/decorators/json.rb
|
64
65
|
- lib/tml/exception.rb
|
65
66
|
- lib/tml/ext/array.rb
|
66
67
|
- lib/tml/ext/date.rb
|