-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalex-i18n.rb
More file actions
32 lines (28 loc) · 796 Bytes
/
alex-i18n.rb
File metadata and controls
32 lines (28 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'yaml'
def add_few_to_other(yaml_data)
if yaml_data.is_a?(Hash)
updated_yaml_data = {}
yaml_data.each do |key, value|
if key == 'other'
updated_yaml_data['few'] = value
updated_yaml_data['many'] = value
updated_yaml_data['other'] = value
else
updated_yaml_data[key] = add_few_to_other(value)
end
end
updated_yaml_data
elsif yaml_data.is_a?(Array)
yaml_data.map { |item| add_few_to_other(item) }
else
yaml_data
end
end
Dir.glob('config/locales/uk.*yml') do |file|
# Load YAML file
yaml_data = YAML.load_file(file)
# Find and add "few" key recursively
updated_yaml_data = add_few_to_other(yaml_data)
# Overwrite same file with updated YAML data
File.write(file, updated_yaml_data.to_yaml)
end