tml-rails 5.4.5 → 5.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/i18n/backend/tml.rb +34 -27
- data/lib/tasks/templates/tml.rb +24 -24
- data/lib/tml_rails/extensions/action_controller_extension.rb +10 -6
- data/lib/tml_rails/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: bf3a772c2d881f6862aa2fe6dae70c021d65ed66
|
4
|
+
data.tar.gz: 8dc31a645a9f092905cfb4b0ca8d39db18eccc78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6c56a78acfd2c5144cf3085252ca68182981ad7ea3794ffc4661e8346a6ddd114d633aea3aa0b25f6805d16423572fa67a841212c5b5fe88e30e917ba191608
|
7
|
+
data.tar.gz: 0be0458b0969a2381e1941f00d4a951a9f3653b1c0326f991760b4bdfb97c1db9586c7019a42a4ce03986d5d11942b7ae37161af19d97136eeadbf9ce2f2a0ad
|
data/lib/i18n/backend/tml.rb
CHANGED
@@ -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
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
68
|
-
|
69
|
-
target_language ||= application.language(application.default_locale)
|
73
|
+
hash
|
74
|
+
end
|
70
75
|
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
76
|
-
|
81
|
+
# look up the translation in default locale
|
82
|
+
translation = super(application.default_locale, key, options)
|
77
83
|
|
78
|
-
|
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
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
98
|
+
translation
|
92
99
|
end
|
93
100
|
|
94
101
|
end
|
data/lib/tasks/templates/tml.rb
CHANGED
@@ -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: '
|
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
|
-
:
|
45
|
-
:
|
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
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
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
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
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
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
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
|
-
#
|
83
|
-
#
|
84
|
-
#
|
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
|
-
# :
|
91
|
-
#
|
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.
|
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.
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
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
|
|
data/lib/tml_rails/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|