Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/github_actions/dependabot/fetch…
Browse files Browse the repository at this point in the history
…-metadata-2.2.0
  • Loading branch information
jglaszka authored Jan 3, 2025
2 parents 3fc6800 + 8ee5ca4 commit de5f8ea
Show file tree
Hide file tree
Showing 69 changed files with 3,304 additions and 3,123 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 @@ -29,6 +30,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 Down Expand Up @@ -103,12 +105,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 @@ -189,21 +191,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 @@ -264,6 +271,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
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import spock.lang.Unroll
import static pl.allegro.finance.tradukisto.LongValueConverters.ENGLISH_LONG
import static pl.allegro.finance.tradukisto.LongValueConverters.HINDI_LONG
import static pl.allegro.finance.tradukisto.LongValueConverters.POLISH_LONG
import static pl.allegro.finance.tradukisto.LongValueConverters.RUSSIAN_LONG
import static pl.allegro.finance.tradukisto.LongValueConverters.SWEDISH_LONG
import static pl.allegro.finance.tradukisto.LongValueConverters.JAPANESE_KANJI_LONG

Expand All @@ -19,6 +20,7 @@ class LongValueConvertersTest extends Specification {
where:
language | converter || number
"English" | ENGLISH_LONG || "one quintillion"
"Russian" | RUSSIAN_LONG || "один квинтиллион"
"Polish" | POLISH_LONG || "jeden trylion"
"Hindi" | HINDI_LONG || "दस शंख"
"Swedish" | SWEDISH_LONG || "en triljon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import static pl.allegro.finance.tradukisto.MoneyConverters.HINDI_BANKING_MONEY_
import static pl.allegro.finance.tradukisto.MoneyConverters.ITALIAN_BANKING_MONEY_VALUE
import static pl.allegro.finance.tradukisto.MoneyConverters.JAPANESE_BANKING_MONEY_VALUE
import static pl.allegro.finance.tradukisto.MoneyConverters.KAZAKH_BANKING_MONEY_VALUE
import static pl.allegro.finance.tradukisto.MoneyConverters.KYRGYZ_BANKING_MONEY_VALUE
import static pl.allegro.finance.tradukisto.MoneyConverters.LATVIAN_BANKING_MONEY_VALUE
import static pl.allegro.finance.tradukisto.MoneyConverters.POLISH_BANKING_MONEY_VALUE
import static pl.allegro.finance.tradukisto.MoneyConverters.RUSSIAN_BANKING_MONEY_VALUE
Expand Down Expand Up @@ -47,6 +48,7 @@ class MoneyConvertersTest extends Specification {
"Italian" | ITALIAN_BANKING_MONEY_VALUE || "milleduecentotrentaquattro € 56/100"
"Japanese" | JAPANESE_BANKING_MONEY_VALUE || "千二百三十四 円 56/100"
"Kazakh" | KAZAKH_BANKING_MONEY_VALUE || "бір мың екі жүз отыз төрт KZT 56/100"
"Kyrgyz" | KYRGYZ_BANKING_MONEY_VALUE || "бир миң эки жүз отуз төрт сом 56/100"
"Latvian" | LATVIAN_BANKING_MONEY_VALUE || "viens tūkstotis divi simti trīsdesmit četri EUR 56/100"
"Polish" | POLISH_BANKING_MONEY_VALUE || "jeden tysiąc dwieście trzydzieści cztery PLN 56/100"
"Serbian Cyrillic" | SERBIAN_CYRILLIC_BANKING_MONEY_VALUE || "једна хиљада двеста тридесет четири РСД 56/100"
Expand Down
Loading

0 comments on commit de5f8ea

Please sign in to comment.