Skip to content

Commit

Permalink
Merge pull request #28 from aleksandarni/master
Browse files Browse the repository at this point in the history
Support for Serbian language (latin)
  • Loading branch information
wjur authored Jan 2, 2019
2 parents aa10d14 + 5a68bf8 commit 5eff82e
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Supported languages
* Russian
* Slovak
* Ukrainian
* Serbian (latin)

Usage
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static pl.allegro.finance.tradukisto.internal.Container.latvianContainer;
import static pl.allegro.finance.tradukisto.internal.Container.kazakhContainer;
import static pl.allegro.finance.tradukisto.internal.Container.ukrainianContainer;
import static pl.allegro.finance.tradukisto.internal.Container.serbianContainer;

import java.math.BigDecimal;

Expand All @@ -27,7 +28,8 @@ public enum MoneyConverters {
SLOVAK_BANKING_MONEY_VALUE(slovakContainer().getBankingMoneyConverter()),
LATVIAN_BANKING_MONEY_VALUE(latvianContainer().getBankingMoneyConverter()),
KAZAKH_BANKING_MONEY_VALUE(kazakhContainer().getBankingMoneyConverter()),
UKRAINIAN_BANKING_MONEY_VALUE(ukrainianContainer().getBankingMoneyConverter());
UKRAINIAN_BANKING_MONEY_VALUE(ukrainianContainer().getBankingMoneyConverter()),
SERBIAN_BANKING_MONEY_VALUE(serbianContainer().getBankingMoneyConverter());

private final BigDecimalToStringConverter converter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static pl.allegro.finance.tradukisto.internal.Container.latvianContainer;
import static pl.allegro.finance.tradukisto.internal.Container.kazakhContainer;
import static pl.allegro.finance.tradukisto.internal.Container.ukrainianContainer;
import static pl.allegro.finance.tradukisto.internal.Container.serbianContainer;
import static pl.allegro.finance.tradukisto.internal.Container.frenchContainer;

import pl.allegro.finance.tradukisto.internal.IntegerToStringConverter;
Expand All @@ -27,6 +28,7 @@ public enum ValueConverters {
LATVIAN_INTEGER(latvianContainer().getNumbersConverter()),
KAZAKH_INTEGER(kazakhContainer().getNumbersConverter()),
UKRAINIAN_INTEGER(ukrainianContainer().getNumbersConverter()),
SERBIAN_INTEGER(serbianContainer().getNumbersConverter()),
FRENCH_INTEGER(frenchContainer().getNumbersConverter());

private final IntegerToStringConverter converter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import pl.allegro.finance.tradukisto.internal.languages.portuguese.PortugueseIntegerToWordsConverterAdapter;
import pl.allegro.finance.tradukisto.internal.languages.portuguese.PortugueseThousandToWordsConverter;
import pl.allegro.finance.tradukisto.internal.languages.russian.RussianValues;
import pl.allegro.finance.tradukisto.internal.languages.serbian.SerbianValues;
import pl.allegro.finance.tradukisto.internal.languages.slovak.SlovakValues;
import pl.allegro.finance.tradukisto.internal.languages.slovak.SlovakValuesForSmallNumbers;
import pl.allegro.finance.tradukisto.internal.languages.ukrainian.UkrainianValues;
Expand All @@ -34,6 +35,10 @@ public static Container russianContainer() {
return new Container(new RussianValues());
}

public static Container serbianContainer() {
return new Container(new SerbianValues());
}

public static Container ukrainianContainer() {
return new Container(new UkrainianValues());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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 pl.allegro.finance.tradukisto.internal.languages.SlavonicPluralForms;

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 SerbianValues implements BaseValues {
@Override
public Map<Integer, GenderForms> baseNumbers() {
return baseNumbersBuilder()
.put(0, "nula")
.put(1, genderForms("jedan", "jedna", "jedan", "jedan"))
.put(2, genderForms("dva", "dve", "dve", "dva"))
.put(3, "tri")
.put(4, "četiri")
.put(5, "pet")
.put(6, "šest")
.put(7, "sedam")
.put(8, "osam")
.put(9, "devet")
.put(10, "deset")
.put(11, "jedanaest")
.put(12, "dvanaest")
.put(13, "trinaest")
.put(14, "četrnaest")
.put(15, "petnaest")
.put(16, "šestnaest")
.put(17, "sedamnaest")
.put(18, "osamnaest")
.put(19, "devetnaest")
.put(20, "dvadeset")
.put(30, "trideset")
.put(40, "četrdeset")
.put(50, "pedeset")
.put(60, "šezdeset")
.put(70, "sedamdeset")
.put(80, "osamdeset")
.put(90, "devedeset")
.put(100, "sto")
.put(200, "dvesta")
.put(300, "trista")
.put(400, "četristo")
.put(500, "petsto")
.put(600, "šeststo")
.put(700, "sedamsto")
.put(800, "osamsto")
.put(900, "devetsto")
.build();
}

@Override
public List<PluralForms> pluralForms() {
return Arrays.asList(
new SlavonicPluralForms("", "", ""),
new SlavonicPluralForms("hiljada", "hiljade", "hiljada", GenderType.FEMININE),
new SlavonicPluralForms("milion", "miliona", "miliona", GenderType.MASCULINE),
new SlavonicPluralForms("milijarda", "milijarde", "milijardi", GenderType.FEMININE));
}

@Override
public String currency() {
return "RSD";
}

@Override
public char twoDigitsNumberSeparator() {
return ' ';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import static pl.allegro.finance.tradukisto.MoneyConverters.BRAZILIAN_PORTUGUESE
import static pl.allegro.finance.tradukisto.MoneyConverters.RUSSIAN_BANKING_MONEY_VALUE
import static pl.allegro.finance.tradukisto.MoneyConverters.SLOVAK_BANKING_MONEY_VALUE
import static pl.allegro.finance.tradukisto.MoneyConverters.UKRAINIAN_BANKING_MONEY_VALUE
import static pl.allegro.finance.tradukisto.MoneyConverters.SERBIAN_BANKING_MONEY_VALUE

class MoneyConvertersTest extends Specification {

Expand Down Expand Up @@ -66,6 +67,11 @@ class MoneyConvertersTest extends Specification {
UKRAINIAN_BANKING_MONEY_VALUE.asWords(1_234.56) == "одна тисяча двісті тридцять чотири ₴ 56/100"
}

def "should convert money in Serbian"() {
expect:
SERBIAN_BANKING_MONEY_VALUE.asWords(1_234.56) == "jedna hiljada dvesta trideset četiri RSD 56/100"
}

def "should throw exception when null given"() {
when:
POLISH_BANKING_MONEY_VALUE.asWords(null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package pl.allegro.finance.tradukisto.internal.languages.serbian

import spock.lang.Specification
import spock.lang.Unroll

import static pl.allegro.finance.tradukisto.internal.Container.serbianContainer

class SerbianValuesTest extends Specification {

static converter = serbianContainer().getNumbersConverter()

@Unroll
def "should convert #value to '#words' in Serbian"() {
expect:
converter.asWords(value) == words

where:
value | words
0 | "nula"
1 | "jedan"
2 | "dva"
3 | "tri"
4 | "četiri"
5 | "pet"
6 | "šest"
7 | "sedam"
8 | "osam"
9 | "devet"

11 | "jedanaest"
12 | "dvanaest"
13 | "trinaest"
14 | "četrnaest"
15 | "petnaest"
16 | "šestnaest"
17 | "sedamnaest"
18 | "osamnaest"
19 | "devetnaest"

10 | "deset"
20 | "dvadeset"
30 | "trideset"
40 | "četrdeset"
50 | "pedeset"
60 | "šezdeset"
70 | "sedamdeset"
80 | "osamdeset"
90 | "devedeset"

21 | "dvadeset jedan"
37 | "trideset sedam"
43 | "četrdeset tri"
58 | "pedeset osam"
69 | "šezdeset devet"
76 | "sedamdeset šest"
82 | "osamdeset dva"
95 | "devedeset pet"

100 | "sto"
200 | "dvesta"
300 | "trista"
400 | "četristo"
500 | "petsto"
600 | "šeststo"
700 | "sedamsto"
800 | "osamsto"
900 | "devetsto"

111 | "sto jedanaest"
272 | "dvesta sedamdeset dva"
387 | "trista osamdeset sedam"
448 | "četristo četrdeset osam"
569 | "petsto šezdeset devet"
625 | "šeststo dvadeset pet"
782 | "sedamsto osamdeset dva"
895 | "osamsto devedeset pet"
999 | "devetsto devedeset devet"

1_000 | "jedna hiljada"
2_000 | "dve hiljade"
5_000 | "pet hiljada"
7_634 | "sedam hiljada šeststo trideset četiri"
24_190 | "dvadeset četiri hiljade sto devedeset"
653_000 | "šeststo pedeset tri hiljade"
123_454 | "sto dvadeset tri hiljade četristo pedeset četiri"
700_000 | "sedamsto hiljada"
999_999 | "devetsto devedeset devet hiljada devetsto devedeset devet"

1_000_000 | "jedan milion"
2_000_000 | "dva miliona"
5_000_000 | "pet miliona"
23_437_219 | "dvadeset tri miliona četristo trideset sedam hiljada dvesta devetnaest"
100_000_000 | "sto miliona"
123_456_789 | "sto dvadeset tri miliona četristo pedeset šest hiljada sedamsto osamdeset devet"

1_000_000_000 | "jedna milijarda"
Integer.MAX_VALUE | "dve milijarde sto četrdeset sedam miliona četristo osamdeset tri hiljade šeststo četrdeset sedam"

}
}

0 comments on commit 5eff82e

Please sign in to comment.