-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added slovene support * update README.md * updated long values * updated long values * removed unused imports * updated test cases * corrected tests * renamed methods in SlovenePluralForms'
- Loading branch information
Showing
10 changed files
with
356 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
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
51 changes: 51 additions & 0 deletions
51
src/main/java/pl/allegro/finance/tradukisto/internal/languages/SlovenePluralForms.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,51 @@ | ||
package pl.allegro.finance.tradukisto.internal.languages; | ||
|
||
import pl.allegro.finance.tradukisto.internal.support.Range; | ||
|
||
public class SlovenePluralForms implements PluralForms { | ||
private final String singularForm; | ||
private final String dualForm; | ||
private final String pluralForm; | ||
private final String genitivePluralForm; | ||
|
||
private final GenderType genderType; | ||
|
||
public SlovenePluralForms(String singularForm, String dualForm, String pluralForm, String genitivePluralForm, GenderType genderType) { | ||
this.singularForm = singularForm; | ||
this.dualForm = dualForm; | ||
this.pluralForm = pluralForm; | ||
this.genitivePluralForm = genitivePluralForm; | ||
this.genderType = genderType; | ||
} | ||
|
||
@Override | ||
public String formFor(Integer value) { | ||
if (shouldUseSingularForm(value)) { | ||
return singularForm; | ||
} | ||
if (shouldUseDualForm(value)) { | ||
return dualForm; | ||
} | ||
if (shouldUsePluralForm(value)) { | ||
return pluralForm; | ||
} | ||
return genitivePluralForm; | ||
} | ||
|
||
private boolean shouldUseSingularForm(Integer value) { | ||
return value == 1 || value % 100 == 1; | ||
} | ||
|
||
private boolean shouldUseDualForm(Integer value) { | ||
return value == 2 || value % 100 == 2; | ||
} | ||
|
||
private boolean shouldUsePluralForm(Integer value) { | ||
return Range.closed(3, 4).contains(value % 100); | ||
} | ||
|
||
@Override | ||
public GenderType genderType() { | ||
return genderType; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...llegro/finance/tradukisto/internal/languages/slovene/SloveneThousandToWordsConverter.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.slovene; | ||
|
||
import pl.allegro.finance.tradukisto.internal.GenderAwareIntegerToStringConverter; | ||
import pl.allegro.finance.tradukisto.internal.languages.GenderForms; | ||
import pl.allegro.finance.tradukisto.internal.languages.GenderType; | ||
import pl.allegro.finance.tradukisto.internal.support.Range; | ||
|
||
import java.util.Map; | ||
|
||
import static java.lang.String.format; | ||
|
||
public class SloveneThousandToWordsConverter implements GenderAwareIntegerToStringConverter { | ||
|
||
private final Map<Integer, GenderForms> baseValues; | ||
|
||
public SloveneThousandToWordsConverter(Map<Integer, GenderForms> baseValues) { | ||
this.baseValues = baseValues; | ||
} | ||
|
||
@Override | ||
public String asWords(Integer value, GenderType genderType) { | ||
if (baseValues.containsKey(value)) { | ||
return baseValues.get(value).formFor(genderType); | ||
} | ||
if (Range.closed(21, 99).contains(value)) { | ||
return twoDigitsNumberAsString(value); | ||
} | ||
if (Range.closed(101, 999).contains(value)) { | ||
return threeDigitsNumberAsString(value, genderType); | ||
} | ||
throw new IllegalArgumentException(format("Can't convert %d", value)); | ||
} | ||
|
||
private String twoDigitsNumberAsString(Integer value) { | ||
Integer units = value % 10; | ||
Integer tens = value - units; | ||
return format("%sin%s", asWords(units, GenderType.FEMININE), asWords(tens, GenderType.FEMININE)); | ||
} | ||
|
||
private String threeDigitsNumberAsString(Integer value, GenderType genderType) { | ||
Integer tensWithUnits = value % 100; | ||
Integer hundreds = value - tensWithUnits; | ||
return format("%s %s", asWords(hundreds, genderType), asWords(tensWithUnits, genderType)); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/pl/allegro/finance/tradukisto/internal/languages/slovene/SloveneValues.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,78 @@ | ||
package pl.allegro.finance.tradukisto.internal.languages.slovene; | ||
|
||
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.SlovenePluralForms; | ||
|
||
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 SloveneValues implements BaseValues { | ||
@Override | ||
public Map<Integer, GenderForms> baseNumbers() { | ||
return baseNumbersBuilder() | ||
.put(0, "nič") | ||
.put(1, genderForms("en", "ena", "ena", "ena")) | ||
.put(2, genderForms("dva", "dve", "dve", "dva")) | ||
.put(3, genderForms("trije", "tri", "tri", "tri")) | ||
.put(4, genderForms("štirije", "štiri", "štiri", "štiri")) | ||
.put(5, "pet") | ||
.put(6, "šest") | ||
.put(7, "sedem") | ||
.put(8, "osem") | ||
.put(9, "devet") | ||
.put(10, "deset") | ||
.put(11, "enajst") | ||
.put(12, "dvanajst") | ||
.put(13, "trinajst") | ||
.put(14, "štirinajst") | ||
.put(15, "petnajst") | ||
.put(16, "šestnajst") | ||
.put(17, "sedemnajst") | ||
.put(18, "osemnajst") | ||
.put(19, "devetnajst") | ||
.put(20, "dvajset") | ||
.put(30, "trideset") | ||
.put(40, "štirideset") | ||
.put(50, "petdeset") | ||
.put(60, "šestdeset") | ||
.put(70, "sedemdeset") | ||
.put(80, "osemdeset") | ||
.put(90, "devetdeset") | ||
.put(100, "sto") | ||
.put(200, "dvesto") | ||
.put(300, "tristo") | ||
.put(400, "štiristo") | ||
.put(500, "petsto") | ||
.put(600, "šeststo") | ||
.put(700, "sedemsto") | ||
.put(800, "osemsto") | ||
.put(900, "devetsto") | ||
.build(); | ||
} | ||
|
||
@Override | ||
public List<PluralForms> pluralForms() { | ||
return Arrays.asList( | ||
new SlovenePluralForms("", "", "", "", GenderType.FEMININE), | ||
new SlovenePluralForms("tisoč", "tisoč", "tisoč", "tisoč", GenderType.NEUTER), | ||
new SlovenePluralForms("milijon", "milijona", "milijone", "milijonov", GenderType.MASCULINE), | ||
new SlovenePluralForms("milijarda", "milijardi", "milijarde", "milijard", GenderType.FEMININE)); | ||
} | ||
|
||
@Override | ||
public String currency() { | ||
return "€"; | ||
} | ||
|
||
@Override | ||
public char twoDigitsNumberSeparator() { | ||
return ' '; | ||
} | ||
} |
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
Oops, something went wrong.