Skip to content

Commit efbcd62

Browse files
committed
Merge pull request ocpsoft#104 from furplag/fixJaJPLocale
Fix Japanese translation.
2 parents 342221b + 92933aa commit efbcd62

2 files changed

Lines changed: 68 additions & 47 deletions

File tree

‎core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ja.java‎

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,62 @@
11
package org.ocpsoft.prettytime.i18n;
22

3-
import org.ocpsoft.prettytime.Duration;
4-
import org.ocpsoft.prettytime.TimeFormat;
5-
import org.ocpsoft.prettytime.TimeUnit;
6-
import org.ocpsoft.prettytime.impl.TimeFormatProvider;
7-
83
import java.util.ListResourceBundle;
94
import java.util.ResourceBundle;
105
import java.util.concurrent.ConcurrentHashMap;
116
import java.util.concurrent.ConcurrentMap;
127

8+
import org.ocpsoft.prettytime.Duration;
9+
import org.ocpsoft.prettytime.TimeFormat;
10+
import org.ocpsoft.prettytime.TimeUnit;
11+
import org.ocpsoft.prettytime.impl.TimeFormatProvider;
12+
import org.ocpsoft.prettytime.units.Decade;
13+
import org.ocpsoft.prettytime.units.Millennium;
14+
1315
public class Resources_ja extends ListResourceBundle implements TimeFormatProvider
1416
{
1517
private static final Object[][] OBJECTS = new Object[][] {
1618
{ "CenturyPattern", "%n%u" },
1719
{ "CenturyFuturePrefix", "今から" },
18-
{ "CenturyFutureSuffix", "世紀にもわたっ" },
20+
{ "CenturyFutureSuffix", "後" },
1921
{ "CenturyPastPrefix", "" },
20-
{ "CenturyPastSuffix", "世紀前" },
21-
{ "CenturySingularName", "" },
22-
{ "CenturyPluralName", "" },
22+
{ "CenturyPastSuffix", "前" },
23+
{ "CenturySingularName", "世紀" },
24+
{ "CenturyPluralName", "世紀" },
2325
{ "DayPattern", "%n%u" },
2426
{ "DayFuturePrefix", "今から" },
25-
{ "DayFutureSuffix", "間" },
27+
{ "DayFutureSuffix", "後" },
2628
{ "DayPastPrefix", "" },
2729
{ "DayPastSuffix", "前" },
2830
{ "DaySingularName", "日" },
2931
{ "DayPluralName", "日" },
3032
{ "DecadePattern", "%n%u" },
3133
{ "DecadeFuturePrefix", "今から" },
32-
{ "DecadeFutureSuffix", "年間" },
34+
{ "DecadeFutureSuffix", "後" },
3335
{ "DecadePastPrefix", "" },
34-
{ "DecadePastSuffix", "年前" },
35-
{ "DecadeSingularName", "" },
36-
{ "DecadePluralName", "" },
36+
{ "DecadePastSuffix", "前" },
37+
{ "DecadeSingularName", "年" },
38+
{ "DecadePluralName", "年" },
3739
{ "HourPattern", "%n%u" },
3840
{ "HourFuturePrefix", "今から" },
39-
{ "HourFutureSuffix", "" },
41+
{ "HourFutureSuffix", "後" },
4042
{ "HourPastPrefix", "" },
4143
{ "HourPastSuffix", "前" },
4244
{ "HourSingularName", "時間" },
4345
{ "HourPluralName", "時間" },
4446
{ "JustNowPattern", "%u" },
45-
{ "JustNowFuturePrefix", "" },
46-
{ "JustNowFutureSuffix", "今からすぐ" },
47+
{ "JustNowFuturePrefix", "今から" },
48+
{ "JustNowFutureSuffix", "すぐ" },
4749
{ "JustNowPastPrefix", "" },
48-
{ "JustNowPastSuffix", "さっき" },
50+
{ "JustNowPastSuffix", "たった今" },
4951
{ "JustNowSingularName", "" },
5052
{ "JustNowPluralName", "" },
51-
{ "MillenniumPattern", "%n %u" },
52-
{ "MillenniumFuturePrefix", "" },
53-
{ "MillenniumFutureSuffix", "今から" },
53+
{ "MillenniumPattern", "%n%u" },
54+
{ "MillenniumFuturePrefix", "今から" },
55+
{ "MillenniumFutureSuffix", "後" },
5456
{ "MillenniumPastPrefix", "" },
5557
{ "MillenniumPastSuffix", "前" },
56-
{ "MillenniumSingularName", "千年" },
57-
{ "MillenniumPluralName", "千年" },
58+
{ "MillenniumSingularName", "年" },
59+
{ "MillenniumPluralName", "年" },
5860
{ "MillisecondPattern", "%n%u" },
5961
{ "MillisecondFuturePrefix", "" },
6062
{ "MillisecondFutureSuffix", "今から" },
@@ -64,14 +66,14 @@ public class Resources_ja extends ListResourceBundle implements TimeFormatProvid
6466
{ "MillisecondPluralName", "ミリ秒" },
6567
{ "MinutePattern", "%n%u" },
6668
{ "MinuteFuturePrefix", "今から" },
67-
{ "MinuteFutureSuffix", "" },
69+
{ "MinuteFutureSuffix", "後" },
6870
{ "MinutePastPrefix", "" },
6971
{ "MinutePastSuffix", "前" },
7072
{ "MinuteSingularName", "分" },
7173
{ "MinutePluralName", "分" },
7274
{ "MonthPattern", "%n%u" },
7375
{ "MonthFuturePrefix", "今から" },
74-
{ "MonthFutureSuffix", "" },
76+
{ "MonthFutureSuffix", "後" },
7577
{ "MonthPastPrefix", "" },
7678
{ "MonthPastSuffix", "前" },
7779
{ "MonthSingularName", "ヶ月" },
@@ -85,18 +87,18 @@ public class Resources_ja extends ListResourceBundle implements TimeFormatProvid
8587
{ "SecondPluralName", "秒" },
8688
{ "WeekPattern", "%n%u" },
8789
{ "WeekFuturePrefix", "今から" },
88-
{ "WeekFutureSuffix", "週間" },
90+
{ "WeekFutureSuffix", "後" },
8991
{ "WeekPastPrefix", "" },
90-
{ "WeekPastSuffix", "週間前" },
91-
{ "WeekSingularName", "" },
92-
{ "WeekPluralName", "" },
92+
{ "WeekPastSuffix", "前" },
93+
{ "WeekSingularName", "週間" },
94+
{ "WeekPluralName", "週間" },
9395
{ "YearPattern", "%n%u" },
94-
{ "YearFuturePrefix", "" },
95-
{ "YearFutureSuffix", "年後の" },
96+
{ "YearFuturePrefix", "今から" },
97+
{ "YearFutureSuffix", "後" },
9698
{ "YearPastPrefix", "" },
97-
{ "YearPastSuffix", "年前" },
98-
{ "YearSingularName", "" },
99-
{ "YearPluralName", "" },
99+
{ "YearPastSuffix", "前" },
100+
{ "YearSingularName", "年" },
101+
{ "YearPluralName", "年" },
100102
{ "AbstractTimeUnitPattern", "" },
101103
{ "AbstractTimeUnitFuturePrefix", "" },
102104
{ "AbstractTimeUnitFutureSuffix", "" },
@@ -199,6 +201,8 @@ private String format(final Duration duration, final boolean round)
199201
String sign = getSign(duration);
200202
String unit = getGramaticallyCorrectName(duration, round);
201203
long quantity = getQuantity(duration, round);
204+
if (duration.getUnit() instanceof Decade) quantity *= 10;
205+
if (duration.getUnit() instanceof Millennium) quantity *= 1000;
202206

203207
return applyPattern(sign, unit, quantity);
204208
}
@@ -208,6 +212,7 @@ private String applyPattern(final String sign, final String unit, final long qua
208212
String result = getPattern(quantity).replaceAll(SIGN, sign);
209213
result = result.replaceAll(QUANTITY, String.valueOf(quantity));
210214
result = result.replaceAll(UNIT, unit);
215+
211216
return result;
212217
}
213218

@@ -380,4 +385,4 @@ public String toString()
380385
}
381386

382387
}
383-
}
388+
}

‎core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_JA_Test.java‎

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,63 +61,71 @@ public void testMinutesFromNow() throws Exception
6161
{
6262
PrettyTime t = new PrettyTime(new Date(0), locale);
6363
// 12 minutes from now
64-
assertEquals("12 minutes from now", "今から12分", t.format(new Date(1000 * 60 * 12)));
64+
assertEquals("12 minutes from now", "今から12分後", t.format(new Date(1000 * 60 * 12)));
6565
}
6666

6767
@Test
6868
public void testHoursFromNow() throws Exception
6969
{
7070
PrettyTime t = new PrettyTime(new Date(0), locale);
7171
// 3 hours from now
72-
assertEquals("3 hours from now", "今から3時間", t.format(new Date(1000 * 60 * 60 * 3)));
72+
assertEquals("3 hours from now", "今から3時間後", t.format(new Date(1000 * 60 * 60 * 3)));
7373
}
7474

7575
@Test
7676
public void testDaysFromNow() throws Exception
7777
{
7878
PrettyTime t = new PrettyTime(new Date(0), locale);
7979
// 3 days from now
80-
assertEquals("3 days from now", "今から3日間", t.format(new Date(1000 * 60 * 60 * 24 * 3)));
80+
assertEquals("3 days from now", "今から3日後", t.format(new Date(1000 * 60 * 60 * 24 * 3)));
8181
}
8282

8383
@Test
8484
public void testWeeksFromNow() throws Exception
8585
{
8686
PrettyTime t = new PrettyTime(new Date(0), locale);
8787
// 3 weeks from now
88-
assertEquals("3 weeks from now", "今から3週間", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3)));
88+
assertEquals("3 weeks from now", "今から3週間後", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3)));
8989
}
9090

9191
@Test
9292
public void testMonthsFromNow() throws Exception
9393
{
9494
PrettyTime t = new PrettyTime(new Date(0), locale);
9595
// 3 months from now
96-
assertEquals("3 months from now", "今から3ヶ月", t.format(new Date(2629743830L * 3L)));
96+
assertEquals("3 months from now", "今から3ヶ月後", t.format(new Date(2629743830L * 3L)));
9797
}
9898

9999
@Test
100100
public void testYearsFromNow() throws Exception
101101
{
102102
PrettyTime t = new PrettyTime(new Date(0), locale);
103103
// 3 years from now
104-
assertEquals("3 years from now", "3年後の", t.format(new Date(2629743830L * 12L * 3L)));
104+
assertEquals("3 years from now", "今から3年後", t.format(new Date(2629743830L * 12L * 3L)));
105105
}
106106

107107
@Test
108108
public void testOneDecadeFromNow() throws Exception
109109
{
110110
PrettyTime t = new PrettyTime(new Date(0), locale);
111111
// 1 decade from now
112-
assertEquals("今から1年間", t.format(new Date(315569259747L * 1L)));
112+
assertEquals("今から10年後", t.format(new Date(315569259747L * 1L)));
113113
}
114114

115115
@Test
116116
public void testCenturiesFromNow() throws Exception
117117
{
118118
PrettyTime t = new PrettyTime(new Date(0), locale);
119119
// 3 centuries from now
120-
assertEquals("3 centuries from now", "今から3世紀にもわたっ", t.format(new Date(3155692597470L * 3L)));
120+
assertEquals("3 centuries from now", "今から3世紀後", t.format(new Date(3155692597470L * 3L)));
121+
}
122+
123+
@Test
124+
public void testMillenniumFromNow() throws Exception
125+
{
126+
PrettyTime t = new PrettyTime(new Date(0), locale);
127+
// 3 millennia from now
128+
assertEquals("3 millennia from now", "今から3000年後", t.format(new Date(3155692597470L * 10L * 3L)));
121129
}
122130

123131
/*
@@ -128,7 +136,7 @@ public void testMomentsAgo() throws Exception
128136
{
129137
PrettyTime t = new PrettyTime(new Date(6000), locale);
130138
// moments ago
131-
assertEquals("さっき", t.format(new Date(0)));
139+
assertEquals("たった今", t.format(new Date(0)));
132140
}
133141

134142
@Test
@@ -196,7 +204,7 @@ public long getMillisPerUnit()
196204
{
197205
return 5000;
198206
}
199-
207+
200208
@Override
201209
public boolean isPrecise()
202210
{
@@ -229,7 +237,7 @@ public void testDecadeAgo() throws Exception
229237
{
230238
PrettyTime t = new PrettyTime(new Date(315569259747L * 1L), locale);
231239
// 1 decade ago
232-
assertEquals("1年前", t.format(new Date(0)));
240+
assertEquals("10年前", t.format(new Date(0)));
233241
}
234242

235243
@Test
@@ -240,6 +248,14 @@ public void testCenturiesAgo() throws Exception
240248
assertEquals("3 centuries ago", "3世紀前", t.format(new Date(0)));
241249
}
242250

251+
@Test
252+
public void testMilleniumAgo() throws Exception
253+
{
254+
PrettyTime t = new PrettyTime(new Date(3155692597470L * 10 * 3L), locale);
255+
// 3 millennia ago
256+
assertEquals("3 millennia ago", "3000年前", t.format(new Date(0)));
257+
}
258+
243259
@Test
244260
public void testWithinTwoHoursRounding() throws Exception
245261
{
@@ -275,7 +291,7 @@ public void testSetLocale() throws Exception
275291
{
276292
PrettyTime t = new PrettyTime(new Date(315569259747L * 1L), locale);
277293
// 1 decade ago
278-
assertEquals("1年前", t.format(new Date(0)));
294+
assertEquals("10年前", t.format(new Date(0)));
279295
t.setLocale(Locale.GERMAN);
280296
assertEquals("vor 1 Jahrzehnt", t.format(new Date(0)));
281297
}

0 commit comments

Comments
 (0)