11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/e9_rails/helpers/translation.rb', line 11
def e9_translate(lookup_key, opts = {})
defaults = []
lookup_key = lookup_key.to_s
if lookup_key.include?(".")
defaults << lookup_key
lookup_key = lookup_key.split('.').last
elsif scope = opts.delete(:scope)
scope = nil if scope.blank?
defaults << (Array.wrap(scope) << lookup_key).compact.join('.')
elsif default = opts.delete(:default)
defaults << default
end
defaults << [controller_path.gsub(/\//, '.'), lookup_key].join('.')
defaults << lookup_key
defaults.map! {|default| [:e9, default].join('.').gsub(/\.+/, '.').to_sym }
defaults.uniq!
lookup_key = defaults.shift
begin
model_name = (opts.delete(:resource_class) || resource_class).model_name
opts.reverse_merge!(
:model => model_name.human,
:models => model_name.human.pluralize,
:collection => model_name.collection,
:element => model_name.element
)
rescue
end
::I18n.translate(lookup_key, opts.merge(:default => defaults))
end
|