-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
231 additions
and
2 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
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
45 changes: 45 additions & 0 deletions
45
...java/pl/allegro/finance/tradukisto/internal/languages/ukrainian/UkrainianPluralForms.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.ukrainian; | ||
|
||
import com.google.common.collect.Range; | ||
import pl.allegro.finance.tradukisto.internal.languages.GenderType; | ||
import pl.allegro.finance.tradukisto.internal.languages.PluralForms; | ||
|
||
public class UkrainianPluralForms implements PluralForms { | ||
|
||
private final String singularForm; | ||
private final String pluralForm; | ||
private final String genitivePluralForm; | ||
|
||
private final GenderType genderType; | ||
|
||
public UkrainianPluralForms(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; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...main/java/pl/allegro/finance/tradukisto/internal/languages/ukrainian/UkrainianValues.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,79 @@ | ||
package pl.allegro.finance.tradukisto.internal.languages.ukrainian; | ||
|
||
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 UkrainianValues 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 UkrainianPluralForms("", "", "", GenderType.MASCULINE), | ||
new UkrainianPluralForms("тисяча", "тисячі", "тисяч", GenderType.FEMININE), | ||
new UkrainianPluralForms("мільйон", "мільйони", "мільйонів", GenderType.MASCULINE), | ||
new UkrainianPluralForms("мільярд", "мільярди", "мільярдів", GenderType.MASCULINE)); | ||
} | ||
|
||
@Override | ||
public String currency() { | ||
return "₴"; | ||
} | ||
|
||
@Override | ||
public char twoDigitsNumberSeparator() { | ||
return ' '; | ||
} | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
...ovy/pl/allegro/finance/tradukisto/internal/languages/ukrainian/UkrainianValuesTest.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,98 @@ | ||
package pl.allegro.finance.tradukisto.internal.languages.ukrainian | ||
|
||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
import static pl.allegro.finance.tradukisto.internal.Container.ukrainianContainer | ||
|
||
class UkrainianValuesTest extends Specification { | ||
|
||
static converter = ukrainianContainer().getNumbersConverter() | ||
|
||
@Unroll | ||
def "should convert #value to '#words' in Ukrainian"() { | ||
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 | "дев'ятсот" | ||
111 | "сто одинадцять" | ||
272 | "двісті сімдесят два" | ||
387 | "триста вісімдесят сім" | ||
448 | "чотириста сорок вісім" | ||
569 | "п'ятсот шістдесят дев'ять" | ||
625 | "шістсот двадцять п'ять" | ||
782 | "сімсот вісімдесят два" | ||
895 | "вісімсот дев'яносто п'ять" | ||
999 | "дев'ятсот дев'яносто дев'ять" | ||
1_000 | "одна тисяча" | ||
2_000 | "дві тисячі" | ||
5_000 | "п'ять тисяч" | ||
7_634 | "сім тисяч шістсот тридцять чотири" | ||
21_000 | "двадцять одна тисяча" | ||
24_190 | "двадцять чотири тисячі сто дев'яносто" | ||
51_000 | "пятдесят одна тисяча" | ||
101_000 | "сто одна тисяча" | ||
481_000 | "чотириста вісімдесят одна тисяча" | ||
653_000 | "шістсот пятдесят три тисячі" | ||
123_454 | "сто двадцять три тисячі чотириста пятдесят чотири" | ||
700_000 | "сімсот тисяч" | ||
999_999 | "дев'ятсот дев'яносто дев'ять тисяч дев'ятсот дев'яносто дев'ять" | ||
1_000_000 | "один мільйон" | ||
2_000_000 | "два мільйони" | ||
5_000_000 | "п'ять мільйонів" | ||
23_437_219 | "двадцять три мільйони чотириста тридцять сім тисяч двісті дев'ятнадцять" | ||
100_000_000 | "сто мільйонів" | ||
123_456_789 | "сто двадцять три мільйони чотириста пятдесят шість тисяч сімсот вісімдесят дев'ять" | ||
1_000_000_000 | "один мільярд" | ||
2_147_483_647 | "два мільярди сто сорок сім мільйонів чотириста вісімдесят три тисячі шістсот сорок сім" | ||
} | ||
|
||
} |