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
|
# File 'lib/ab_admin/i18n_tools/model_translator.rb', line 14
def make_hash
@locales.each do |locale|
I18n.with_locale(locale) do
@models_i18n_hash[locale] = {'activerecord' => {'attributes' => {}, 'models' => {}}}
models_hash = @models.each_with_object({}) do |model, h|
model_i18n = {
'zero' => model.model_name.human(count: 0),
'one' => model.model_name.human(count: 1),
'few' => (model.model_name.human(count: 2) rescue model.model_name.human(count: 1)),
'many' => (model.model_name.human(count: 9) rescue model.model_name.human(count: 1)),
'other' => (model.model_name.human(count: 9) rescue model.model_name.human(count: 1))
}
@models_i18n_hash[locale]['activerecord']['models'][model.model_name.i18n_key.to_s]= model_i18n
attributes = model.columns.map(&:name)
attributes.concat(model.translated_attribute_names.map(&:to_s)) if model.try!(:translates?)
attributes.reject! { |el| IGNORE_COLUMNS.include?(el) }
h[model.model_name.i18n_key.to_s] = attributes.each_with_object({}) do |attr, o|
o[attr] = ha(model, attr, locale).presence || attr
model.reflect_on_all_associations.map(&:name).map(&:to_s).reject { |a| a =~ /^translation/ }.each do |assoc|
o[assoc] = ha(model, assoc, locale)
end
if model.new.respond_to?("#{attr}_#{locale.to_s}".to_sym)
@locales.each do |locale_1|
attr_suffix = I18n.t(locale_1, scope: [:attrs], default: locale_1.to_s.humanize)
o["#{attr}_#{locale_1.to_s}"] = "#{ha(model, attr, locale)} (#{attr_suffix})"
end
end
end.sort.to_h
end
@models_i18n_hash[locale]['activerecord']['attributes'] = models_hash
end
end
end
|