Skip to content

Commit

Permalink
Merge branch 'master' into support_for_Greek
Browse files Browse the repository at this point in the history
  • Loading branch information
jglaszka authored Jan 3, 2025
2 parents 62771da + 8ee5ca4 commit 1178429
Show file tree
Hide file tree
Showing 71 changed files with 3,359 additions and 3,120 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ With Tradukisto, you can now transform numbers into their word equivalents easy
* 🇮🇹 Italian
* 🇯🇵 Japanese (KANJI)
* 🇰🇿 Kazakh
* 🇰🇬 Kyrgyz
* 🇱🇻 Latvian
* 🇵🇱 Polish
* 🇷🇺 Russian
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
import java.util.Objects;

import static pl.allegro.finance.tradukisto.internal.Container.croatianContainer;
import static pl.allegro.finance.tradukisto.internal.Container.dutchContainer;
import static pl.allegro.finance.tradukisto.internal.Container.englishContainer;
import static pl.allegro.finance.tradukisto.internal.Container.polishContainer;
import static pl.allegro.finance.tradukisto.internal.Container.hindiContainer;
import static pl.allegro.finance.tradukisto.internal.Container.swedishContainer;
import static pl.allegro.finance.tradukisto.internal.Container.japaneseKanjiContainer;
import static pl.allegro.finance.tradukisto.internal.Container.polishContainer;
import static pl.allegro.finance.tradukisto.internal.Container.russianContainer;
import static pl.allegro.finance.tradukisto.internal.Container.swedishContainer;

public enum LongValueConverters {

CROATIAN_LONG(croatianContainer().getLongConverter()),
ENGLISH_LONG(englishContainer().getLongConverter()),
RUSSIAN_LONG(russianContainer().getLongConverter()),
POLISH_LONG(polishContainer().getLongConverter()),
HINDI_LONG(hindiContainer().getLongConverter()),
SWEDISH_LONG(swedishContainer().getLongConverter()),
JAPANESE_KANJI_LONG(japaneseKanjiContainer().getLongConverter());
JAPANESE_KANJI_LONG(japaneseKanjiContainer().getLongConverter()),
DUTCH_LONG(dutchContainer().getLongConverter());

private final LongToStringConverter converter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static pl.allegro.finance.tradukisto.internal.Container.ukrainianContainer;
import static pl.allegro.finance.tradukisto.internal.Container.bulgarianContainer;
import static pl.allegro.finance.tradukisto.internal.Container.dutchContainer;
import static pl.allegro.finance.tradukisto.internal.Container.kyrgyzContainer;

public enum MoneyConverters {

Expand All @@ -44,6 +45,7 @@ public enum MoneyConverters {
SLOVAK_BANKING_MONEY_VALUE(slovakContainer().getBankingMoneyConverter()),
LATVIAN_BANKING_MONEY_VALUE(latvianContainer().getBankingMoneyConverter()),
KAZAKH_BANKING_MONEY_VALUE(kazakhContainer().getBankingMoneyConverter()),
KYRGYZ_BANKING_MONEY_VALUE(kyrgyzContainer().getBankingMoneyConverter()),
UKRAINIAN_BANKING_MONEY_VALUE(ukrainianContainer().getBankingMoneyConverter()),
TURKISH_BANKING_MONEY_VALUE(turkishContainer().getBankingMoneyConverter()),
SERBIAN_BANKING_MONEY_VALUE(serbianContainer().getBankingMoneyConverter()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum ValueConverters {
SLOVAK_INTEGER(Container.slovakContainer().getIntegerConverter(), "sk"),
LATVIAN_INTEGER(Container.latvianContainer().getIntegerConverter(), "lv"),
KAZAKH_INTEGER(Container.kazakhContainer().getIntegerConverter(), "kk"),
KYRGYZ_INTEGER(Container.kyrgyzContainer().getIntegerConverter(), "ky"),
UKRAINIAN_INTEGER(Container.ukrainianContainer().getIntegerConverter(), "uk"),
SERBIAN_INTEGER(Container.serbianContainer().getIntegerConverter(), Arrays.asList("sr", getLanguageCodeFor("sr", "Latn"))),
SERBIAN_CYRILLIC_INTEGER(Container.serbianCyrillicContainer().getIntegerConverter(), getLanguageCodeFor("sr", "Cyrl")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pl.allegro.finance.tradukisto.internal.languages.czech.CzechValues;
import pl.allegro.finance.tradukisto.internal.languages.czech.CzechValuesForSmallNumbers;
import pl.allegro.finance.tradukisto.internal.languages.dutch.DutchIntegerToWordsConverter;
import pl.allegro.finance.tradukisto.internal.languages.dutch.DutchLongToWordsConverter;
import pl.allegro.finance.tradukisto.internal.languages.dutch.DutchThousandToWordsConverter;
import pl.allegro.finance.tradukisto.internal.languages.dutch.DutchValues;
import pl.allegro.finance.tradukisto.internal.languages.english.AmericanEnglishValues;
Expand All @@ -33,6 +34,7 @@
import pl.allegro.finance.tradukisto.internal.languages.japanese.JapaneseThousandToWordsConverter;
import pl.allegro.finance.tradukisto.internal.languages.japanese.JapaneseValues;
import pl.allegro.finance.tradukisto.internal.languages.kazakh.KazakhValues;
import pl.allegro.finance.tradukisto.internal.languages.kyrgyz.KyrgyzValues;
import pl.allegro.finance.tradukisto.internal.languages.latvian.LatvianValues;
import pl.allegro.finance.tradukisto.internal.languages.polish.PolishValues;
import pl.allegro.finance.tradukisto.internal.languages.portuguese.BrazilianPortugueseValues;
Expand All @@ -46,6 +48,7 @@
import pl.allegro.finance.tradukisto.internal.languages.slovak.SlovakValuesForSmallNumbers;
import pl.allegro.finance.tradukisto.internal.languages.slovene.SloveneThousandToWordsConverter;
import pl.allegro.finance.tradukisto.internal.languages.slovene.SloveneValues;
import pl.allegro.finance.tradukisto.internal.languages.spanish.SpanishBigDecimalToBankingMoneyConverter;
import pl.allegro.finance.tradukisto.internal.languages.spanish.SpanishIntegerToWordsConverter;
import pl.allegro.finance.tradukisto.internal.languages.spanish.SpanishIntegerToWordsConverterAdapter;
import pl.allegro.finance.tradukisto.internal.languages.spanish.SpanishThousandToWordsConverter;
Expand Down Expand Up @@ -106,12 +109,12 @@ public static Container sloveneContainer() {
SloveneValues values = new SloveneValues();

SloveneThousandToWordsConverter sloveneThousandToWordsConverter = new SloveneThousandToWordsConverter(
values.baseNumbers());
values.baseNumbers());

IntegerToStringConverter converter = new NumberToWordsConverter(sloveneThousandToWordsConverter, values.pluralForms());

BigDecimalToStringConverter bigDecimalBankingMoneyValueConverter = new BigDecimalToBankingMoneyConverter(
converter, values.currency());
converter, values.currency());

return new Container(converter, null, bigDecimalBankingMoneyValueConverter);
}
Expand Down Expand Up @@ -209,21 +212,26 @@ public static Container germanContainer() {
}

public static Container dutchContainer() {

DutchValues values = new DutchValues();

DutchThousandToWordsConverter dutchThousandToWordsConverter =
new DutchThousandToWordsConverter(values.baseNumbers());

IntegerToStringConverter converter = new DutchIntegerToWordsConverter(
new NumberToWordsConverter(dutchThousandToWordsConverter, values.pluralForms()), values.exceptions(),
new NumberToWordsConverter(dutchThousandToWordsConverter, values.pluralForms()),
values.exceptions(),
dutchThousandToWordsConverter
);

LongToStringConverter dutchLongToWordsConverter = new DutchLongToWordsConverter(
dutchThousandToWordsConverter,
values.pluralForms()
);

BigDecimalToStringConverter bigDecimalBankingMoneyValueConverter =
new BigDecimalToBankingMoneyConverter(converter, values.currency());

return new Container(converter, null, bigDecimalBankingMoneyValueConverter);
return new Container(converter, dutchLongToWordsConverter, bigDecimalBankingMoneyValueConverter);
}

public static Container italianContainer() {
Expand Down Expand Up @@ -284,6 +292,11 @@ public static Container kazakhContainer() {
return new Container(kazakhValues);
}

public static Container kyrgyzContainer() {
KyrgyzValues kyrgyzValues = new KyrgyzValues();
return new Container(kyrgyzValues);
}

public static Container hindiContainer() {
HindiValues hindiValues = new HindiValues();

Expand Down Expand Up @@ -318,7 +331,7 @@ public static Container spanishContainer() {
spanishThousandToWordsConverter
);

BigDecimalToStringConverter bigDecimalBankingMoneyValueConverter = new BigDecimalToBankingMoneyConverter(
BigDecimalToStringConverter bigDecimalBankingMoneyValueConverter = new SpanishBigDecimalToBankingMoneyConverter(
converter,
values.currency()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public String asWords(BigDecimal value, String currencySymbol) {
return format(FORMAT, converter.asWords(units), currencySymbol, subunits);
}

private void validate(BigDecimal value) {
protected void validate(BigDecimal value) {
Assert.isTrue(value.scale() <= MAXIMAL_DECIMAL_PLACES_COUNT,
() -> String.format("can't transform more than %s decimal places for value %s", MAXIMAL_DECIMAL_PLACES_COUNT, value));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package pl.allegro.finance.tradukisto.internal.languages.dutch;

import pl.allegro.finance.tradukisto.internal.GenderAwareIntegerToStringConverter;
import pl.allegro.finance.tradukisto.internal.LongToStringConverter;
import pl.allegro.finance.tradukisto.internal.languages.GenderType;
import pl.allegro.finance.tradukisto.internal.languages.PluralForms;
import pl.allegro.finance.tradukisto.internal.support.Assert;
import pl.allegro.finance.tradukisto.internal.support.NumberChunking;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import static java.util.Collections.reverse;

public class DutchLongToWordsConverter implements LongToStringConverter {

private final NumberChunking numberChunking = new NumberChunking();

private final GenderAwareIntegerToStringConverter hundredsToWordsConverter;
private final List<PluralForms> pluralForms;

public DutchLongToWordsConverter(
GenderAwareIntegerToStringConverter hundredsToWordsConverter,
List<PluralForms> pluralForms
) {
this.hundredsToWordsConverter = hundredsToWordsConverter;
this.pluralForms = pluralForms;
}

@Override
public String asWords(Long value) {
Assert.isTrue(value >= 0, () -> String.format("can't convert negative numbers for value %d", value));

List<String> result = new ArrayList<>();

long bigNumber = value / 1000000;
long smallNumber = value % 1000000;

if (bigNumber > 0) {
List<Integer> valueChunks = numberChunking.chunk(bigNumber);
List<PluralForms> formsToUse = getRequiredFormsInReversedOrder(valueChunks.size());
result.add(joinValueChunksWithForms(valueChunks.iterator(), formsToUse.iterator()));
}

if (smallNumber > 0) {
result.add(hundredsToWordsConverter.asWords((int) smallNumber, GenderType.NON_APPLICABLE));
}

return joinParts(result);
}

protected List<PluralForms> getRequiredFormsInReversedOrder(int chunks) {
List<PluralForms> formsToUse = new ArrayList<>(pluralForms.subList(0, chunks));
reverse(formsToUse);
return formsToUse;
}

protected String joinValueChunksWithForms(Iterator<Integer> chunks, Iterator<PluralForms> formsToUse) {
List<String> result = new ArrayList<>();

while (chunks.hasNext() && formsToUse.hasNext()) {
Integer currentChunkValue = chunks.next();
PluralForms currentForms = formsToUse.next();

if (currentChunkValue > 0) {
String words = hundredsToWordsConverter.asWords(currentChunkValue, currentForms.genderType());
result.add(words);
result.add(currentForms.formFor(currentChunkValue));
}
}

return joinParts(result);
}

protected String joinParts(List<String> result) {
return result.isEmpty()
? hundredsToWordsConverter.asWords(0, pluralForms.get(0).genderType())
: String.join(" ", result).trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import java.util.Map;

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.RegularPluralForms;

import static java.util.Collections.singletonMap;

Expand Down Expand Up @@ -63,7 +65,10 @@ public Map<Integer, String> exceptions() {
public List<PluralForms> pluralForms() {
return Arrays.asList(
new DutchPluralForms("miljoen"),
new DutchPluralForms("miljard")
new DutchPluralForms("miljard"),
new DutchPluralForms("biljoen"),
new DutchPluralForms("biljard"),
new DutchPluralForms("triljoen")
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package pl.allegro.finance.tradukisto.internal.languages.kyrgyz;

import pl.allegro.finance.tradukisto.internal.languages.GenderType;
import pl.allegro.finance.tradukisto.internal.languages.PluralForms;

public class KyrgyzPluralForms implements PluralForms {

private String form;

public KyrgyzPluralForms(String form) {
this.form = form;
}

@Override
public String formFor(Integer value) {
return form;
}

@Override
public GenderType genderType() {
return GenderType.NON_APPLICABLE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package pl.allegro.finance.tradukisto.internal.languages.kyrgyz;

import pl.allegro.finance.tradukisto.internal.BaseValues;
import pl.allegro.finance.tradukisto.internal.languages.GenderForms;
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.support.BaseNumbersBuilder.baseNumbersBuilder;

public class KyrgyzValues implements BaseValues {

@Override
public Map<Integer, GenderForms> baseNumbers() {
return baseNumbersBuilder()
.put(0, "нөл")
.put(1, "бир")
.put(2, "эки")
.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 KyrgyzPluralForms(""),
new KyrgyzPluralForms("миң"),
new KyrgyzPluralForms("миллион"),
new KyrgyzPluralForms("миллиард")
);
}

@Override
public String currency() {
return "сом";
}

@Override
public char twoDigitsNumberSeparator() {
return ' ';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public List<PluralForms> pluralForms() {
new SlavicPluralForms("", "", "", GenderType.MASCULINE),
new SlavicPluralForms("тысяча", "тысячи", "тысяч", GenderType.FEMININE),
new SlavicPluralForms("миллион", "миллиона", "миллионов", GenderType.MASCULINE),
new SlavicPluralForms("миллиард", "миллиарда", "миллиардов", GenderType.MASCULINE)
new SlavicPluralForms("миллиард", "миллиарда", "миллиардов", GenderType.MASCULINE),
new SlavicPluralForms("триллион", "триллиона", "триллионов", GenderType.MASCULINE),
new SlavicPluralForms("квадриллион", "квадриллиона", "квадриллионов", GenderType.MASCULINE),
new SlavicPluralForms("квинтиллион", "квинтиллиона", "квинтиллионов", GenderType.MASCULINE)
);
}

Expand Down
Loading

0 comments on commit 1178429

Please sign in to comment.