activesupport 2.3.8 → 2.3.9.pre
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activesupport might be problematic. Click here for more details.
- data/CHANGELOG +11 -0
- data/lib/active_support/core_ext/array/grouping.rb +1 -1
- data/lib/active_support/core_ext/array/random_access.rb +24 -4
- data/lib/active_support/core_ext/class.rb +1 -0
- data/lib/active_support/core_ext/class/attribute.rb +67 -0
- data/lib/active_support/core_ext/enumerable.rb +1 -1
- data/lib/active_support/core_ext/kernel/singleton_class.rb +13 -0
- data/lib/active_support/core_ext/module/remove_method.rb +6 -0
- data/lib/active_support/core_ext/object/misc.rb +3 -0
- data/lib/active_support/core_ext/range/blockless_step.rb +1 -1
- data/lib/active_support/core_ext/string/output_safety.rb +0 -11
- data/lib/active_support/dependencies.rb +36 -12
- data/lib/active_support/deprecation.rb +7 -0
- data/lib/active_support/json/backends/yajl.rb +1 -1
- data/lib/active_support/ordered_hash.rb +6 -0
- data/lib/active_support/testing/performance.rb +1 -1
- data/lib/active_support/values/time_zone.rb +5 -1
- data/lib/active_support/vendor.rb +2 -2
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n.rb +92 -105
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/backend.rb +5 -4
- data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/active_record.rb +61 -0
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/backend/active_record/missing.rb +4 -6
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/backend/active_record/store_procs.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/backend/active_record/translation.rb +8 -3
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/backend/base.rb +55 -84
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/backend/cache.rb +1 -0
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/backend/cascade.rb +0 -1
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/backend/chain.rb +3 -1
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/backend/cldr.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/backend/fallbacks.rb +0 -0
- data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/flatten.rb +113 -0
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/backend/gettext.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/backend/interpolation_compiler.rb +8 -4
- data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/key_value.rb +102 -0
- data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/memoize.rb +48 -0
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/backend/metadata.rb +5 -13
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/backend/pluralization.rb +0 -0
- data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/simple.rb +87 -0
- data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/transliterator.rb +98 -0
- data/lib/active_support/vendor/i18n-0.4.1/i18n/config.rb +84 -0
- data/lib/active_support/vendor/i18n-0.4.1/i18n/core_ext/hash.rb +29 -0
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/core_ext/string/interpolate.rb +3 -4
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/exceptions.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/gettext.rb +2 -0
- data/lib/active_support/vendor/{i18n-0.3.7/i18n/helpers/gettext.rb → i18n-0.4.1/i18n/gettext/helpers.rb} +2 -2
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/gettext/po_parser.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/locale.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/locale/fallbacks.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/locale/tag.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/locale/tag/parents.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/locale/tag/rfc4646.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/locale/tag/simple.rb +0 -0
- data/lib/active_support/vendor/i18n-0.4.1/i18n/version.rb +3 -0
- data/lib/active_support/version.rb +1 -1
- data/lib/active_support/whiny_nil.rb +1 -1
- metadata +48 -43
- data/lib/active_support/vendor/i18n-0.3.7/i18n/backend/active_record.rb +0 -66
- data/lib/active_support/vendor/i18n-0.3.7/i18n/backend/fast.rb +0 -69
- data/lib/active_support/vendor/i18n-0.3.7/i18n/backend/helpers.rb +0 -68
- data/lib/active_support/vendor/i18n-0.3.7/i18n/backend/links.rb +0 -34
- data/lib/active_support/vendor/i18n-0.3.7/i18n/backend/simple.rb +0 -22
- data/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/hash/except.rb +0 -8
- data/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/hash/slice.rb +0 -8
- data/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/object/meta_class.rb +0 -5
- data/lib/active_support/vendor/i18n-0.3.7/i18n/helpers.rb +0 -5
- data/lib/active_support/vendor/i18n-0.3.7/i18n/version.rb +0 -3
@@ -0,0 +1,29 @@
|
|
1
|
+
class Hash
|
2
|
+
def slice(*keep_keys)
|
3
|
+
h = {}
|
4
|
+
keep_keys.each { |key| h[key] = fetch(key) }
|
5
|
+
h
|
6
|
+
end unless Hash.method_defined?(:slice)
|
7
|
+
|
8
|
+
def except(*less_keys)
|
9
|
+
slice(*keys - less_keys)
|
10
|
+
end unless Hash.method_defined?(:except)
|
11
|
+
|
12
|
+
def deep_symbolize_keys
|
13
|
+
inject({}) { |result, (key, value)|
|
14
|
+
value = value.deep_symbolize_keys if value.is_a?(Hash)
|
15
|
+
result[(key.to_sym rescue key) || key] = value
|
16
|
+
result
|
17
|
+
}
|
18
|
+
end unless Hash.method_defined?(:deep_symbolize_keys)
|
19
|
+
|
20
|
+
# deep_merge_hash! by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
|
21
|
+
MERGER = proc do |key, v1, v2|
|
22
|
+
Hash === v1 && Hash === v2 ? v1.merge(v2, &MERGER) : v2
|
23
|
+
end
|
24
|
+
|
25
|
+
def deep_merge!(data)
|
26
|
+
merge!(data, &MERGER)
|
27
|
+
end unless Hash.method_defined?(:deep_merge!)
|
28
|
+
end
|
29
|
+
|
data/lib/active_support/vendor/{i18n-0.3.7 → i18n-0.4.1}/i18n/core_ext/string/interpolate.rb
RENAMED
@@ -7,13 +7,13 @@
|
|
7
7
|
You may redistribute it and/or modify it under the same license terms as Ruby.
|
8
8
|
=end
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
begin
|
11
|
+
raise ArgumentError if ("a %{x}" % {:x=>'b'}) != 'a b'
|
12
|
+
rescue ArgumentError
|
12
13
|
# KeyError is raised by String#% when the string contains a named placeholder
|
13
14
|
# that is not contained in the given arguments hash. Ruby 1.9 includes and
|
14
15
|
# raises this exception natively. We define it to mimic Ruby 1.9's behaviour
|
15
16
|
# in Ruby 1.8.x
|
16
|
-
|
17
17
|
class KeyError < IndexError
|
18
18
|
def initialize(message = nil)
|
19
19
|
super(message || "key not found")
|
@@ -24,7 +24,6 @@ if RUBY_VERSION < '1.9'
|
|
24
24
|
#
|
25
25
|
# String#% method which accept "named argument". The translator can know
|
26
26
|
# the meaning of the msgids using "named argument" instead of %s/%d style.
|
27
|
-
|
28
27
|
class String
|
29
28
|
# For older ruby versions, such as ruby-1.8.5
|
30
29
|
alias :bytesize :size unless instance_methods.find {|m| m.to_s == 'bytesize'}
|
File without changes
|
@@ -2,12 +2,12 @@
|
|
2
2
|
require 'i18n/gettext'
|
3
3
|
|
4
4
|
module I18n
|
5
|
-
module
|
5
|
+
module Gettext
|
6
6
|
# Implements classical Gettext style accessors. To use this include the
|
7
7
|
# module to the global namespace or wherever you want to use it.
|
8
8
|
#
|
9
9
|
# include I18n::Helpers::Gettext
|
10
|
-
module
|
10
|
+
module Helpers
|
11
11
|
def gettext(msgid, options = {})
|
12
12
|
I18n.t(msgid, { :default => msgid, :separator => '|' }.merge(options))
|
13
13
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -45,7 +45,7 @@ class NilClass
|
|
45
45
|
def method_missing(method, *args, &block)
|
46
46
|
# Ruby 1.9.2: disallow explicit coercion via method_missing.
|
47
47
|
if method == :to_ary || method == :to_str
|
48
|
-
|
48
|
+
super
|
49
49
|
elsif klass = METHOD_CLASS_MAP[method]
|
50
50
|
raise_nil_warning_for klass, method, caller
|
51
51
|
else
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activesupport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: true
|
5
5
|
segments:
|
6
6
|
- 2
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
|
8
|
+
- 9
|
9
|
+
- pre
|
10
|
+
version: 2.3.9.pre
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- David Heinemeier Hansson
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-08-29 00:00:00 -07:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -58,6 +59,7 @@ files:
|
|
58
59
|
- lib/active_support/core_ext/blank.rb
|
59
60
|
- lib/active_support/core_ext/cgi/escape_skipping_slashes.rb
|
60
61
|
- lib/active_support/core_ext/cgi.rb
|
62
|
+
- lib/active_support/core_ext/class/attribute.rb
|
61
63
|
- lib/active_support/core_ext/class/attribute_accessors.rb
|
62
64
|
- lib/active_support/core_ext/class/delegating_attributes.rb
|
63
65
|
- lib/active_support/core_ext/class/inheritable_attributes.rb
|
@@ -96,6 +98,7 @@ files:
|
|
96
98
|
- lib/active_support/core_ext/kernel/debugger.rb
|
97
99
|
- lib/active_support/core_ext/kernel/reporting.rb
|
98
100
|
- lib/active_support/core_ext/kernel/requires.rb
|
101
|
+
- lib/active_support/core_ext/kernel/singleton_class.rb
|
99
102
|
- lib/active_support/core_ext/kernel.rb
|
100
103
|
- lib/active_support/core_ext/load_error.rb
|
101
104
|
- lib/active_support/core_ext/logger.rb
|
@@ -108,6 +111,7 @@ files:
|
|
108
111
|
- lib/active_support/core_ext/module/introspection.rb
|
109
112
|
- lib/active_support/core_ext/module/loading.rb
|
110
113
|
- lib/active_support/core_ext/module/model_naming.rb
|
114
|
+
- lib/active_support/core_ext/module/remove_method.rb
|
111
115
|
- lib/active_support/core_ext/module/synchronization.rb
|
112
116
|
- lib/active_support/core_ext/module.rb
|
113
117
|
- lib/active_support/core_ext/name_error.rb
|
@@ -214,42 +218,41 @@ files:
|
|
214
218
|
- lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb
|
215
219
|
- lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb
|
216
220
|
- lib/active_support/vendor/builder-2.1.2/builder.rb
|
217
|
-
- lib/active_support/vendor/i18n-0.
|
218
|
-
- lib/active_support/vendor/i18n-0.
|
219
|
-
- lib/active_support/vendor/i18n-0.
|
220
|
-
- lib/active_support/vendor/i18n-0.
|
221
|
-
- lib/active_support/vendor/i18n-0.
|
222
|
-
- lib/active_support/vendor/i18n-0.
|
223
|
-
- lib/active_support/vendor/i18n-0.
|
224
|
-
- lib/active_support/vendor/i18n-0.
|
225
|
-
- lib/active_support/vendor/i18n-0.
|
226
|
-
- lib/active_support/vendor/i18n-0.
|
227
|
-
- lib/active_support/vendor/i18n-0.
|
228
|
-
- lib/active_support/vendor/i18n-0.
|
229
|
-
- lib/active_support/vendor/i18n-0.
|
230
|
-
- lib/active_support/vendor/i18n-0.
|
231
|
-
- lib/active_support/vendor/i18n-0.
|
232
|
-
- lib/active_support/vendor/i18n-0.
|
233
|
-
- lib/active_support/vendor/i18n-0.
|
234
|
-
- lib/active_support/vendor/i18n-0.
|
235
|
-
- lib/active_support/vendor/i18n-0.
|
236
|
-
- lib/active_support/vendor/i18n-0.
|
237
|
-
- lib/active_support/vendor/i18n-0.
|
238
|
-
- lib/active_support/vendor/i18n-0.
|
239
|
-
- lib/active_support/vendor/i18n-0.
|
240
|
-
- lib/active_support/vendor/i18n-0.
|
241
|
-
- lib/active_support/vendor/i18n-0.
|
242
|
-
- lib/active_support/vendor/i18n-0.
|
243
|
-
- lib/active_support/vendor/i18n-0.
|
244
|
-
- lib/active_support/vendor/i18n-0.
|
245
|
-
- lib/active_support/vendor/i18n-0.
|
246
|
-
- lib/active_support/vendor/i18n-0.
|
247
|
-
- lib/active_support/vendor/i18n-0.
|
248
|
-
- lib/active_support/vendor/i18n-0.
|
249
|
-
- lib/active_support/vendor/i18n-0.
|
250
|
-
- lib/active_support/vendor/i18n-0.
|
251
|
-
- lib/active_support/vendor/i18n-0.
|
252
|
-
- lib/active_support/vendor/i18n-0.3.7/i18n.rb
|
221
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/active_record/missing.rb
|
222
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/active_record/store_procs.rb
|
223
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/active_record/translation.rb
|
224
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/active_record.rb
|
225
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/base.rb
|
226
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/cache.rb
|
227
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/cascade.rb
|
228
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/chain.rb
|
229
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/cldr.rb
|
230
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/fallbacks.rb
|
231
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/flatten.rb
|
232
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/gettext.rb
|
233
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/interpolation_compiler.rb
|
234
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/key_value.rb
|
235
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/memoize.rb
|
236
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/metadata.rb
|
237
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/pluralization.rb
|
238
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/simple.rb
|
239
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend/transliterator.rb
|
240
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/backend.rb
|
241
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/config.rb
|
242
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/core_ext/hash.rb
|
243
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/core_ext/string/interpolate.rb
|
244
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/exceptions.rb
|
245
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/gettext/helpers.rb
|
246
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/gettext/po_parser.rb
|
247
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/gettext.rb
|
248
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/locale/fallbacks.rb
|
249
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/locale/tag/parents.rb
|
250
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/locale/tag/rfc4646.rb
|
251
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/locale/tag/simple.rb
|
252
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/locale/tag.rb
|
253
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/locale.rb
|
254
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n/version.rb
|
255
|
+
- lib/active_support/vendor/i18n-0.4.1/i18n.rb
|
253
256
|
- lib/active_support/vendor/memcache-client-1.7.4/memcache.rb
|
254
257
|
- lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone.rb
|
255
258
|
- lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone_info.rb
|
@@ -419,11 +422,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
419
422
|
version: "0"
|
420
423
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
421
424
|
requirements:
|
422
|
-
- - "
|
425
|
+
- - ">"
|
423
426
|
- !ruby/object:Gem::Version
|
424
427
|
segments:
|
425
|
-
-
|
426
|
-
|
428
|
+
- 1
|
429
|
+
- 3
|
430
|
+
- 1
|
431
|
+
version: 1.3.1
|
427
432
|
requirements: []
|
428
433
|
|
429
434
|
rubyforge_project: activesupport
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'i18n/backend/base'
|
2
|
-
require 'i18n/backend/active_record/translation'
|
3
|
-
|
4
|
-
module I18n
|
5
|
-
module Backend
|
6
|
-
class ActiveRecord
|
7
|
-
autoload :Missing, 'i18n/backend/active_record/missing'
|
8
|
-
autoload :StoreProcs, 'i18n/backend/active_record/store_procs'
|
9
|
-
autoload :Translation, 'i18n/backend/active_record/translation'
|
10
|
-
|
11
|
-
include Base, Links
|
12
|
-
|
13
|
-
def reload!
|
14
|
-
end
|
15
|
-
|
16
|
-
def store_translations(locale, data, options = {})
|
17
|
-
separator = options[:separator] || I18n.default_separator
|
18
|
-
wind_keys(data, separator).each do |key, value|
|
19
|
-
store_link(locale, key, value) if value.is_a?(Symbol)
|
20
|
-
Translation.locale(locale).lookup(expand_keys(key, separator), separator).delete_all
|
21
|
-
Translation.create(:locale => locale.to_s, :key => key.to_s, :value => value)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def available_locales
|
26
|
-
begin
|
27
|
-
Translation.available_locales
|
28
|
-
rescue ::ActiveRecord::StatementInvalid
|
29
|
-
[]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
protected
|
34
|
-
|
35
|
-
def lookup(locale, key, scope = [], options = {})
|
36
|
-
return unless key
|
37
|
-
|
38
|
-
separator = options[:separator] || I18n.default_separator
|
39
|
-
|
40
|
-
key = resolve_link(locale, key)
|
41
|
-
key = (Array(scope) + Array(key)).join(separator)
|
42
|
-
result = Translation.locale(locale).lookup(key, separator).all
|
43
|
-
|
44
|
-
if result.empty?
|
45
|
-
return nil
|
46
|
-
elsif result.first.key == key
|
47
|
-
return result.first.value
|
48
|
-
else
|
49
|
-
chop_range = (key.size + separator.size)..-1
|
50
|
-
result = result.inject({}) do |hash, r|
|
51
|
-
hash[r.key.slice(chop_range)] = r.value
|
52
|
-
hash
|
53
|
-
end
|
54
|
-
deep_symbolize_keys(unwind_keys(result, separator))
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# For a key :'foo.bar.baz' return ['foo', 'foo.bar', 'foo.bar.baz']
|
59
|
-
def expand_keys(key, separator = I18n.default_separator)
|
60
|
-
key.to_s.split(separator).inject([]) do |keys, key|
|
61
|
-
keys << [keys.last, key].compact.join(separator)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# The Fast module contains optimizations that can tremendously speed up the
|
4
|
-
# lookup process on the Simple backend. It works by flattening the nested
|
5
|
-
# translation hash to a flat hash (e.g. { :a => { :b => 'c' } } becomes
|
6
|
-
# { :'a.b' => 'c' }).
|
7
|
-
#
|
8
|
-
# To enable these optimizations you can simply include the Fast module to
|
9
|
-
# the Simple backend:
|
10
|
-
#
|
11
|
-
# I18n::Backend::Simple.send(:include, I18n::Backend::Fast)
|
12
|
-
module I18n
|
13
|
-
module Backend
|
14
|
-
module Fast
|
15
|
-
include Links
|
16
|
-
|
17
|
-
def reset_flattened_translations!
|
18
|
-
@flattened_translations = nil
|
19
|
-
end
|
20
|
-
|
21
|
-
def flattened_translations
|
22
|
-
@flattened_translations ||= flatten_translations(translations)
|
23
|
-
end
|
24
|
-
|
25
|
-
def merge_translations(locale, data, options = {})
|
26
|
-
super
|
27
|
-
reset_flattened_translations!
|
28
|
-
end
|
29
|
-
|
30
|
-
def init_translations
|
31
|
-
super
|
32
|
-
reset_flattened_translations!
|
33
|
-
end
|
34
|
-
|
35
|
-
protected
|
36
|
-
def flatten_translations(translations)
|
37
|
-
# don't flatten locale roots
|
38
|
-
translations.inject({}) do |result, (locale, translations)|
|
39
|
-
result[locale] = wind_keys(translations, nil, true)
|
40
|
-
result[locale].each do |key, value|
|
41
|
-
store_link(locale, key, value) if value.is_a?(Symbol)
|
42
|
-
end
|
43
|
-
result
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def lookup(locale, key, scope = nil, options = {})
|
48
|
-
return unless key
|
49
|
-
init_translations unless initialized?
|
50
|
-
|
51
|
-
return nil unless flattened_translations.has_key?(locale.to_sym)
|
52
|
-
|
53
|
-
separator = options[:separator]
|
54
|
-
if separator && I18n.default_separator != separator
|
55
|
-
key = cleanup_non_standard_separator(key, separator)
|
56
|
-
scope = Array(scope).map{|k| cleanup_non_standard_separator(k, separator)} if scope
|
57
|
-
end
|
58
|
-
|
59
|
-
key = resolve_link(locale, key)
|
60
|
-
key = (Array(scope) + [key]).join(I18n.default_separator) if scope
|
61
|
-
flattened_translations[locale.to_sym][key.to_sym]
|
62
|
-
end
|
63
|
-
|
64
|
-
def cleanup_non_standard_separator(key, user_separator)
|
65
|
-
escape_default_separator(key).tr(user_separator, I18n.default_separator)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
module I18n
|
2
|
-
module Backend
|
3
|
-
module Helpers
|
4
|
-
SEPARATOR_ESCAPE_CHAR = "\001"
|
5
|
-
|
6
|
-
# Return a new hash with all keys and nested keys converted to symbols.
|
7
|
-
def deep_symbolize_keys(hash)
|
8
|
-
hash.inject({}) { |result, (key, value)|
|
9
|
-
value = deep_symbolize_keys(value) if value.is_a?(Hash)
|
10
|
-
result[(key.to_sym rescue key) || key] = value
|
11
|
-
result
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
# Flatten keys for nested Hashes by chaining up keys using the separator
|
16
|
-
# >> { "a" => { "b" => { "c" => "d", "e" => "f" }, "g" => "h" }, "i" => "j"}.wind
|
17
|
-
# => { "a.b.c" => "d", "a.b.e" => "f", "a.g" => "h", "i" => "j" }
|
18
|
-
def wind_keys(hash, separator = nil, subtree = false, prev_key = nil, result = {}, orig_hash=hash)
|
19
|
-
separator ||= I18n.default_separator
|
20
|
-
|
21
|
-
hash.each_pair do |key, value|
|
22
|
-
key = escape_default_separator(key, separator)
|
23
|
-
curr_key = [prev_key, key].compact.join(separator).to_sym
|
24
|
-
|
25
|
-
if value.is_a?(Hash)
|
26
|
-
result[curr_key] = value if subtree
|
27
|
-
wind_keys(value, separator, subtree, curr_key, result, orig_hash)
|
28
|
-
else
|
29
|
-
result[unescape_default_separator(curr_key)] = value
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
result
|
34
|
-
end
|
35
|
-
|
36
|
-
def escape_default_separator(key, separator=nil)
|
37
|
-
key.to_s.tr(separator || I18n.default_separator, SEPARATOR_ESCAPE_CHAR)
|
38
|
-
end
|
39
|
-
|
40
|
-
def unescape_default_separator(key, separator=nil)
|
41
|
-
key.to_s.tr(SEPARATOR_ESCAPE_CHAR, separator || I18n.default_separator).to_sym
|
42
|
-
end
|
43
|
-
|
44
|
-
# Expand keys chained by the the given separator through nested Hashes
|
45
|
-
# >> { "a.b.c" => "d", "a.b.e" => "f", "a.g" => "h", "i" => "j" }.unwind
|
46
|
-
# => { "a" => { "b" => { "c" => "d", "e" => "f" }, "g" => "h" }, "i" => "j"}
|
47
|
-
def unwind_keys(hash, separator = ".")
|
48
|
-
result = {}
|
49
|
-
hash.each do |key, value|
|
50
|
-
keys = key.to_s.split(separator)
|
51
|
-
curr = result
|
52
|
-
curr = curr[keys.shift] ||= {} while keys.size > 1
|
53
|
-
curr[keys.shift] = value
|
54
|
-
end
|
55
|
-
result
|
56
|
-
end
|
57
|
-
|
58
|
-
# # Flatten the given array once
|
59
|
-
# def flatten_once(array)
|
60
|
-
# result = []
|
61
|
-
# for element in array # a little faster than each
|
62
|
-
# result.push(*element)
|
63
|
-
# end
|
64
|
-
# result
|
65
|
-
# end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|