Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hindi support #112

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import static pl.allegro.finance.tradukisto.internal.Container.croatianContainer;
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;

public enum LongValueConverters {

CROATIAN_LONG(croatianContainer().getLongConverter()),
ENGLISH_LONG(englishContainer().getLongConverter()),
POLISH_LONG(polishContainer().getLongConverter());
POLISH_LONG(polishContainer().getLongConverter()),
HINDI_LONG(hindiContainer().getLongConverter());

private final LongToStringConverter converter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pl.allegro.finance.tradukisto;

import pl.allegro.finance.tradukisto.internal.BigDecimalToStringConverter;
import pl.allegro.finance.tradukisto.internal.Container;

import java.math.BigDecimal;
import java.util.Objects;
Expand All @@ -24,7 +25,6 @@
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;

public enum MoneyConverters {

BRAZILIAN_PORTUGUESE_BANKING_MONEY_VALUE(brazilianPortugueseContainer().getBankingMoneyConverter()),
Expand All @@ -45,7 +45,8 @@ public enum MoneyConverters {
SERBIAN_CYRILLIC_BANKING_MONEY_VALUE(serbianCyrillicContainer().getBankingMoneyConverter()),
FRENCH_BANKING_MONEY_VALUE(frenchContainer().getBankingMoneyConverter()),
BULGARIAN_BANKING_MONEY_VALUE(bulgarianContainer().getBankingMoneyConverter()),
DUTCH_BANKING_MONEY_VALUE(dutchContainer().getBankingMoneyConverter());
DUTCH_BANKING_MONEY_VALUE(dutchContainer().getBankingMoneyConverter()),
HINDI_BANKING_MONEY_VALUE(Container.hindiContainer().getBankingMoneyConverter());

private final BigDecimalToStringConverter converter;

Expand Down
23 changes: 3 additions & 20 deletions src/main/java/pl/allegro/finance/tradukisto/ValueConverters.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,7 @@
import java.util.Locale;
import java.util.Objects;

import static pl.allegro.finance.tradukisto.internal.Container.brazilianPortugueseContainer;
import static pl.allegro.finance.tradukisto.internal.Container.bulgarianContainer;
import static pl.allegro.finance.tradukisto.internal.Container.croatianContainer;
import static pl.allegro.finance.tradukisto.internal.Container.czechContainer;
import static pl.allegro.finance.tradukisto.internal.Container.englishContainer;
import static pl.allegro.finance.tradukisto.internal.Container.frenchContainer;
import static pl.allegro.finance.tradukisto.internal.Container.germanContainer;
import static pl.allegro.finance.tradukisto.internal.Container.italianContainer;
import static pl.allegro.finance.tradukisto.internal.Container.kazakhContainer;
import static pl.allegro.finance.tradukisto.internal.Container.latvianContainer;
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.serbianContainer;
import static pl.allegro.finance.tradukisto.internal.Container.serbianCyrillicContainer;
import static pl.allegro.finance.tradukisto.internal.Container.slovakContainer;
import static pl.allegro.finance.tradukisto.internal.Container.turkishContainer;
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.*;
girdharsourabh marked this conversation as resolved.
Show resolved Hide resolved

public enum ValueConverters {

Expand All @@ -48,7 +30,8 @@ public enum ValueConverters {
BULGARIAN_INTEGER(bulgarianContainer().getIntegerConverter(), "bg"),
FRENCH_INTEGER(frenchContainer().getIntegerConverter(), "fr"),
TURKISH_INTEGER(turkishContainer().getIntegerConverter(), "tr"),
DUTCH_INTEGER(dutchContainer().getIntegerConverter(), "nl");
DUTCH_INTEGER(dutchContainer().getIntegerConverter(), "nl"),
HINDI_INTEGER(hindiContainer().getIntegerConverter(), "hi");

private final IntegerToStringConverter converter;
private final List<String> languageCodes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import pl.allegro.finance.tradukisto.internal.languages.german.GermanIntegerToWordsConverter;
import pl.allegro.finance.tradukisto.internal.languages.german.GermanThousandToWordsConverter;
import pl.allegro.finance.tradukisto.internal.languages.german.GermanValues;
import pl.allegro.finance.tradukisto.internal.languages.hindi.HindiBigDecimalToBankingMoneyConverter;
import pl.allegro.finance.tradukisto.internal.languages.hindi.HindiValues;
import pl.allegro.finance.tradukisto.internal.languages.hindi.IndianNumberToWordsConverter;
import pl.allegro.finance.tradukisto.internal.languages.italian.ItalianIntegerToWordsConverter;
import pl.allegro.finance.tradukisto.internal.languages.italian.ItalianThousandToWordsConverter;
import pl.allegro.finance.tradukisto.internal.languages.italian.ItalianValues;
Expand Down Expand Up @@ -226,6 +229,22 @@ public static Container kazakhContainer() {
return new Container(kazakhValues);
}

public static Container hindiContainer(){
girdharsourabh marked this conversation as resolved.
Show resolved Hide resolved
HindiValues hindiValues = new HindiValues();

HundredsToWordsConverter hundredsToStringConverter = new HundredsToWordsConverter(hindiValues.baseNumbers(),
hindiValues.twoDigitsNumberSeparator());

IntegerToStringConverter integerToStringConverter = new IndianNumberToWordsConverter(hundredsToStringConverter, hindiValues.pluralForms());

BigDecimalToStringConverter bigDecimalConverter = new HindiBigDecimalToBankingMoneyConverter(
integerToStringConverter,
hindiValues);
LongToStringConverter longValueConverters = new IndianNumberToWordsConverter(hundredsToStringConverter,hindiValues.pluralForms());
girdharsourabh marked this conversation as resolved.
Show resolved Hide resolved

return new Container(integerToStringConverter, longValueConverters, bigDecimalConverter);
}

private final IntegerToStringConverter integerConverter;
private final LongToStringConverter longConverter;
private final BigDecimalToStringConverter bigDecimalConverter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ 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));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package pl.allegro.finance.tradukisto.internal.languages.hindi;

import pl.allegro.finance.tradukisto.internal.BigDecimalToStringConverter;
import pl.allegro.finance.tradukisto.internal.IntegerToStringConverter;
import pl.allegro.finance.tradukisto.internal.support.Assert;

import java.math.BigDecimal;

import static java.lang.String.format;

/**
* @author Dilaver Demirel
girdharsourabh marked this conversation as resolved.
Show resolved Hide resolved
*/
public class HindiBigDecimalToBankingMoneyConverter implements BigDecimalToStringConverter {
private static final String SUBUNIT_SEPARATOR = ",";
private static final String FORMAT = "%s %s%s %s";
private static final int MAXIMAL_DECIMAL_PLACES_COUNT = 2;

private final IntegerToStringConverter converter;
private final HindiValues hindiValues;

public HindiBigDecimalToBankingMoneyConverter(IntegerToStringConverter converter, HindiValues hindiValues) {
this.converter = converter;
this.hindiValues = hindiValues;
}

@Override
public String asWords(BigDecimal value) {
return asWords(value, hindiValues.currency());
}

@Override
public String asWords(BigDecimal value, String currencySymbol) {
validate(value);

Integer units = value.intValue();
int subunits = value.remainder(BigDecimal.ONE).multiply(new BigDecimal(100)).intValue();

String tempSubunitSymbol = hindiValues.paiseSymbol();
String tempSubUnitWords = SUBUNIT_SEPARATOR + converter.asWords(subunits);
if (subunits <= 0) {
tempSubunitSymbol = "";
tempSubUnitWords = "";
}

String formattedValue = format(FORMAT, converter.asWords(units), currencySymbol, tempSubUnitWords, tempSubunitSymbol);
return formattedValue.replace(Character.toString(hindiValues.twoDigitsNumberSeparator()), "");
girdharsourabh marked this conversation as resolved.
Show resolved Hide resolved
}

private 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));

Assert.isTrue(valueLessThanIntMax(value),
() -> String.format("can't transform numbers greater than Integer.MAX_VALUE for value %s", value));

Assert.isTrue(valueGreaterThanOrEqualToZero(value),
() -> String.format("can't transform negative numbers for value %s", value));
}

private boolean valueLessThanIntMax(BigDecimal value) {
return value.compareTo(new BigDecimal(Integer.MAX_VALUE).add(BigDecimal.ONE)) < 0;
}

private boolean valueGreaterThanOrEqualToZero(BigDecimal value) {
return value.signum() >= 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package pl.allegro.finance.tradukisto.internal.languages.hindi;

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

public class HindiPluralForms implements PluralForms {
girdharsourabh marked this conversation as resolved.
Show resolved Hide resolved

private final String form;

public HindiPluralForms(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,164 @@
package pl.allegro.finance.tradukisto.internal.languages.hindi;

import pl.allegro.finance.tradukisto.internal.BaseValues;
import pl.allegro.finance.tradukisto.internal.languages.GenderForms;
import pl.allegro.finance.tradukisto.internal.languages.PluralForms;
import pl.allegro.finance.tradukisto.internal.languages.english.EnglishPluralForms;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import static pl.allegro.finance.tradukisto.internal.support.BaseNumbersBuilder.baseNumbersBuilder;

public class HindiValues 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(21,"इक्कीस")
.put(22,"बाईस")
.put(23,"तेईस")
.put(24,"चौबीस")
.put(25,"पच्चीस")
.put(26,"छब्बीस")
.put(27,"सत्ताईस")
.put(28,"अट्ठाईस")
.put(29,"उनतीस")
.put(30,"तीस")

.put(31,"इकत्तीस")
.put(32,"बत्तीस")
.put(33,"तेंतीस")
.put(34,"चौंतीस")
.put(35,"पैंतीस")
.put(36,"छत्तीस")
.put(37,"सैंतीस")
.put(38,"अड़तीस")
.put(39,"उनतालीस")
.put(40,"चालीस")

.put(41,"एकतालीस")
.put(42,"बायलीस")
.put(43,"तैंतालीस")
.put(44,"चौवालीस")
.put(45,"पैंतालिस")
.put(46,"छियालीस")
.put(47,"सैंतालीस")
.put(48,"अड़तालीस")
.put(49,"उनचास")
.put(50,"पचास")

.put(51,"इक्यबन")
.put(52,"बावन")
.put(53,"तिरपन")
.put(54,"चौवन")
.put(55,"पचपन")
.put(56,"छप्पन")
.put(57,"सत्तावन")
.put(58,"अट्ठावन")
.put(59,"उनसठ")
.put(60,"साठ")
girdharsourabh marked this conversation as resolved.
Show resolved Hide resolved
.put(61,"इकसठ")
.put(62,"बासठ")
.put(63,"तिरसठ")
.put(64,"चौंसठ")
.put(65,"पैंसठ")
.put(66,"छियासठ")
.put(67,"सड़सठ")
.put(68,"सड़सठ")
.put(69,"उनहत्तर")
.put(70,"सत्तर")

.put(71,"इकहत्तर")
.put(72,"बहत्तर")
.put(73,"तिहत्तर")
.put(74,"चौहत्तर")
.put(75,"पचहत्तर")
.put(76,"छीहत्तर")
.put(77,"सतहत्तर")
.put(78,"अठहत्तर")
.put(79,"उनासी")
.put(80,"असी")
.put(81,"इक्यासी")
.put(82,"बयासी")
.put(83,"तिरासी")
.put(84,"चौरासी")
.put(85,"पचासी")
.put(86,"छियासी")
.put(87,"सतासी")
.put(88,"अट्ठासी")
.put(89,"नवासी")
.put(90,"नब्बे")

.put(91,"इक्यानवे")
.put(92,"बानवे")
.put(93,"तिरानवे")
.put(94,"चौरानवे")
.put(95,"पचानवे")
.put(96,"छियानवे")
.put(97,"सतानवे")
.put(98,"अट्ठानवे")
.put(99,"निन्यानवे")

.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 EnglishPluralForms(""),
new EnglishPluralForms("हजार"),
new EnglishPluralForms("लाख"),
new EnglishPluralForms("करोड़"),
new EnglishPluralForms("अरब"),
new EnglishPluralForms("खरब"),
new EnglishPluralForms("नील"),
new EnglishPluralForms("पद्म"),
new EnglishPluralForms("शंख"),
new EnglishPluralForms("महाशंख"));
}

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

@Override
public char twoDigitsNumberSeparator() {
girdharsourabh marked this conversation as resolved.
Show resolved Hide resolved
return 0;
}

public String paiseSymbol(){
return "p";
}
}
Loading