tml 5.5.0 → 5.5.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/application.rb +19 -14
- data/lib/tml/cache_version.rb +7 -0
- data/lib/tml/language.rb +11 -2
- data/lib/tml/session.rb +5 -0
- 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: caf33060b73c70df64aaec5d6c65af53e5a79fa5
|
4
|
+
data.tar.gz: 8943817182ebd7a933122e8599c44606a02a291c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a852cc091ec891903b91ebbd6438e87aedb431146e2b4a73fe0e24a2ee82e771fbe04a989fd0165d21ff1889167b19298f8506f6af856af957e65dfb6f39177
|
7
|
+
data.tar.gz: a8063602bb5db4c83ed368281a0a107d5889d62c80a0fd509406a5a589fef30aa65aac308dc1c379c7b2c259e8f64921402ad1203b4d409015562518999c99ee
|
data/lib/tml/application.rb
CHANGED
@@ -52,6 +52,7 @@ class Tml::Application < Tml::Base
|
|
52
52
|
"#{locale}/translations"
|
53
53
|
end
|
54
54
|
|
55
|
+
# Returns application token
|
55
56
|
def token
|
56
57
|
access_token
|
57
58
|
end
|
@@ -136,12 +137,24 @@ class Tml::Application < Tml::Base
|
|
136
137
|
end
|
137
138
|
end
|
138
139
|
|
140
|
+
# Returns a list of application supported locales
|
141
|
+
def locales
|
142
|
+
@locales ||= languages.collect{|lang| lang.locale}
|
143
|
+
end
|
144
|
+
|
145
|
+
# Returns supported locale or fallback locale
|
146
|
+
def supported_locale(locale)
|
147
|
+
return default_locale if locale.to_s == ''
|
148
|
+
locale = Tml::Language.normalize_locale(locale)
|
149
|
+
unless locales.include?(locale)
|
150
|
+
locale = locale.split('-').first
|
151
|
+
end
|
152
|
+
locales.include?(locale) ? locale : default_locale
|
153
|
+
end
|
154
|
+
|
139
155
|
# Returns language by locale
|
140
156
|
def language(locale = nil)
|
141
|
-
locale =
|
142
|
-
|
143
|
-
locale ||= default_locale || Tml.config.default_locale
|
144
|
-
locale = locale.to_s
|
157
|
+
locale = supported_locale(locale)
|
145
158
|
|
146
159
|
self.languages_by_locale ||= {}
|
147
160
|
self.languages_by_locale[locale] ||= api_client.get("languages/#{locale}/definition", {
|
@@ -157,13 +170,10 @@ class Tml::Application < Tml::Base
|
|
157
170
|
end
|
158
171
|
|
159
172
|
# Normalizes and returns current language
|
173
|
+
# if locale is passed as nil, default locale will be used
|
160
174
|
def current_language(locale)
|
161
175
|
return Tml.config.default_language unless locale
|
162
|
-
locale
|
163
|
-
lang = language(locale)
|
164
|
-
lang ||= language(locale.split('-').first) if locale.index('-')
|
165
|
-
lang ||= Tml.config.default_language
|
166
|
-
lang
|
176
|
+
language(supported_locale(locale)) || Tml.config.default_language
|
167
177
|
end
|
168
178
|
|
169
179
|
# Adds a language to the application
|
@@ -176,11 +186,6 @@ class Tml::Application < Tml::Base
|
|
176
186
|
new_language
|
177
187
|
end
|
178
188
|
|
179
|
-
# Returns a list of application supported locales
|
180
|
-
def locales
|
181
|
-
@locales ||= languages.collect{|lang| lang.locale}
|
182
|
-
end
|
183
|
-
|
184
189
|
# Returns source by key
|
185
190
|
def source(key, locale)
|
186
191
|
self.sources ||= {}
|
data/lib/tml/cache_version.rb
CHANGED
@@ -65,6 +65,13 @@ module Tml
|
|
65
65
|
return 'undefined' unless version['t'].is_a?(Numeric)
|
66
66
|
return version['version'] if cache.read_only?
|
67
67
|
|
68
|
+
# if version check interval is disabled, don't try to check for the new
|
69
|
+
# cache version on the CDN
|
70
|
+
if version_check_interval == -1
|
71
|
+
Tml.logger.debug('Cache version check is disabled')
|
72
|
+
return version['version']
|
73
|
+
end
|
74
|
+
|
68
75
|
expires_at = version['t'] + version_check_interval
|
69
76
|
if expires_at < Time.now.to_i
|
70
77
|
Tml.logger.debug('Cache version is outdated, needs refresh')
|
data/lib/tml/language.rb
CHANGED
@@ -40,11 +40,18 @@ class Tml::Language < Tml::Base
|
|
40
40
|
File.join(locale, 'language')
|
41
41
|
end
|
42
42
|
|
43
|
+
# Supported locales must be of a form en, en-US, az-Cyrl-AZ
|
44
|
+
def self.normalize_locale(locale)
|
45
|
+
parts = locale.split(/[-_]/)
|
46
|
+
return parts.first.downcase if parts.size == 1
|
47
|
+
return [parts.first.downcase, parts.last.upcase].join('-') if parts.size == 2
|
48
|
+
([parts.first.downcase] + parts[1..-2].collect{|part| part.downcase.capitalize} + [parts.first.upcase]).join('-')
|
49
|
+
end
|
50
|
+
|
43
51
|
# Loads language definition from the service
|
44
52
|
def fetch
|
45
53
|
update_attributes(application.api_client.get(
|
46
|
-
"language/#{locale}/definition",
|
47
|
-
{},
|
54
|
+
"language/#{locale}/definition", {},
|
48
55
|
{
|
49
56
|
cache_key: self.class.cache_key(locale)
|
50
57
|
}
|
@@ -73,10 +80,12 @@ class Tml::Language < Tml::Base
|
|
73
80
|
end
|
74
81
|
end
|
75
82
|
|
83
|
+
# Returns context by keyword
|
76
84
|
def context_by_keyword(keyword)
|
77
85
|
hash_value(contexts, keyword)
|
78
86
|
end
|
79
87
|
|
88
|
+
# Returns context by token name
|
80
89
|
def context_by_token_name(token_name)
|
81
90
|
contexts.values.detect{|ctx| ctx.applies_to_token?(token_name)}
|
82
91
|
end
|
data/lib/tml/session.rb
CHANGED
@@ -78,9 +78,14 @@ module Tml
|
|
78
78
|
def preferred_locale(locales)
|
79
79
|
return application.default_locale unless locales
|
80
80
|
locales = locales.is_a?(String) ? locales.split(',') : locales
|
81
|
+
|
81
82
|
locales.each do |locale|
|
83
|
+
locale = Tml::Language.normalize_locale(locale)
|
84
|
+
return locale if application.locales.include?(locale)
|
85
|
+
locale = locale.split('-').first
|
82
86
|
return locale if application.locales.include?(locale)
|
83
87
|
end
|
88
|
+
|
84
89
|
application.default_locale
|
85
90
|
end
|
86
91
|
|
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.5.
|
4
|
+
version: 5.5.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-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|