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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f42d555219e71bb58c86535e4a8c992e3343032
4
- data.tar.gz: a11497c6e6f55880a9c73132130051d4401228c1
3
+ metadata.gz: 470f4942f0fab2b30f5a0d7b712ae1a23794303c
4
+ data.tar.gz: b7066bedabf3daa74aaad31d11ca3cb8bf76b45b
5
5
  SHA512:
6
- metadata.gz: 5146a1907d0e0685615814e640f1a07b02d091c4f5f184a6e79a7b844cfe55a0cb552296302120a8374a531e8d0467a45199dbc63110a1d71a43d0ca37720d7c
7
- data.tar.gz: 352115940aba499f2ea752c5a9c980e2f51cb66c4ae49f6c7a74af6fade8138f299c6b79b53aec8ff9679f8c4bd336e37b6f6c7d7c2265b5e3dc0abfb77ebbe4
6
+ metadata.gz: 2d17fb49dd55b1f0fd6e6798060dc6e90694f3e77bec6771fa00ef41aae6b0b446a4e6f331db0ee0f67a0b99890a7085c6a1d502160c52cfb37a18da3967425f
7
+ data.tar.gz: 86a847db7c7af547f2c036d3b38c0eb2c51bd13b3310cfc2f565f9f2997c01f0768b61348f951699ecb482346ce643a048442a410a9c92cb12dbcb6be429c8c0
@@ -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
- element = 'div' if options[:use_div]
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: " + key_locale.inspect + " to " + locale.inspect)
132
+ # Tr8n.logger.info("Translating " + params[:label] + " from: " + translation_key.locale.inspect + " to " + locale.inspect)
133
133
 
134
- params[:tokens].merge!(:viewing_user => Tr8n.session.current_user)
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
  #########################################################
@@ -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.current_language.translate(tml, tokens, options)
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
@@ -68,4 +68,8 @@ class Tr8n::Translator < Tr8n::Base
68
68
  "http://gravatar.com/avatar/#{gravatar_id}.png?s=48"
69
69
  end
70
70
 
71
+ def inline?
72
+ return Tr8n.session.block_options[:inline] unless Tr8n.session.block_options[:inline].nil?
73
+ super
74
+ end
71
75
  end
@@ -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.current_language
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
 
@@ -32,13 +32,13 @@
32
32
  class String
33
33
 
34
34
  def translate(desc = '', tokens = {}, options = {})
35
- Tr8n.session.current_language.translate(
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.current_language.translate(
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
@@ -32,7 +32,7 @@
32
32
  class Time
33
33
 
34
34
  def translate(format = :default, options = {})
35
- language = Tr8n.session.current_language
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
@@ -30,5 +30,5 @@
30
30
  #++
31
31
 
32
32
  module Tr8nCore
33
- VERSION = '4.0.16'
33
+ VERSION = '4.0.17'
34
34
  end
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.16
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-17 00:00:00.000000000 Z
11
+ date: 2014-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday