10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/i18n_accessor.rb', line 10
def i18n_accessor(accessor_name, options={})
scope = options.fetch(:scope) { nil }
key = options.fetch(:key) { nil }
class_name = self.name.underscore
is_active_hash = defined?(ActiveHash::Base) && self.ancestors.include?(ActiveHash::Base)
define_method accessor_name do
unless key
key = if is_active_hash
self.identifier
else
accessor_name
end
end
i18n_path = [
class_name,
key,
scope
].compact.join('.')
I18n.t("#{i18n_path}")
end
end
|