Skip to content

Commit aa666a5

Browse files
Tomo Matsumotogreysteil
authored andcommitted
add Japanese locale
1 parent c325a00 commit aa666a5

17 files changed

+414
-25
lines changed

config/locales/en.yml

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
11
en:
22
ice_cube:
3+
pieces_connector: ' / '
4+
not: 'not %{target}'
5+
not_on: 'not on %{target}'
6+
date:
7+
formats:
8+
default: '%B %-d, %Y'
9+
month_names:
10+
-
11+
- January
12+
- February
13+
- March
14+
- April
15+
- May
16+
- June
17+
- July
18+
- August
19+
- September
20+
- October
21+
- November
22+
- December
23+
day_names:
24+
- Sunday
25+
- Monday
26+
- Tuesday
27+
- Wednesday
28+
- Thursday
29+
- Friday
30+
- Saturday
331
times:
432
other: '%{count} times'
533
one: '%{count} time'
34+
until: 'until %{date}'
35+
days_of_week: '%{segments} %{day}'
636
days_of_month:
737
other: '%{segments} days of the month'
838
one: '%{segments} day of the month'
@@ -21,13 +51,35 @@ en:
2151
on_seconds_of_minute:
2252
other: on the %{segments} seconds of the minute
2353
one: on the %{segments} second of the minute
54+
each_second:
55+
one: Secondly
56+
other: Every %{count} seconds
57+
each_minute:
58+
one: Minutely
59+
other: Every %{count} minutes
60+
each_hour:
61+
one: Hourly
62+
other: Every %{count} hours
63+
each_day:
64+
one: Daily
65+
other: Every %{count} days
66+
each_week:
67+
one: Weekly
68+
other: Every %{count} weeks
69+
each_month:
70+
one: Monthly
71+
other: Every %{count} months
72+
each_year:
73+
one: Yearly
74+
other: Every %{count} years
2475
'on': on the %{sentence}
25-
in: in
76+
in: 'in %{target}'
2677
integer:
2778
negative: '%{ordinal} to last'
2879
literal_ordinals:
2980
-1: last
3081
-2: 2nd to last
82+
ordinal: '%{number}%{ordinal}'
3183
ordinals:
3284
default: th
3385
1: st
@@ -47,6 +99,18 @@ en:
4799
- Fridays
48100
- Saturdays
49101
on_days: on %{days}
50-
support:
51102
array:
103+
last_word_connector: ', and '
52104
two_words_connector: ' and '
105+
words_connector: ', '
106+
string:
107+
format:
108+
day: '%{rest} %{current}'
109+
day_of_week: '%{rest} %{current}'
110+
day_of_month: '%{rest} %{current}'
111+
day_of_year: '%{rest} %{current}'
112+
hour_of_day: '%{rest} %{current}'
113+
minute_of_hour: '%{rest} %{current}'
114+
until: '%{rest} %{current}'
115+
count: '%{rest} %{current}'
116+
default: '%{rest} %{current}'

config/locales/ja.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
ja:
2+
ice_cube:
3+
pieces_connector: ' / '
4+
not: '%{target}以外'
5+
not_on: '%{target}以外'
6+
date:
7+
formats:
8+
default: '%Y年%m月%d日'
9+
month_names:
10+
-
11+
- 1月
12+
- 2月
13+
- 3月
14+
- 4月
15+
- 5月
16+
- 6月
17+
- 7月
18+
- 8月
19+
- 9月
20+
- 10月
21+
- 11月
22+
- 12月
23+
day_names:
24+
- 日曜
25+
- 月曜
26+
- 火曜
27+
- 水曜
28+
- 木曜
29+
- 金曜
30+
- 土曜
31+
times:
32+
other: '%{count}回'
33+
one: '%{count}回'
34+
until: '%{date}まで'
35+
days_of_week: '%{segments}%{day}'
36+
days_of_month:
37+
other: '%{segments}日'
38+
one: '%{segments}日'
39+
days_of_year:
40+
other: '%{segments}日'
41+
one: '%{segments}日'
42+
at_hours_of_the_day:
43+
other: '%{segments}時'
44+
one: '%{segments}時'
45+
on_minutes_of_hour:
46+
other: '%{segments}分'
47+
one: '%{segments}分'
48+
on_seconds_of_minute:
49+
other: '%{segments}秒'
50+
one: '%{segments}秒'
51+
each_second:
52+
one: 毎秒
53+
other: '%{count}秒ごと'
54+
each_minute:
55+
one: 毎分
56+
other: '%{count}分ごと'
57+
each_hour:
58+
one: 毎時間
59+
other: '%{count}時間ごと'
60+
each_day:
61+
one: 毎日
62+
other: '%{count}日ごと'
63+
each_week:
64+
one: 毎週
65+
other: '%{count}週間ごと'
66+
each_month:
67+
one: 毎月
68+
other: '%{count}ヶ月ごと'
69+
each_year:
70+
one: 毎年
71+
other: '%{count}年ごと'
72+
'on': '%{sentence}'
73+
in: '%{target}'
74+
integer:
75+
negative: '最終%{ordinal}'
76+
literal_ordinals:
77+
-1: 最終
78+
-2: 最後から2番目の
79+
ordinal: '%{ordinal}%{number}'
80+
ordinals:
81+
default: ''
82+
on_weekends: 週末
83+
on_weekdays: 平日
84+
days_on:
85+
- 日曜
86+
- 月曜
87+
- 火曜
88+
- 水曜
89+
- 木曜
90+
- 金曜
91+
- 土曜
92+
on_days: '%{days}'
93+
array:
94+
last_word_connector: ''
95+
two_words_connector: ''
96+
words_connector: ''
97+
string:
98+
format:
99+
day: '%{rest}%{current}'
100+
day_of_week: '%{rest}%{current}'
101+
day_of_month: '%{rest}%{current}'
102+
day_of_year: '%{rest}%{current}'
103+
hour_of_day: '%{rest}%{current}'
104+
minute_of_hour: '%{rest}%{current}'
105+
until: '%{current}%{rest}'
106+
count: '%{rest}%{current}'
107+
default: '%{rest}%{current}'

lib/ice_cube.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module Validations
7272
# Defines the format used by IceCube when printing out Schedule#to_s.
7373
# Defaults to '%B %e, %Y'
7474
def self.to_s_time_format
75-
@to_s_time_format ||= '%B %e, %Y'
75+
@to_s_time_format ||= I18n.t("ice_cube.date.formats.default")
7676
end
7777

7878
# Sets the format used by IceCube when printing out Schedule#to_s.

lib/ice_cube/builders/string_builder.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ def piece(type, prefix = nil, suffix = nil)
1313
end
1414

1515
def to_s
16-
@types.each_with_object(@base || '') do |(type, segments), str|
16+
string = @base || ''
17+
@types.each do |type, segments|
1718
if f = self.class.formatter(type)
18-
str << ' ' << f.call(segments)
19+
current = f.call(segments)
1920
else
2021
next if segments.empty?
21-
str << ' ' << self.class.sentence(segments)
22+
current = self.class.sentence(segments)
2223
end
24+
f = I18n.t('ice_cube.string.format')[type] ? type : 'default'
25+
string = I18n.t("ice_cube.string.format.#{f}", rest: string, current: current)
2326
end
27+
string
2428
end
2529

2630
def self.formatter(type)
@@ -39,8 +43,8 @@ def sentence(array)
3943
case array.length
4044
when 0 ; ''
4145
when 1 ; array[0].to_s
42-
when 2 ; "#{array[0]} and #{array[1]}"
43-
else ; "#{array[0...-1].join(', ')}, and #{array[-1]}"
46+
when 2 ; "#{array[0]}#{I18n.t('ice_cube.array.two_words_connector')}#{array[1]}"
47+
else ; "#{array[0...-1].join(I18n.t('ice_cube.array.words_connector'))}#{I18n.t('ice_cube.array.last_word_connector')}#{array[-1]}"
4448
end
4549
end
4650

@@ -49,7 +53,7 @@ def nice_number(number)
4953
end
5054

5155
def ordinalize(number)
52-
"#{number}#{ordinal(number)}"
56+
I18n.t('ice_cube.integer.ordinal', number: number, ordinal: ordinal(number))
5357
end
5458

5559
def literal_ordinal(number)

lib/ice_cube/schedule.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,11 @@ def to_s
315315
rd = recurrence_times_with_start_time - extimes
316316
pieces.concat rd.sort.map { |t| t.strftime(IceCube.to_s_time_format) }
317317
pieces.concat rrules.map { |t| t.to_s }
318-
pieces.concat exrules.map { |t| "not #{t.to_s}" }
319-
pieces.concat extimes.sort.map { |t| "not on #{t.strftime(IceCube.to_s_time_format)}" }
320-
pieces.join(' / ')
318+
pieces.concat exrules.map { |t| I18n.t('ice_cube.not', target: t.to_s) }
319+
pieces.concat extimes.sort.map { |t|
320+
I18n.t('ice_cube.not_on', target: t.strftime(IceCube.to_s_time_format))
321+
}
322+
pieces.join(I18n.t('ice_cube.pieces_connector'))
321323
end
322324

323325
# Serialize this schedule to_ical

lib/ice_cube/validations/daily_interval.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def validate(step_time, schedule)
3535
end
3636

3737
def build_s(builder)
38-
builder.base = interval == 1 ? 'Daily' : "Every #{interval} days"
38+
builder.base = I18n.t('ice_cube.each_day', count: interval)
3939
end
4040

4141
def build_hash(builder)

lib/ice_cube/validations/day_of_week.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ def validate(step_time, schedule)
4545
end
4646

4747
def build_s(builder)
48-
builder.piece(:day_of_week) << "#{StringBuilder.nice_number(occ)} #{Date::DAYNAMES[day]}"
48+
builder.piece(:day_of_week) << I18n.t(
49+
'ice_cube.days_of_week',
50+
segments: StringBuilder.nice_number(occ),
51+
day: I18n.t('ice_cube.date.day_names')[day]
52+
)
4953
end
5054

5155
def build_hash(builder)
@@ -62,7 +66,7 @@ def build_ical(builder)
6266
end
6367

6468
StringBuilder.register_formatter(:day_of_week) do |segments|
65-
sentence = segments.join(I18n.t('support.array.two_words_connector'))
69+
sentence = segments.join(I18n.t('ice_cube.array.two_words_connector'))
6670
I18n.t('ice_cube.on', sentence: sentence)
6771
end
6872

lib/ice_cube/validations/hourly_interval.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def validate(step_time, schedule)
3535
end
3636

3737
def build_s(builder)
38-
builder.base = interval == 1 ? 'Hourly' : "Every #{interval} hours"
38+
builder.base = I18n.t("ice_cube.each_hour", count: interval)
3939
end
4040

4141
def build_hash(builder)

lib/ice_cube/validations/minutely_interval.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def validate(step_time, schedule)
3535
end
3636

3737
def build_s(builder)
38-
builder.base = interval == 1 ? 'Minutely' : "Every #{interval} minutes"
38+
builder.base = I18n.t('ice_cube.each_minute', count: interval)
3939
end
4040

4141
def build_hash(builder)

lib/ice_cube/validations/month_of_year.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def dst_adjust?
3232
end
3333

3434
def build_s(builder)
35-
builder.piece(:month_of_year) << Date::MONTHNAMES[month]
35+
builder.piece(:month_of_year) << I18n.t("ice_cube.date.month_names")[month]
3636
end
3737

3838
def build_hash(builder)
@@ -44,7 +44,7 @@ def build_ical(builder)
4444
end
4545

4646
StringBuilder.register_formatter(:month_of_year) do |segments|
47-
"#{I18n.t("ice_cube.in")} #{StringBuilder.sentence(segments)}"
47+
I18n.t("ice_cube.in", target: StringBuilder.sentence(segments))
4848
end
4949

5050
end

0 commit comments

Comments
 (0)