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
|
# File 'lib/inertia_i18n/file_converter.rb', line 22
def convert_locale(locale)
config = InertiaI18n.configuration
yaml_files = config.source_paths.flat_map do |path|
Dir.glob(File.join(path, config.source_pattern))
end
merged_data = {}
yaml_files.each do |file|
data = YAML.load_file(file, permitted_classes: [Symbol])
deep_merge!(merged_data, data) if data
rescue Psych::SyntaxError => e
warn "Warning: Failed to parse #{file}: #{e.message}"
end
converter = Converter.new(merged_data, locale: locale)
json_data = converter.convert
output_file = File.join(config.target_path, "#{locale}.json")
FileUtils.mkdir_p(config.target_path)
File.write(output_file, JSON.pretty_generate(json_data) + "\n")
{
locale: locale,
output_file: output_file,
keys_count: LocaleLoader.(json_data).size,
source_files: yaml_files.size
}
end
|