tr8n_core 4.0.12 → 4.0.13

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: a984c2942575807bbf4d7e6b3b340ce2c2428020
4
- data.tar.gz: 5cd3e83a8c544fb42a390a9218b1350f4ba66d01
3
+ metadata.gz: dca2df7d8abff227fe6cd78b14724655e1e111a0
4
+ data.tar.gz: d96499b858853cb354e8bc0f518fc92fe58e37df
5
5
  SHA512:
6
- metadata.gz: 936c126d175de897ac02f4635c6052db44f4314ec3ed745d4e2a150b5ecc99514f1f64e54d8e58735a85f3dbc5a4a290fd9e3d4162923b67c3a36cf38a77435d
7
- data.tar.gz: 91c3092764f4a26a38d9a0b731daac3b1fe686b257a3b53d62889b7c735d6fa47edb771b134a755fcfc6e9d1490caeb8ff16604886eaee55e9adca95b64d9815
6
+ metadata.gz: fe7f3e60226a364b1f95e9876bfcf60a229ea3d5c39f0fe956faeb64a1daa95968e75f1ad8287e04529d51c81c5345d8e9f0157314e419716e16e3c0efaad45b
7
+ data.tar.gz: 3a4308861adb7328031deb12d362026d8c57e8b04cf1fac065050b105a155cc352db6c82d99103f1db78c2f0ffe27ba04056fba462e2b03ffa5a1461110531e3
data/lib/tr8n/language.rb CHANGED
@@ -117,9 +117,8 @@ class Tr8n::Language < Tr8n::Base
117
117
  ########################################################################################################
118
118
 
119
119
  def translate(label, description = nil, tokens = {}, options = {})
120
- return label if label.tr8n_translated?
121
-
122
120
  params = Tr8n::Utils.normalize_tr_params(label, description, tokens, options)
121
+ return params[:label] if params[:label].tr8n_translated?
123
122
 
124
123
  translation_key = Tr8n::TranslationKey.new({
125
124
  :application => application,
@@ -145,7 +144,9 @@ class Tr8n::Language < Tr8n::Base
145
144
 
146
145
  # should this be done only for testing?
147
146
  cached_key = application.translation_key(translation_key.key)
148
- return cached_key.translate(self, params[:tokens], params[:options]) if cached_key
147
+ if cached_key
148
+ return cached_key.translate(self, params[:tokens], params[:options]).tr8n_translated
149
+ end
149
150
 
150
151
  source_key = current_source(options)
151
152
  source = application.source(source_key, locale)
@@ -32,27 +32,34 @@
32
32
  class Array
33
33
 
34
34
  # translates an array of options for a select tag
35
- def tro(description = "", options = {}, language = Tr8n.session.current_language)
35
+ def tro(description = '', options = {})
36
36
  return [] if empty?
37
37
 
38
+ options = options.merge(:skip_decorations => true)
39
+
38
40
  collect do |opt|
39
41
  if opt.is_a?(Array) and opt.first.is_a?(String)
40
- [opt.first.trl(description, {}, options, language), opt.last]
42
+ [opt.first.translate(description, {}, options), opt.last]
41
43
  elsif opt.is_a?(String)
42
- [opt.trl(description, {}, options, language), opt]
44
+ [opt.translate(description, {}, options), opt]
43
45
  else
44
46
  opt
45
47
  end
46
48
  end
47
49
  end
48
50
 
51
+ # translates and joins all elements
52
+ def translated_and_join(separator = '', description = '', options = {})
53
+ self.translate(description, options).join(separator).tr8n_translated
54
+ end
55
+
49
56
  # translate array values
50
- def trl(description = "", options = {}, language = Tr8n.session.current_language)
57
+ def translate(description = '', options = {})
51
58
  return [] if empty?
52
59
 
53
60
  collect do |opt|
54
61
  if opt.is_a?(String)
55
- opt.trl(description, {}, options, language)
62
+ opt.translate(description, {}, options)
56
63
  else
57
64
  opt
58
65
  end
@@ -60,23 +67,20 @@ class Array
60
67
  end
61
68
 
62
69
  # creates a sentence with tr "and" joiner
63
- def tr_sentence(options = {}, language = Tr8n.session.current_language)
70
+ def translate_sentence(description = '', options = {})
64
71
  return "" if empty?
65
72
  return first if size == 1
66
73
 
67
- result = "#{self[0..-2].join(", ")}"
68
- result << " " << "and".translate("List elements joiner", {}, options, language) << " "
69
- result << self.last
70
- end
74
+ elements = translate(description, options)
71
75
 
72
- def tr8n_translated
73
- return self if frozen?
74
- @tr8n_translated = true
75
- self
76
- end
76
+ options[:separator] ||= ', '
77
+ options[:joiner] ||= 'and'
78
+
79
+ result = elements[0..-2].join(options[:separator])
80
+ result << ' ' << options[:joiner].translate('List elements joiner', {}, options) << ' '
81
+ result << elements.last
77
82
 
78
- def tr8n_translated?
79
- @tr8n_translated
83
+ result.tr8n_translated
80
84
  end
81
85
 
82
86
  end
@@ -47,7 +47,9 @@ class Date
47
47
  #
48
48
  # The last allows you to use language cases to get something like "on March 1st".
49
49
 
50
- def translate(format = :default, language = Tr8n.session.current_language, options = {})
50
+ def translate(format = :default, options = {})
51
+ language = Tr8n.session.current_language
52
+
51
53
  label = (format.is_a?(String) ? format.clone : Tr8n.config.default_date_formats[format].clone)
52
54
 
53
55
  selected_tokens = []
@@ -90,7 +92,7 @@ class Date
90
92
  end
91
93
  alias :tr :translate
92
94
 
93
- def trl(format = :default, language = Tr8n.session.current_language, options = {})
94
- tr(format, language, options.merge!(:skip_decorations => true))
95
+ def trl(format = :default, options = {})
96
+ tr(format, options.merge!(:skip_decorations => true))
95
97
  end
96
98
  end
@@ -35,13 +35,13 @@ class Fixnum
35
35
  (to_i < 10 ? "0#{to_s}" : to_s)
36
36
  end
37
37
 
38
- def translate(desc = "", tokens = {}, options = {}, language = Tr8n.session.current_language)
39
- to_s.translate(desc, tokens, options, language)
38
+ def translate(desc = "", tokens = {}, options = {})
39
+ to_s.translate(desc, tokens, options)
40
40
  end
41
41
  alias tr translate
42
42
 
43
- def trl(desc = "", tokens = {}, options = {}, language = Tr8n.session.current_language)
44
- to_s.trl(desc, tokens, options, language)
43
+ def trl(desc = "", tokens = {}, options = {})
44
+ to_s.trl(desc, tokens, options)
45
45
  end
46
46
 
47
47
  end
@@ -30,18 +30,7 @@
30
30
  #++
31
31
 
32
32
  class Hash
33
-
34
- def tr8n_translated
35
- return self if frozen?
36
- @tr8n_translated = true
37
- self
38
- end
39
-
40
- def tr8n_translated?
41
- @tr8n_translated
42
- end
43
-
44
- #
33
+ #
45
34
  # = Hash Recursive Merge
46
35
  #
47
36
  # Merges a Ruby Hash recursively, Also known as deep merge.
@@ -31,12 +31,16 @@
31
31
 
32
32
  class String
33
33
 
34
- def translate(desc = "", tokens = {}, options = {}, language = Tr8n.session.current_language)
35
- language.translate(self, desc, tokens, options)
34
+ def translate(desc = '', tokens = {}, options = {})
35
+ Tr8n.session.current_language.translate(
36
+ Tr8n::Utils.normalize_tr_params(self, desc, tokens, options)
37
+ )
36
38
  end
37
39
 
38
- def trl(desc = "", tokens = {}, options = {}, language = Tr8n.session.current_language)
39
- translate(desc, tokens, options.merge(:skip_decorations => true), language)
40
+ def trl(desc = '', tokens = {}, options = {})
41
+ Tr8n.session.current_language.translate(
42
+ Tr8n::Utils.normalize_tr_params(self, desc, tokens, options.merge(:skip_decorations => true))
43
+ )
40
44
  end
41
45
 
42
46
  def tr8n_translated
@@ -31,7 +31,9 @@
31
31
 
32
32
  class Time
33
33
 
34
- def translate(format = :default, language = Tr8n.session.current_language, options = {})
34
+ def translate(format = :default, options = {})
35
+ language = Tr8n.session.current_language
36
+
35
37
  label = (format.is_a?(String) ? format.clone : Tr8n.config.default_date_formats[format].clone)
36
38
  symbols = label.scan(/(%\w)/).flatten.uniq
37
39
 
@@ -78,8 +80,8 @@ class Time
78
80
  end
79
81
  alias :tr :translate
80
82
 
81
- def trl(format = :default, language = Tr8n.session.current_language, options = {})
82
- tr(format, language, options.merge!(:skip_decorations => true))
83
+ def trl(format = :default, options = {})
84
+ tr(format, options.merge!(:skip_decorations => true))
83
85
  end
84
86
 
85
87
  end
@@ -30,5 +30,5 @@
30
30
  #++
31
31
 
32
32
  module Tr8nCore
33
- VERSION = '4.0.12'
33
+ VERSION = '4.0.13'
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.12
4
+ version: 4.0.13
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-08-26 00:00:00.000000000 Z
11
+ date: 2014-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0.9'
19
+ version: '0.8'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '0.9'
26
+ version: '0.8'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '1.6'
33
+ version: '1.5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '1.6'
40
+ version: '1.5'
41
41
  description: Tr8n core classes that can be used by any Ruby framework
42
42
  email:
43
43
  - michael@tr8nhub.com