Skip to content

Commit 2b31f78

Browse files
committed
kazakh translations
1 parent 11857bf commit 2b31f78

2 files changed

Lines changed: 386 additions & 0 deletions

File tree

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
package org.ocpsoft.prettytime.i18n;
2+
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+
import org.ocpsoft.prettytime.units.*;
8+
9+
import java.util.ListResourceBundle;
10+
11+
/**
12+
* Created by Azimkhan Yerzhan on 5/8/2017
13+
*/
14+
public class Resources_kk extends ListResourceBundle implements TimeFormatProvider {
15+
16+
private static final Object[][] OBJECTS = new Object[0][0];
17+
@Override
18+
protected Object[][] getContents() {
19+
return OBJECTS;
20+
}
21+
22+
private static class KkTimeFormat implements TimeFormat
23+
{
24+
private final int tolerance = 50;
25+
private final String[] forms;
26+
27+
public KkTimeFormat(String... plurals)
28+
{
29+
if (plurals.length != 2) {
30+
throw new IllegalArgumentException("Future and past forms must be provided for kazakh language!");
31+
}
32+
this.forms = plurals;
33+
}
34+
35+
@Override
36+
public String format(Duration duration)
37+
{
38+
long quantity = duration.getQuantityRounded(tolerance);
39+
StringBuilder result = new StringBuilder();
40+
result.append(quantity);
41+
return result.toString();
42+
}
43+
44+
@Override
45+
public String formatUnrounded(Duration duration)
46+
{
47+
long quantity = duration.getQuantity();
48+
StringBuilder result = new StringBuilder();
49+
result.append(quantity);
50+
return result.toString();
51+
}
52+
53+
@Override
54+
public String decorate(Duration duration, String time)
55+
{
56+
return performDecoration(
57+
duration.isInPast(),
58+
duration.isInFuture(),
59+
duration.getQuantityRounded(tolerance),
60+
time);
61+
}
62+
63+
@Override
64+
public String decorateUnrounded(Duration duration, String time)
65+
{
66+
return performDecoration(
67+
duration.isInPast(),
68+
duration.isInFuture(),
69+
duration.getQuantity(),
70+
time);
71+
}
72+
73+
private String performDecoration(boolean past, boolean future, long n, String time)
74+
{
75+
StringBuilder builder = new StringBuilder();
76+
int formIndex = past ? 0 : 1;
77+
78+
builder.append(time);
79+
builder.append(' ');
80+
builder.append(forms[formIndex]);
81+
builder.append(' ');
82+
83+
if (past) {
84+
builder.append("бұрын");
85+
}
86+
87+
if (future) {
88+
builder.append("кейін");
89+
}
90+
return builder.toString();
91+
}
92+
}
93+
94+
@Override
95+
public TimeFormat getFormatFor(TimeUnit t) {
96+
if (t instanceof JustNow) {
97+
return new TimeFormat() {
98+
@Override
99+
public String format(Duration duration)
100+
{
101+
return performFormat(duration);
102+
}
103+
104+
@Override
105+
public String formatUnrounded(Duration duration)
106+
{
107+
return performFormat(duration);
108+
}
109+
110+
private String performFormat(Duration duration)
111+
{
112+
if (duration.isInFuture()) {
113+
return "дәл қазір";
114+
}
115+
if (duration.isInPast()) {
116+
return "жана ғана";
117+
}
118+
return null;
119+
}
120+
121+
@Override
122+
public String decorate(Duration duration, String time)
123+
{
124+
return time;
125+
}
126+
127+
@Override
128+
public String decorateUnrounded(Duration duration, String time)
129+
{
130+
return time;
131+
}
132+
};
133+
}
134+
else if (t instanceof Century) {
135+
return new KkTimeFormat("ғасыр","ғасырдан");
136+
}
137+
else if (t instanceof Day) {
138+
return new KkTimeFormat("күн", "күннен");
139+
}
140+
else if (t instanceof Decade) {
141+
return new KkTimeFormat("онжылдық", "онжылдықтан");
142+
}
143+
else if (t instanceof Hour) {
144+
return new KkTimeFormat("сағат", "сағаттан");
145+
}
146+
else if (t instanceof Millennium) {
147+
return new KkTimeFormat("мыңжылдық", "мыңжылдықтан");
148+
}
149+
else if (t instanceof Millisecond) {
150+
return new KkTimeFormat("миллисекунд", "миллисекундтан");
151+
}
152+
else if (t instanceof Minute) {
153+
return new KkTimeFormat("минут", "минуттан");
154+
}
155+
else if (t instanceof Month) {
156+
return new KkTimeFormat("ай", "айдан");
157+
}
158+
else if (t instanceof Second) {
159+
return new KkTimeFormat("секунд", "секундтан");
160+
}
161+
else if (t instanceof Week) {
162+
return new KkTimeFormat("апта", "аптадан");
163+
}
164+
else if (t instanceof Year) {
165+
return new KkTimeFormat("жыл", "жылдан");
166+
}
167+
return null;
168+
}
169+
}
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
package org.ocpsoft.prettytime;
2+
3+
import org.junit.After;
4+
import org.junit.Before;
5+
import org.junit.Test;
6+
7+
import java.text.SimpleDateFormat;
8+
import java.util.Date;
9+
import java.util.Locale;
10+
11+
import static org.junit.Assert.assertEquals;
12+
13+
/**
14+
* Created by Azimkhan Yerzhan on 5/8/2017
15+
*/
16+
public class PrettyTimeI18n_kk_Test {
17+
private final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
18+
private Locale locale;
19+
20+
@Before
21+
public void setUp() throws Exception
22+
{
23+
locale = new Locale("kk");
24+
Locale.setDefault(locale);
25+
}
26+
27+
@Test
28+
public void testPrettyTime()
29+
{
30+
PrettyTime p = new PrettyTime(locale);
31+
assertEquals("дәл қазір", p.format(new Date()));
32+
}
33+
34+
@Test
35+
public void testPrettyTimeCenturies()
36+
{
37+
PrettyTime p = new PrettyTime(new Date(3155692597470L * 3L), locale);
38+
assertEquals("3 ғасыр бұрын", p.format(new Date(0)));
39+
40+
p = new PrettyTime(new Date(0), locale);
41+
assertEquals("3 ғасырдан кейін", p.format(new Date(3155692597470L * 3L)));
42+
}
43+
44+
@Test
45+
public void testCeilingInterval() throws Exception
46+
{
47+
Date then = format.parse("20/5/2009");
48+
Date ref = format.parse("17/6/2009");
49+
PrettyTime t = new PrettyTime(ref, locale);
50+
assertEquals("1 ай бұрын", t.format(then));
51+
}
52+
53+
@Test
54+
public void testNullDate() throws Exception
55+
{
56+
PrettyTime t = new PrettyTime(locale);
57+
Date date = null;
58+
assertEquals("дәл қазір", t.format(date));
59+
}
60+
61+
@Test
62+
public void testRightNow() throws Exception
63+
{
64+
PrettyTime t = new PrettyTime(locale);
65+
assertEquals("дәл қазір", t.format(new Date()));
66+
}
67+
68+
@Test
69+
public void testRightNowVariance() throws Exception
70+
{
71+
PrettyTime t = new PrettyTime(new Date(0), locale);
72+
assertEquals("дәл қазір", t.format(new Date(600)));
73+
}
74+
75+
@Test
76+
public void testMinutesFromNow() throws Exception
77+
{
78+
PrettyTime t = new PrettyTime(new Date(0), locale);
79+
assertEquals("12 минуттан кейін", t.format(new Date(1000 * 60 * 12)));
80+
}
81+
82+
@Test
83+
public void testHoursFromNow() throws Exception
84+
{
85+
PrettyTime t = new PrettyTime(new Date(0), locale);
86+
assertEquals("3 сағаттан кейін", t.format(new Date(1000 * 60 * 60 * 3)));
87+
}
88+
89+
@Test
90+
public void testDaysFromNow() throws Exception
91+
{
92+
PrettyTime t = new PrettyTime(new Date(0), locale);
93+
assertEquals("3 күннен кейін", t.format(new Date(1000 * 60 * 60 * 24 * 3)));
94+
}
95+
96+
@Test
97+
public void testWeeksFromNow() throws Exception
98+
{
99+
PrettyTime t = new PrettyTime(new Date(0), locale);
100+
assertEquals("3 аптадан кейін", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3)));
101+
}
102+
103+
@Test
104+
public void testMonthsFromNow() throws Exception
105+
{
106+
PrettyTime t = new PrettyTime(new Date(0), locale);
107+
assertEquals("3 айдан кейін", t.format(new Date(2629743830L * 3L)));
108+
}
109+
110+
@Test
111+
public void testYearsFromNow() throws Exception
112+
{
113+
PrettyTime t = new PrettyTime(new Date(0), locale);
114+
assertEquals("3 жылдан кейін", t.format(new Date(2629743830L * 12L * 3L)));
115+
}
116+
117+
@Test
118+
public void testDecadesFromNow() throws Exception
119+
{
120+
PrettyTime t = new PrettyTime(new Date(0), locale);
121+
assertEquals("3 онжылдықтан кейін", t.format(new Date(315569259747L * 3L)));
122+
}
123+
124+
@Test
125+
public void testCenturiesFromNow() throws Exception
126+
{
127+
PrettyTime t = new PrettyTime(new Date(0), locale);
128+
assertEquals("3 ғасырдан кейін", t.format(new Date(3155692597470L * 3L)));
129+
}
130+
131+
@Test
132+
public void testMillenniaFromNow() throws Exception
133+
{
134+
PrettyTime t = new PrettyTime(new Date(0), locale);
135+
assertEquals("3 мыңжылдықтан кейін", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 1000 * 3)));
136+
}
137+
138+
/*
139+
* Past
140+
*/
141+
@Test
142+
public void testMomentsAgo() throws Exception
143+
{
144+
PrettyTime t = new PrettyTime(new Date(6000), locale);
145+
assertEquals("жана ғана", t.format(new Date(0)));
146+
}
147+
148+
@Test
149+
public void testMinutesAgo() throws Exception
150+
{
151+
PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale);
152+
assertEquals("12 минут бұрын", t.format(new Date(0)));
153+
}
154+
155+
@Test
156+
public void testHoursAgo() throws Exception
157+
{
158+
PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale);
159+
assertEquals("3 сағат бұрын", t.format(new Date(0)));
160+
}
161+
162+
@Test
163+
public void testDaysAgo() throws Exception
164+
{
165+
PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale);
166+
assertEquals("3 күн бұрын", t.format(new Date(0)));
167+
}
168+
169+
@Test
170+
public void testWeeksAgo() throws Exception
171+
{
172+
PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale);
173+
assertEquals("3 апта бұрын", t.format(new Date(0)));
174+
}
175+
176+
@Test
177+
public void testMonthsAgo() throws Exception
178+
{
179+
PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale);
180+
assertEquals("3 ай бұрын", t.format(new Date(0)));
181+
}
182+
183+
@Test
184+
public void testYearsAgo() throws Exception
185+
{
186+
PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale);
187+
assertEquals("3 жыл бұрын", t.format(new Date(0)));
188+
}
189+
190+
@Test
191+
public void testDecadesAgo() throws Exception
192+
{
193+
PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale);
194+
assertEquals("3 онжылдық бұрын", t.format(new Date(0)));
195+
}
196+
197+
@Test
198+
public void testCenturiesAgo() throws Exception
199+
{
200+
PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale);
201+
assertEquals("3 ғасыр бұрын", t.format(new Date(0)));
202+
}
203+
204+
@Test
205+
public void testMillenniaAgo() throws Exception
206+
{
207+
PrettyTime t = new PrettyTime(new Date(3155692597470L * 10 * 3L), locale);
208+
// 3 millennia ago
209+
assertEquals("3 мыңжылдық бұрын", t.format(new Date(0)));
210+
}
211+
212+
@After
213+
public void tearDown() throws Exception
214+
{
215+
Locale.setDefault(locale);
216+
}
217+
}

0 commit comments

Comments
 (0)