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
35
36
37
38
|
# File 'app/models/copycat_translation.rb', line 10
def self.import_yaml(yaml)
locales = YAML.load(yaml)
locales.each do |locale, translations|
while !translations.empty?
flattened_translations = {}
translations.each_key do |key_component|
translation_or_nesting = translations.delete(key_component)
if translation_or_nesting.is_a?(Hash)
translation_or_nesting.each do |key, value|
flattened_translations["#{key_component}.#{key}"] = value
end
elsif translation_or_nesting.present?
attributes = { key: key_component, locale: locale }
record = where(attributes).first_or_initialize(attributes)
record.value = translation_or_nesting
record.save
end
end
translations.merge!(flattened_translations)
end
end
end
|