-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Serbian Cyrillic support with additional bug fixes (#43)
* Added Serbian Cyrillic support with additional bug fixes * updated README.md with new Serbian cyrillic language support
- Loading branch information
1 parent
f32f9c6
commit 399930b
Showing
11 changed files
with
295 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ Supported languages | |
* Slovak | ||
* Ukrainian | ||
* Serbian (latin) | ||
* Serbian (cyrillic) | ||
* Turkish | ||
|
||
Usage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
.../java/pl/allegro/finance/tradukisto/internal/languages/serbian/SerbianCyrillicValues.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package pl.allegro.finance.tradukisto.internal.languages.serbian; | ||
|
||
import pl.allegro.finance.tradukisto.internal.BaseValues; | ||
import pl.allegro.finance.tradukisto.internal.languages.GenderForms; | ||
import pl.allegro.finance.tradukisto.internal.languages.GenderType; | ||
import pl.allegro.finance.tradukisto.internal.languages.PluralForms; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static pl.allegro.finance.tradukisto.internal.languages.GenderForms.genderForms; | ||
import static pl.allegro.finance.tradukisto.internal.support.BaseNumbersBuilder.baseNumbersBuilder; | ||
|
||
public class SerbianCyrillicValues implements BaseValues { | ||
@Override | ||
public Map<Integer, GenderForms> baseNumbers() { | ||
return baseNumbersBuilder() | ||
.put(0, "нула") | ||
.put(1, genderForms("један", "једна", "један", "један")) | ||
.put(2, genderForms("два", "две", "две", "два")) | ||
.put(3, "три") | ||
.put(4, "четири") | ||
.put(5, "пет") | ||
.put(6, "шест") | ||
.put(7, "седам") | ||
.put(8, "осам") | ||
.put(9, "девет") | ||
.put(10, "десет") | ||
.put(11, "једанаест") | ||
.put(12, "дванаест") | ||
.put(13, "тринаест") | ||
.put(14, "четрнаест") | ||
.put(15, "петнаест") | ||
.put(16, "шеснаест") | ||
.put(17, "седамнаест") | ||
.put(18, "осамнаест") | ||
.put(19, "деветнаест") | ||
.put(20, "двадесет") | ||
.put(30, "тридесет") | ||
.put(40, "четрдесет") | ||
.put(50, "педесет") | ||
.put(60, "шездесет") | ||
.put(70, "седамдесет") | ||
.put(80, "осамдесет") | ||
.put(90, "деведесет") | ||
.put(100, "сто") | ||
.put(200, "двеста") | ||
.put(300, "триста") | ||
.put(400, "четиристо") | ||
.put(500, "петсто") | ||
.put(600, "шестсто") | ||
.put(700, "седамсто") | ||
.put(800, "осамсто") | ||
.put(900, "деветсто") | ||
.build(); | ||
} | ||
|
||
@Override | ||
public List<PluralForms> pluralForms() { | ||
return Arrays.asList( | ||
new SerbianPluralForms("", "", "", GenderType.MASCULINE), | ||
new SerbianPluralForms("хиљада", "хиљаде", "хиљада", GenderType.FEMININE), | ||
new SerbianPluralForms("милион", "милиона", "милиона", GenderType.MASCULINE), | ||
new SerbianPluralForms("милијарда", "милијарде", "милијарди", GenderType.FEMININE)); | ||
} | ||
|
||
@Override | ||
public String currency() { | ||
return "РСД"; | ||
} | ||
|
||
@Override | ||
public char twoDigitsNumberSeparator() { | ||
return ' '; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ain/java/pl/allegro/finance/tradukisto/internal/languages/serbian/SerbianPluralForms.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package pl.allegro.finance.tradukisto.internal.languages.serbian; | ||
|
||
import com.google.common.collect.Range; | ||
import pl.allegro.finance.tradukisto.internal.languages.GenderType; | ||
import pl.allegro.finance.tradukisto.internal.languages.PluralForms; | ||
|
||
public class SerbianPluralForms implements PluralForms { | ||
|
||
private final String singularForm; | ||
private final String pluralForm; | ||
private final String genitivePluralForm; | ||
|
||
private final GenderType genderType; | ||
|
||
public SerbianPluralForms(String singularForm, String pluralForm, String genitivePluralForm, GenderType genderType) { | ||
this.singularForm = singularForm; | ||
this.pluralForm = pluralForm; | ||
this.genitivePluralForm = genitivePluralForm; | ||
|
||
this.genderType = genderType; | ||
} | ||
|
||
@Override | ||
public String formFor(Integer value) { | ||
if (useSingular(value)) { | ||
return singularForm; | ||
} else if (usePluralForm(value)) { | ||
return pluralForm; | ||
} | ||
return genitivePluralForm; | ||
} | ||
|
||
private boolean useSingular(Integer value) { | ||
return value == 1 || (value % 100 != 11 && value % 10 == 1); | ||
} | ||
|
||
private boolean usePluralForm(Integer value) { | ||
return Range.closed(2, 4).contains(value % 10) && !Range.closed(12, 14).contains(value % 100); | ||
} | ||
|
||
@Override | ||
public GenderType genderType() { | ||
return genderType; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...est/groovy/pl/allegro/finance/tradukisto/internal/languages/RegularPluralFormsTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...pl/allegro/finance/tradukisto/internal/languages/serbian/SerbianCyrillicValuesTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package pl.allegro.finance.tradukisto.internal.languages.serbian | ||
|
||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
import static pl.allegro.finance.tradukisto.internal.Container.serbianCyrillicContainer | ||
|
||
class SerbianCyrillicValuesTest extends Specification { | ||
|
||
static converter = serbianCyrillicContainer().getNumbersConverter() | ||
|
||
@Unroll | ||
def "should convert #value to '#words' in Serbian Cyrillic"() { | ||
expect: | ||
converter.asWords(value) == words | ||
|
||
where: | ||
value | words | ||
0 | "нула" | ||
1 | "један" | ||
2 | "два" | ||
3 | "три" | ||
4 | "четири" | ||
5 | "пет" | ||
6 | "шест" | ||
7 | "седам" | ||
8 | "осам" | ||
9 | "девет" | ||
|
||
11 | "једанаест" | ||
12 | "дванаест" | ||
13 | "тринаест" | ||
14 | "четрнаест" | ||
15 | "петнаест" | ||
16 | "шеснаест" | ||
17 | "седамнаест" | ||
18 | "осамнаест" | ||
19 | "деветнаест" | ||
|
||
10 | "десет" | ||
20 | "двадесет" | ||
30 | "тридесет" | ||
40 | "четрдесет" | ||
50 | "педесет" | ||
60 | "шездесет" | ||
70 | "седамдесет" | ||
80 | "осамдесет" | ||
90 | "деведесет" | ||
|
||
21 | "двадесет један" | ||
37 | "тридесет седам" | ||
43 | "четрдесет три" | ||
58 | "педесет осам" | ||
69 | "шездесет девет" | ||
76 | "седамдесет шест" | ||
82 | "осамдесет два" | ||
95 | "деведесет пет" | ||
|
||
100 | "сто" | ||
200 | "двеста" | ||
300 | "триста" | ||
400 | "четиристо" | ||
500 | "петсто" | ||
600 | "шестсто" | ||
700 | "седамсто" | ||
800 | "осамсто" | ||
900 | "деветсто" | ||
|
||
101 | "сто један" | ||
111 | "сто једанаест" | ||
272 | "двеста седамдесет два" | ||
387 | "триста осамдесет седам" | ||
421 | "четиристо двадесет један" | ||
448 | "четиристо четрдесет осам" | ||
569 | "петсто шездесет девет" | ||
625 | "шестсто двадесет пет" | ||
782 | "седамсто осамдесет два" | ||
895 | "осамсто деведесет пет" | ||
999 | "деветсто деведесет девет" | ||
|
||
1_000 | "једна хиљада" | ||
2_000 | "две хиљаде" | ||
3_000 | "три хиљаде" | ||
4_000 | "четири хиљаде" | ||
5_000 | "пет хиљада" | ||
11_000 | "једанаест хиљада" | ||
12_000 | "дванаест хиљада" | ||
13_000 | "тринаест хиљада" | ||
14_000 | "четрнаест хиљада" | ||
15_000 | "петнаест хиљада" | ||
21_000 | "двадесет једна хиљада" | ||
|
||
7_634 | "седам хиљада шестсто тридесет четири" | ||
24_190 | "двадесет четири хиљаде сто деведесет" | ||
99_999 | "деведесет девет хиљада деветсто деведесет девет" | ||
|
||
111_000 | "сто једанаест хиљада" | ||
112_000 | "сто дванаест хиљада" | ||
113_000 | "сто тринаест хиљада" | ||
115_000 | "сто петнаест хиљада" | ||
700_000 | "седамсто хиљада" | ||
653_000 | "шестсто педесет три хиљаде" | ||
|
||
123_454 | "сто двадесет три хиљаде четиристо педесет четири" | ||
999_999 | "деветсто деведесет девет хиљада деветсто деведесет девет" | ||
|
||
1_000_000 | "један милион" | ||
2_000_000 | "два милиона" | ||
5_000_000 | "пет милиона" | ||
11_437_219 | "једанаест милиона четиристо тридесет седам хиљада двеста деветнаест" | ||
21_437_219 | "двадесет један милион четиристо тридесет седам хиљада двеста деветнаест" | ||
22_437_219 | "двадесет два милиона четиристо тридесет седам хиљада двеста деветнаест" | ||
23_437_219 | "двадесет три милиона четиристо тридесет седам хиљада двеста деветнаест" | ||
100_000_000 | "сто милиона" | ||
121_451_789 | "сто двадесет један милион четиристо педесет једна хиљада седамсто осамдесет девет" | ||
123_456_789 | "сто двадесет три милиона четиристо педесет шест хиљада седамсто осамдесет девет" | ||
|
||
1_000_000_000 | "једна милијарда" | ||
2_141_123_731 | "две милијарде сто четрдесет један милион сто двадесет три хиљаде седамсто тридесет један" | ||
Integer.MAX_VALUE | "две милијарде сто четрдесет седам милиона четиристо осамдесет три хиљаде шестсто четрдесет седам" | ||
} | ||
} |
Oops, something went wrong.