tml-rails 5.4.5 → 5.4.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3676748ce4f93018dd2a75c7990cea547c0e663
4
- data.tar.gz: 6a5235f0a7f3881acff7b34538783f9aa9fa7260
3
+ metadata.gz: bf3a772c2d881f6862aa2fe6dae70c021d65ed66
4
+ data.tar.gz: 8dc31a645a9f092905cfb4b0ca8d39db18eccc78
5
5
  SHA512:
6
- metadata.gz: b7fd3487544b74d680dfae6192372054969f515811018d93f5babd483c6a82bf37238e83652b32401e76ac84f07f8557ab1d5b264f110077bc93b9f8590f0d8d
7
- data.tar.gz: 15a714c0c4ef2ba37858618b2802c30f882fa024010fa1d051b745ee02448ec756ac03f3a0ccd3d2fee169b3a79a58df0fcf553afb6ef0a0b8555332b65febc2
6
+ metadata.gz: d6c56a78acfd2c5144cf3085252ca68182981ad7ea3794ffc4661e8346a6ddd114d633aea3aa0b25f6805d16423572fa67a841212c5b5fe88e30e917ba191608
7
+ data.tar.gz: 0be0458b0969a2381e1941f00d4a951a9f3653b1c0326f991760b4bdfb97c1db9586c7019a42a4ce03986d5d11942b7ae37161af19d97136eeadbf9ce2f2a0ad
@@ -40,55 +40,62 @@ module I18n
40
40
  module Implementation
41
41
  include Base, Flatten
42
42
 
43
+ # Returns current application
43
44
  def application
44
45
  ::Tml.session.application
45
46
  end
46
47
 
48
+ # List of all application available locales
47
49
  def available_locales
48
50
  application.locales
49
51
  end
50
52
 
51
- def translate(locale, key, options = {})
52
- translation = super(locale, key, options)
53
- translation.is_a?(String) ? translation.html_safe : translation
53
+ # we will capture interpolation here - so we can process it ourselves using TML
54
+ def interpolate(locale, string, values = {})
55
+ string
54
56
  end
55
57
 
58
+ # TODO: this should be configurable. Our SDK supports both notations.
56
59
  def convert_to_tml(str)
57
60
  str.gsub('%{', '{')
58
61
  end
59
62
 
60
- def lookup(locale, key, scope = [], options = {})
61
- # pp [locale, key, scope, options]
62
-
63
- if key.to_s.match(/^(support|i18n|number|human|distance)/)
64
- return super(locale, key, scope, options)
63
+ # Translates a hash of values
64
+ def translate_hash(target_language, hash, options)
65
+ hash.each do |key, value|
66
+ if value.is_a?(String)
67
+ hash[key] = target_language.translate(convert_to_tml(value), options, options)
68
+ elsif value.is_a?(Hash)
69
+ translate_hash(target_language, value, options)
70
+ end
65
71
  end
66
72
 
67
- # if language is not available, return default value
68
- target_language = application.language(locale.to_s)
69
- target_language ||= application.language(application.default_locale)
73
+ hash
74
+ end
70
75
 
71
- unless target_language
72
- return super(locale, key, scope, options)
73
- end
76
+ # Translates a string
77
+ def translate(locale, key, options = {})
78
+ # TODO: we don't support this yet - but we should
79
+ return super if I18n.locale != locale
74
80
 
75
- default_key = super(application.default_locale, key, scope, options)
76
- default_key ||= key.to_s.split('.').last.gsub('_', ' ').capitalize
81
+ # look up the translation in default locale
82
+ translation = super(application.default_locale, key, options)
77
83
 
78
- if default_key.is_a?(String)
79
- translated_key = target_language.translate(convert_to_tml(default_key), options, options)
80
- elsif default_key.is_a?(Hash)
81
- translated_key = {}
84
+ # pp [locale, key, options, translation]
82
85
 
83
- default_key.each do |key, value|
84
- if value.is_a?(String)
85
- value = target_language.translate(convert_to_tml(value), options, options)
86
- end
87
- translated_key[key] = value
88
- end
86
+ # if no translation is available, ignore it
87
+ return translation if translation.nil? or translation == ''
88
+
89
+ # if language is not available, return default value
90
+ target_language = application.language(locale.to_s)
91
+
92
+ if translation.is_a?(String)
93
+ translation = target_language.translate(convert_to_tml(translation), options, options)
94
+ elsif translation.is_a?(Hash)
95
+ translation = translate_hash(target_language, translation, options)
89
96
  end
90
97
 
91
- translated_key
98
+ translation
92
99
  end
93
100
 
94
101
  end
@@ -31,64 +31,64 @@
31
31
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
32
  #++
33
33
 
34
+ # If you are already using I18n or want to use it in parallel, set I18n::Backend::Tml as the backend
34
35
  I18n.backend = I18n::Backend::Tml.new
35
36
 
36
37
  Tml.configure do |config|
38
+
37
39
  config.application = {
38
- key: 'YOUR KEY'
40
+ key: 'YOUR_APPLICATION_KEY'
39
41
  }
40
42
 
41
43
  # If you are using Rails.cache, use the following settings:
42
44
 
43
45
  config.cache = {
44
- :enabled => true,
45
- :adapter => :rails
46
+ enabled: true,
47
+ adapter: :rails
46
48
  }
47
49
 
48
50
  # If you are using File based pre-generated cache, use the following settings:
49
51
 
50
52
  #config.cache = {
51
- # :enabled => true,
52
- # :adapter => 'file',
53
- # :path => 'config/tml',
54
- # :version => 'current',
55
- # :segmented => false
53
+ # enabled: true,
54
+ # adapter: 'file',
55
+ # path: File.join(Rails.root, :config, :tml),
56
+ # version: 'current',
57
+ # segmented: false
56
58
  #}
57
59
 
58
60
  # If you are using Redis, use the following settings:
59
61
 
60
62
  #config.cache = {
61
- # :enabled => true,
62
- # :adapter => 'redis',
63
- # :host => 'localhost',
64
- # :port => 6379,
65
- # :db => 0,
66
- # :namespace => 'translations',
63
+ # enabled: true,
64
+ # adapter: 'redis',
65
+ # host: 'localhost',
66
+ # port: 6379,
67
+ # namespace: 'translations',
67
68
  #}
68
69
 
69
70
  # If you are using Memcache, use the following settings:
70
71
 
71
72
  #config.cache = {
72
- # :enabled => true,
73
- # :adapter => 'memcache',
74
- # :host => 'localhost:11211',
75
- # :version => 1,
76
- # :namespace => 'translations',
73
+ # enabled: true,
74
+ # adapter: 'memcache',
75
+ # host: 'localhost:11211',
76
+ # namespace: 'translations',
77
77
  #}
78
78
 
79
79
  # For debugging, uncomment the following lines:
80
80
 
81
81
  #config.logger = {
82
- # :enabled => true,
83
- # :path => "#{Rails.root}/log/tml.log",
84
- # :level => 'debug'
82
+ # enabled: true,
83
+ # path: File.join(Rails.root, :log, 'tml.log'),
84
+ # level: 'debug'
85
85
  #}
86
86
 
87
87
  # To use Rails logger instead, use:
88
88
 
89
89
  #config.logger = {
90
- # :enabled => true,
91
- # :type => :rails
90
+ # enabled: true,
91
+ # type: :rails
92
92
  #}
93
93
 
94
94
  end
@@ -98,7 +98,9 @@ module TmlRails
98
98
  locale = tml_cookie[:locale]
99
99
  if locale.nil?
100
100
  if Tml.config.locale[:subdomain]
101
- locale = request.subdomain
101
+ locale = request.subdomains.first
102
+ elsif Tml.config.locale[:tld]
103
+ locale = request.host.split('.').last
102
104
  else
103
105
  locale = tml_browser_accepted_locales
104
106
  end
@@ -154,11 +156,13 @@ module TmlRails
154
156
  :access_token => tml_access_token
155
157
  )
156
158
 
157
- if I18n.backend.class.name == 'I18n::Backend::Tml'
158
- if defined? I18n.enforce_available_locales
159
- I18n.enforce_available_locales = false
160
- end
161
- I18n.locale = Tml.session.current_language.locale
159
+ if defined? I18n.enforce_available_locales
160
+ I18n.enforce_available_locales = false
161
+ end
162
+ I18n.locale = Tml.session.current_language.locale
163
+
164
+ if tml_current_translator and tml_current_translator.inline?
165
+ I18n.reload!
162
166
  end
163
167
  end
164
168
 
@@ -30,5 +30,5 @@
30
30
  #++
31
31
 
32
32
  module TmlRails
33
- VERSION = '5.4.5'
33
+ VERSION = '5.4.6'
34
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tml-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.4.5
4
+ version: 5.4.6
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-06-03 00:00:00.000000000 Z
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails