tr8n_core 4.0.16 → 4.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tr8n/decorators/html.rb +8 -2
- data/lib/tr8n/language.rb +3 -2
- data/lib/tr8n/session.rb +17 -0
- data/lib/tr8n/tokenizers/dom.rb +1 -1
- data/lib/tr8n/translator.rb +4 -0
- data/lib/tr8n_core/ext/date.rb +1 -1
- data/lib/tr8n_core/ext/string.rb +2 -2
- data/lib/tr8n_core/ext/time.rb +1 -1
- data/lib/tr8n_core/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: 470f4942f0fab2b30f5a0d7b712ae1a23794303c
|
4
|
+
data.tar.gz: b7066bedabf3daa74aaad31d11ca3cb8bf76b45b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d17fb49dd55b1f0fd6e6798060dc6e90694f3e77bec6771fa00ef41aae6b0b446a4e6f331db0ee0f67a0b99890a7085c6a1d502160c52cfb37a18da3967425f
|
7
|
+
data.tar.gz: 86a847db7c7af547f2c036d3b38c0eb2c51bd13b3310cfc2f565f9f2997c01f0768b61348f951699ecb482346ce643a048442a410a9c92cb12dbcb6be429c8c0
|
data/lib/tr8n/decorators/html.rb
CHANGED
@@ -33,6 +33,7 @@
|
|
33
33
|
class Tr8n::Decorators::Html < Tr8n::Decorators::Base
|
34
34
|
|
35
35
|
def decorate(translated_label, translation_language, target_language, translation_key, options = {})
|
36
|
+
# Tr8n.logger.info("Decorating #{translated_label} of #{translation_language.locale} to #{target_language.locale}")
|
36
37
|
# skip decoration if instructed so
|
37
38
|
return translated_label if options[:skip_decorations]
|
38
39
|
# if translation key language is the same as target language - skip decorations
|
@@ -41,7 +42,12 @@ class Tr8n::Decorators::Html < Tr8n::Decorators::Base
|
|
41
42
|
return translated_label if translation_key.locked? and not Tr8n.session.current_translator.manager?
|
42
43
|
|
43
44
|
element = 'tr8n:tr'
|
44
|
-
|
45
|
+
if options[:use_div]
|
46
|
+
element = 'div'
|
47
|
+
elsif options[:use_span]
|
48
|
+
element = 'span'
|
49
|
+
end
|
50
|
+
|
45
51
|
classes = ['tr8n_translatable']
|
46
52
|
|
47
53
|
if translation_key.locked?
|
@@ -56,7 +62,7 @@ class Tr8n::Decorators::Html < Tr8n::Decorators::Base
|
|
56
62
|
classes << 'tr8n_fallback'
|
57
63
|
end
|
58
64
|
|
59
|
-
html = "<#{element} class='#{classes.join(' ')}' data-translation_key='#{translation_key.key}'>"
|
65
|
+
html = "<#{element} class='#{classes.join(' ')}' data-translation_key='#{translation_key.key}' data-target_locale='#{target_language.locale}'>"
|
60
66
|
html << translated_label
|
61
67
|
html << "</#{element}>"
|
62
68
|
html
|
data/lib/tr8n/language.rb
CHANGED
@@ -129,9 +129,10 @@ class Tr8n::Language < Tr8n::Base
|
|
129
129
|
:translations => []
|
130
130
|
})
|
131
131
|
|
132
|
-
#Tr8n.logger.info("Translating " + params[:label] + " from: " +
|
132
|
+
# Tr8n.logger.info("Translating " + params[:label] + " from: " + translation_key.locale.inspect + " to " + locale.inspect)
|
133
133
|
|
134
|
-
params[:tokens]
|
134
|
+
params[:tokens] ||= {}
|
135
|
+
params[:tokens][:viewing_user] ||= Tr8n.session.current_user
|
135
136
|
|
136
137
|
if Tr8n.config.disabled? or self.locale == translation_key.locale
|
137
138
|
return translation_key.substitute_tokens(
|
data/lib/tr8n/session.rb
CHANGED
@@ -70,6 +70,23 @@ module Tr8n
|
|
70
70
|
def application
|
71
71
|
@application ||= Tr8n::Application.new(:host => Tr8n::ApiClient::API_HOST)
|
72
72
|
end
|
73
|
+
|
74
|
+
def source_language
|
75
|
+
arr = @block_options || []
|
76
|
+
arr.reverse.each do |opts|
|
77
|
+
return application.language(opts[:locale]) unless opts[:locale].blank?
|
78
|
+
end
|
79
|
+
application.language
|
80
|
+
end
|
81
|
+
|
82
|
+
def target_language
|
83
|
+
arr = @block_options || []
|
84
|
+
arr.reverse.each do |opts|
|
85
|
+
return application.language(opts[:target_locale]) unless opts[:target_locale].blank?
|
86
|
+
end
|
87
|
+
current_language
|
88
|
+
end
|
89
|
+
|
73
90
|
#########################################################
|
74
91
|
## Block Options
|
75
92
|
#########################################################
|
data/lib/tr8n/tokenizers/dom.rb
CHANGED
@@ -114,7 +114,7 @@ module Tr8n
|
|
114
114
|
|
115
115
|
tml = tml.gsub(/[\n]/, '').gsub(/\s\s+/, ' ').strip
|
116
116
|
|
117
|
-
translation = option('debug') ? debug_translation(tml) : Tr8n.session.
|
117
|
+
translation = option('debug') ? debug_translation(tml) : Tr8n.session.target_language.translate(tml, tokens, options)
|
118
118
|
reset_context
|
119
119
|
translation
|
120
120
|
end
|
data/lib/tr8n/translator.rb
CHANGED
data/lib/tr8n_core/ext/date.rb
CHANGED
@@ -48,7 +48,7 @@ class Date
|
|
48
48
|
# The last allows you to use language cases to get something like "on March 1st".
|
49
49
|
|
50
50
|
def translate(format = :default, options = {})
|
51
|
-
language = Tr8n.session.
|
51
|
+
language = Tr8n.session.target_language
|
52
52
|
|
53
53
|
label = (format.is_a?(String) ? format.clone : Tr8n.config.default_date_formats[format].clone)
|
54
54
|
|
data/lib/tr8n_core/ext/string.rb
CHANGED
@@ -32,13 +32,13 @@
|
|
32
32
|
class String
|
33
33
|
|
34
34
|
def translate(desc = '', tokens = {}, options = {})
|
35
|
-
Tr8n.session.
|
35
|
+
Tr8n.session.target_language.translate(
|
36
36
|
Tr8n::Utils.normalize_tr_params(self, desc, tokens, options)
|
37
37
|
)
|
38
38
|
end
|
39
39
|
|
40
40
|
def trl(desc = '', tokens = {}, options = {})
|
41
|
-
Tr8n.session.
|
41
|
+
Tr8n.session.target_language.translate(
|
42
42
|
Tr8n::Utils.normalize_tr_params(self, desc, tokens, options.merge(:skip_decorations => true))
|
43
43
|
)
|
44
44
|
end
|
data/lib/tr8n_core/ext/time.rb
CHANGED
@@ -32,7 +32,7 @@
|
|
32
32
|
class Time
|
33
33
|
|
34
34
|
def translate(format = :default, options = {})
|
35
|
-
language = Tr8n.session.
|
35
|
+
language = Tr8n.session.target_language
|
36
36
|
|
37
37
|
label = (format.is_a?(String) ? format.clone : Tr8n.config.default_date_formats[format].clone)
|
38
38
|
symbols = label.scan(/(%\w)/).flatten.uniq
|
data/lib/tr8n_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tr8n_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Berkovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|