i18n-inflector 2.3.1 → 2.4.0

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.
data.tar.gz.sig CHANGED
Binary file
data/ChangeLog CHANGED
@@ -1,3 +1,15 @@
1
+ commit 6d343ad3137735492e130b7abdd8f86bf23a4a06
2
+ Author: Paweł Wilk <siefca@gnu.org>
3
+ Date: Wed Feb 23 02:20:18 2011 +0100
4
+
5
+ Release 2.4.0
6
+
7
+ commit d8a8354dfa428d649c89157bbcf4f2a4aa2fa74f
8
+ Author: Paweł Wilk <siefca@gnu.org>
9
+ Date: Wed Feb 23 02:19:29 2011 +0100
10
+
11
+ Added collections support
12
+
1
13
  commit ed4cea2f3b809028b02fa19c089fecc7cf56713b
2
14
  Author: Paweł Wilk <siefca@gnu.org>
3
15
  Date: Tue Feb 15 02:39:26 2011 +0100
data/docs/HISTORY CHANGED
@@ -1,3 +1,9 @@
1
+ === 2.4.0 / 2011-02-23
2
+
3
+ * major enhancements
4
+
5
+ * Added nested translations (collections) support
6
+
1
7
  === 2.3.1 / 2011-02-14
2
8
 
3
9
  * major enhancements
@@ -78,19 +78,6 @@ module I18n
78
78
  translated_string = @inflector.key_to_pattern(translated_string)
79
79
  end
80
80
 
81
- # return immediatelly if something is wrong with locale (preventive)
82
- # return if locale is not inflected - return string cleaned from pattern
83
- if (locale.nil? || !@inflector.inflected_locale?(locale))
84
- return translated_string.gsub(InflectorCfg::PATTERN_REGEXP) do
85
- InflectorCfg::Escapes::PATTERN[$1] ? $& : ''
86
- end
87
- end
88
-
89
- # no pattern in a string - return string as is
90
- unless translated_string.include?(InflectorCfg::Markers::PATTERN)
91
- return translated_string
92
- end
93
-
94
81
  # interpolate string
95
82
  begin
96
83
 
@@ -38,8 +38,30 @@ module I18n
38
38
  # that overrides global setting (see: {I18n::Inflector::InflectionOptions#aliased_patterns})
39
39
  # @option options [Boolean] :inflector_cache_aware (false) local switch
40
40
  # that overrides global setting (see: {I18n::Inflector::InflectionOptions#cache_aware})
41
+ # @option options [Boolean] :inflector_traverses (true) local switch
42
+ # that overrides global setting (see: {I18n::Inflector::InflectionOptions#traverses})
41
43
  # @return [String] the string with interpolated patterns
42
44
  def interpolate(string, locale, options = {})
45
+
46
+ # traverse tree and call interpolate for each value
47
+ if string.is_a?(Hash)
48
+ return string unless options[:inflector_traverses]
49
+ return string.merge(string) do |k, v|
50
+ interpolate(v, locale, options)
51
+ end
52
+ end
53
+
54
+ # return immediatelly if something is wrong with locale (preventive)
55
+ # return if locale is not inflected - return string cleaned from pattern
56
+ if (locale.nil? || !inflected_locale?(locale))
57
+ return string.to_s.gsub(PATTERN_REGEXP) do
58
+ Escapes::PATTERN[$1] ? $& : ''
59
+ end
60
+ end
61
+
62
+ # no pattern in a string - return string as is
63
+ return string unless string.to_s.include?(Markers::PATTERN)
64
+
43
65
  interpolate_core(string, locale, options)
44
66
  end
45
67
 
@@ -105,6 +105,22 @@ module I18n
105
105
  # @param [Boolean] state +true+ enables, +false+ disables this switch
106
106
  attr_accessor :aliased_patterns
107
107
 
108
+ # This is a switch that enables you to interpolate patterns contained
109
+ # in resulting nested Hashes. It is used when the original translation
110
+ # method returns a subtree of translation data because the given key
111
+ # is not pointing to a leaf of the data but to some collection.
112
+ #
113
+ # This switch is by default set to +true+. When you turn it off then
114
+ # the Inflector won't touch nested results and will return them as they are.
115
+ #
116
+ # @note Local option +:inflector_traverses+ passed to the
117
+ # {I18n::Backend::Inflector#translate} overrides this setting.
118
+ #
119
+ # @api public
120
+ # @return [Boolean] state of the switch
121
+ # @param [Boolean] state +true+ enables, +false+ disables this switch
122
+ attr_accessor :traverses
123
+
108
124
  # When this switch is set to +true+ then inflector falls back to the default
109
125
  # token for a kind if an inflection option passed to the
110
126
  # {I18n::Backend::Inflector#translate} is unknown or +nil+.
@@ -247,6 +263,7 @@ module I18n
247
263
  # @return [void]
248
264
  def reset
249
265
  @unknown_defaults = true
266
+ @traverses = true
250
267
  @excluded_defaults = false
251
268
  @aliased_patterns = false
252
269
  @cache_aware = false
@@ -14,7 +14,7 @@ module I18n
14
14
  # @private
15
15
  EMAIL = 'pw@gnu.org'
16
16
  # @private
17
- VERSION = '2.3.1'
17
+ VERSION = '2.4.0'
18
18
  # @private
19
19
  NAME = 'i18n-inflector'
20
20
  # @private
@@ -366,6 +366,13 @@ class I18nInflectorTest < Test::Unit::TestCase
366
366
  assert_equal 'Dear Someone!', I18n.t('hi', :gender => :m, :locale => :xx)
367
367
  end
368
368
 
369
+ test "backend inflector translate: works with collections" do
370
+ h = Hash.new
371
+ h[:hi2] = h[:hi] = "Dear Someone!"
372
+ store_translations(:xx, 'welcomes' => {'hi' => 'Dear @{f,m:Someone|n:You|All}!', 'hi2' => 'Dear @{f,m:Someone|n:You|All}!'})
373
+ assert_equal h, I18n.t('welcomes', :gender => :m, :foo => 5, :locale => :xx)
374
+ end
375
+
369
376
  test "backend inflector translate: works with negative tokens" do
370
377
  store_translations(:xx, 'hi' => 'Dear @{!m:Lady|m:Sir|n:You|All}!')
371
378
  assert_equal 'Dear Lady!', I18n.t('hi', :gender => :n, :locale => :xx)
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 2
7
- - 3
8
- - 1
9
- version: 2.3.1
7
+ - 4
8
+ - 0
9
+ version: 2.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Pawe\xC5\x82 Wilk"
@@ -34,7 +34,7 @@ cert_chain:
34
34
  NK3TIZaPCh1S2/ES6wXNvjQ+5EnEEL9j/pSEop9DYEBPaM2WDVR5i0jJTAaRWw==
35
35
  -----END CERTIFICATE-----
36
36
 
37
- date: 2011-02-15 00:00:00 +01:00
37
+ date: 2011-02-23 00:00:00 +01:00
38
38
  default_executable:
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
@@ -202,7 +202,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
202
  requirements:
203
203
  - - ">="
204
204
  - !ruby/object:Gem::Version
205
- hash: -182087839473545551
205
+ hash: -1561613972170107536
206
206
  segments:
207
207
  - 0
208
208
  version: "0"
metadata.gz.sig CHANGED
Binary file