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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7bc2c8b32d5455a156eebf41a65c19b6a7cbfd9
4
- data.tar.gz: f9ee0897ad9781e22a18dc2ba9aaf3386808e9ce
3
+ metadata.gz: caf33060b73c70df64aaec5d6c65af53e5a79fa5
4
+ data.tar.gz: 8943817182ebd7a933122e8599c44606a02a291c
5
5
  SHA512:
6
- metadata.gz: 47764416ebb9968bd83076755164c8189c803f9bc88d3b491ba27363b954cf1186d7b0a608e9c62b63a89d4510a9d0cd579d65d50bafef2bdf8a6df614f0e502
7
- data.tar.gz: 334d36b8e44bde4865cf36a0eb10e7b58a2f2850990ef0ba090ac215329413d19c1369bf6efeb42f04121278f797f695ea65faeb5022f280153aba649900dde4
6
+ metadata.gz: 9a852cc091ec891903b91ebbd6438e87aedb431146e2b4a73fe0e24a2ee82e771fbe04a989fd0165d21ff1889167b19298f8506f6af856af957e65dfb6f39177
7
+ data.tar.gz: a8063602bb5db4c83ed368281a0a107d5889d62c80a0fd509406a5a589fef30aa65aac308dc1c379c7b2c259e8f64921402ad1203b4d409015562518999c99ee
@@ -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 = nil if locale and locale.strip == ''
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 = locale.gsub('_', '-') if 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 ||= {}
@@ -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
@@ -31,7 +31,7 @@
31
31
  #++
32
32
 
33
33
  module Tml
34
- VERSION = '5.5.0'
34
+ VERSION = '5.5.1'
35
35
 
36
36
  def self.full_version
37
37
  "tml-ruby v#{Tml::VERSION} (Faraday v#{Faraday::VERSION})"
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.0
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-05-17 00:00:00.000000000 Z
11
+ date: 2016-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday