Skip to content

Commit 000fde4

Browse files
committed
Refactor download and process Rails locale files
Adds a new command line task to download the latest Rails locale files. This task also merges and normalizes the files, allowing us to easily compare them with the existing translations. To run the task: thor locales:normalize_from_rails
1 parent 955a47c commit 000fde4

File tree

7 files changed

+471
-14
lines changed

7 files changed

+471
-14
lines changed

locales.thor

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,45 @@ class Locales < Thor
7474
end
7575
end
7676

77+
desc 'normalize_from_rails', 'Download latest Rails locale files, normalize them, and merge into a single file.'
78+
def normalize_from_rails
79+
curr_dir = File.expand_path(File.dirname(__FILE__))
80+
rails_locale_dir = File.expand_path(File.join(curr_dir, 'rails', 'rails'))
81+
normalized_dir = File.join(rails_locale_dir, 'normalized')
82+
83+
puts "Fetching latest Rails locale files to #{rails_locale_dir}... \n\n"
84+
system <<-BASH
85+
curl -Lo '#{rails_locale_dir}/action_view.yml' https://github.com/rails/rails/8-0-stable/actionview/lib/action_view/locale/en.yml
86+
curl -Lo '#{rails_locale_dir}/active_model.yml' https://github.com/rails/rails/8-0-stable/activemodel/lib/active_model/locale/en.yml
87+
curl -Lo '#{rails_locale_dir}/active_record.yml' https://github.com/rails/rails/8-0-stable/activerecord/lib/active_record/locale/en.yml
88+
curl -Lo '#{rails_locale_dir}/active_support.yml' https://github.com/rails/rails/8-0-stable/activesupport/lib/active_support/locale/en.yml
89+
BASH
90+
puts "\nDownload complete.\n\n"
91+
92+
merged_content = {}
93+
Dir.glob("#{rails_locale_dir}/*.yml").each do |filename|
94+
puts "Normalizing #{filename}..."
95+
96+
content = YAML.load_file(filename)
97+
normalized_content = Normalize.deep_sort(content)
98+
99+
output_filename = File.join(normalized_dir, File.basename(filename))
100+
File.write(output_filename, normalized_content.to_yaml(line_width: -1))
101+
puts "Normalized file saved to #{output_filename}"
102+
103+
merged_content.deep_merge!(normalized_content)
104+
end
105+
106+
puts "\nAll downloaded files normalized and saved."
107+
108+
puts "\nNormalizing merged content..."
109+
normalized_merged_content = Normalize.deep_sort(merged_content)
110+
merged_filename = File.join(normalized_dir, 'merged.yml')
111+
File.write(merged_filename, normalized_merged_content.to_yaml(line_width: -1))
112+
113+
puts "Merged file saved to #{merged_filename}."
114+
end
115+
77116
desc 'list', 'List locale names.'
78117
def list
79118
puts CheckLocales.list_locales.join(', ')
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
en:
3+
datetime:
4+
distance_in_words:
5+
about_x_hours:
6+
one: about 1 hour
7+
other: about %{count} hours
8+
about_x_months:
9+
one: about 1 month
10+
other: about %{count} months
11+
about_x_years:
12+
one: about 1 year
13+
other: about %{count} years
14+
almost_x_years:
15+
one: almost 1 year
16+
other: almost %{count} years
17+
half_a_minute: half a minute
18+
less_than_x_seconds:
19+
one: less than 1 second
20+
other: less than %{count} seconds
21+
less_than_x_minutes:
22+
one: less than a minute
23+
other: less than %{count} minutes
24+
over_x_years:
25+
one: over 1 year
26+
other: over %{count} years
27+
x_seconds:
28+
one: 1 second
29+
other: "%{count} seconds"
30+
x_minutes:
31+
one: 1 minute
32+
other: "%{count} minutes"
33+
x_days:
34+
one: 1 day
35+
other: "%{count} days"
36+
x_months:
37+
one: 1 month
38+
other: "%{count} months"
39+
prompts:
40+
second: Seconds
41+
minute: Minute
42+
hour: Hour
43+
day: Day
44+
month: Month
45+
year: Year
46+
helpers:
47+
select:
48+
prompt: Please select
49+
submit:
50+
create: Create %{model}
51+
submit: Save %{model}
52+
update: Update %{model}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
en:
3+
errors:
4+
format: "%{attribute} %{message}"
5+
messages:
6+
accepted: must be accepted
7+
blank: can't be blank
8+
confirmation: doesn't match %{attribute}
9+
empty: can't be empty
10+
equal_to: must be equal to %{count}
11+
even: must be even
12+
exclusion: is reserved
13+
greater_than: must be greater than %{count}
14+
greater_than_or_equal_to: must be greater than or equal to %{count}
15+
in: must be in %{count}
16+
inclusion: is not included in the list
17+
invalid: is invalid
18+
less_than: must be less than %{count}
19+
less_than_or_equal_to: must be less than or equal to %{count}
20+
model_invalid: 'Validation failed: %{errors}'
21+
not_a_number: is not a number
22+
not_an_integer: must be an integer
23+
odd: must be odd
24+
other_than: must be other than %{count}
25+
password_too_long: is too long
26+
present: must be blank
27+
too_long:
28+
one: is too long (maximum is 1 character)
29+
other: is too long (maximum is %{count} characters)
30+
too_short:
31+
one: is too short (minimum is 1 character)
32+
other: is too short (minimum is %{count} characters)
33+
wrong_length:
34+
one: is the wrong length (should be 1 character)
35+
other: is the wrong length (should be %{count} characters)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
en:
3+
activerecord:
4+
errors:
5+
messages:
6+
record_invalid: 'Validation failed: %{errors}'
7+
restrict_dependent_destroy:
8+
has_one: Cannot delete record because a dependent %{record} exists
9+
has_many: Cannot delete record because dependent %{record} exist
10+
errors:
11+
messages:
12+
required: must exist
13+
taken: has already been taken
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
en:
3+
date:
4+
abbr_day_names:
5+
- Sun
6+
- Mon
7+
- Tue
8+
- Wed
9+
- Thu
10+
- Fri
11+
- Sat
12+
abbr_month_names:
13+
-
14+
- Jan
15+
- Feb
16+
- Mar
17+
- Apr
18+
- May
19+
- Jun
20+
- Jul
21+
- Aug
22+
- Sep
23+
- Oct
24+
- Nov
25+
- Dec
26+
day_names:
27+
- Sunday
28+
- Monday
29+
- Tuesday
30+
- Wednesday
31+
- Thursday
32+
- Friday
33+
- Saturday
34+
formats:
35+
default: "%Y-%m-%d"
36+
long: "%B %d, %Y"
37+
short: "%b %d"
38+
month_names:
39+
-
40+
- January
41+
- February
42+
- March
43+
- April
44+
- May
45+
- June
46+
- July
47+
- August
48+
- September
49+
- October
50+
- November
51+
- December
52+
order:
53+
- year
54+
- month
55+
- day
56+
number:
57+
currency:
58+
format:
59+
delimiter: ","
60+
format: "%u%n"
61+
negative_format: "-%u%n"
62+
precision: 2
63+
separator: "."
64+
significant: false
65+
strip_insignificant_zeros: false
66+
unit: "$"
67+
format:
68+
delimiter: ","
69+
precision: 3
70+
round_mode: default
71+
separator: "."
72+
significant: false
73+
strip_insignificant_zeros: false
74+
human:
75+
decimal_units:
76+
format: "%n %u"
77+
units:
78+
billion: Billion
79+
million: Million
80+
quadrillion: Quadrillion
81+
thousand: Thousand
82+
trillion: Trillion
83+
unit: ''
84+
format:
85+
delimiter: ''
86+
precision: 3
87+
significant: true
88+
strip_insignificant_zeros: true
89+
storage_units:
90+
format: "%n %u"
91+
units:
92+
byte:
93+
one: Byte
94+
other: Bytes
95+
eb: EB
96+
gb: GB
97+
kb: KB
98+
mb: MB
99+
pb: PB
100+
tb: TB
101+
zb: ZB
102+
percentage:
103+
format:
104+
delimiter: ''
105+
format: "%n%"
106+
precision:
107+
format:
108+
delimiter: ''
109+
support:
110+
array:
111+
last_word_connector: ", and "
112+
two_words_connector: " and "
113+
words_connector: ", "
114+
time:
115+
am: am
116+
formats:
117+
default: "%a, %d %b %Y %H:%M:%S %z"
118+
long: "%B %d, %Y %H:%M"
119+
short: "%d %b %H:%M"
120+
pm: pm

0 commit comments

Comments
 (0)