Giter Site home page Giter Site logo

allegro / tradukisto Goto Github PK

View Code? Open in Web Editor NEW
197.0 14.0 88.0 819 KB

A Java i18n library created to convert numbers to their word representations.

License: Apache License 2.0

Java 49.98% Groovy 50.02%
i18n internationalization java numbers-to-text human-readable hacktoberfest

tradukisto's Introduction

Tradukisto

Build codecov Maven Central

Introduction

Tradukisto is a powerful Java library designed to convert numbers into their corresponding word representations.

Our main motivation is to create a production-ready tool providing number conversion for the Polish language. We recognized the need for a well-tested and ready solution that eliminates the hassle of copying and pasting code from different sources. With Tradukisto, you can now transform numbers into their word equivalents easy way!

Features

  • Converts Integer to String with numerical representation support.
  • Converts Long to String with numerical representation support.
  • Converts BigDecimal to String with money representation support.

Supported languages

  • 🇧🇷🇵🇹 Brazilian Portuguese
  • 🇧🇬 Bulgarian
  • 🇭🇷 Croatian
  • 🇨🇿 Czech
  • 🇳🇱 Dutch
  • 🇬🇧 English
  • 🇫🇷 French
  • 🇩🇪 German
  • 🇮🇳 Hindi
  • 🇮🇹 Italian
  • 🇯🇵 Japanese (KANJI)
  • 🇰🇿 Kazakh
  • 🇱🇻 Latvian
  • 🇵🇱 Polish
  • 🇷🇺 Russian
  • 🇷🇸 Serbian (Cyrillic)
  • 🇷🇸 Serbian (Latin)
  • 🇸🇰 Slovak
  • 🇸🇮 Slovene / Slovenian
  • 🇪🇸 Spanish
  • 🇸🇪 Swedish
  • 🇹🇷 Turkish
  • 🇺🇦 Ukrainian

Is your language missing from the list? We encourage you to contribute to our project.

Usage

See article on our Wiki

Contributing

If you are first-time contributor, articles "Create your first Pull Request" and "How to implement new language? " may be helpful.

Changelog

Each release is documented in the release notes.

tradukisto's People

Contributors

aboruhen avatar aleksandarni avatar altro3 avatar anarak404 avatar bartlomiejgraczyk avatar bgalek avatar blarne avatar dependabot[bot] avatar dilaverdemirel avatar dorians avatar fatosmorina avatar gavrilovniki avatar ghim9182 avatar girdharsourabh avatar github-actions[bot] avatar icrnjak avatar ilikeyourhat avatar jglaszka avatar luismateoh avatar ma-go-src avatar maciejlipinski avatar michalkuzma21 avatar mkosmul avatar pawelkowalski92 avatar r055a avatar rpanecki avatar rudinew avatar tabatad avatar thomaszangerl avatar wjur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tradukisto's Issues

Russian language bug

While implementing Latvian test, I found a bug in Russian plural forms.
These are valid assertions which will fail if you add them to RussianValuesTest:

        21_000        | "двадцать одна тысяча"
        51_000        | "пятьдесят одна тысяча"
        481_000       | "четыреста восемьдесят одна тысяча"

I don't speak Polish language so I can't fix it without splitting SlavonicPluralFroms into Russian+fix and Polish as is.

Add support for Estonian

Tradukisto is the library what converts numbers to human-readable words - for example from 14 to fourteen. This issue was created to add support for counting in new language. Depending on how numeral system in your language is similar to other languages (english, arabic, german, slavic) and how many exceptions it have - it can be easy or more demanding.

Implementing unit tests will be really helpful for you, I encourage you to create them first (TDD paradigm), before developing new changes in the code. You can run them in terminal with ./gradlew test or green button in Intellij code editor.

New language needs to have implementation for Container. Depending on how your language works, having conjugation, gender forms, custom chunking (typically divider is for 3 numbers) etc it may be needed to define more advanced container with custom implementations for counting, for example turkish. Tests will really be helpful for you to see if it needs custom implementations or not.

Also define Values - translations for base numers and for plural forms (thousands, millions etc).
Feel free to ask if you have more questions, we will try to help you.
https://github.com/allegro/tradukisto/wiki/How-to-start-contributing

French language support

Hello, you do a really good job i just create this issue because I think i'm not authorized to create a branch, so if you could add some modifications for French language it would be very nice:
in ValueConverters add :
import static pl.allegro.finance.tradukisto.internal.Container.frenchContainer;
FRENCH_INTEGER(frenchContainer().getNumbersConverter())

in ValueConvertersTest add:

def "should convert numbers in French"() {
        expect:
        FRENCH_INTEGER.asWords(1_234) == "un mille deux cent trente-quatre"
    }

if you want to be more precise, FRENCH_INTEGER.asWords(1_234) should return "mille deux cent trente-quatre" instead of "un mille deux cent trente-quatre", in french when we have one thousand (and other number) we don't write the one (like brazilian i think):
ex: 1000 = mille (one thousand)
1750 = mille sept cent cinquante (one thousand seven hundred fifty)
2000 = deux mille (two thousand)

Add support for Swedish

Tradukisto is the library what converts numbers to human-readable words - for example from 14 to fourteen. This issue was created to add support for counting in new language. Depending on how numeral system in your language is similar to other languages (english, arabic, german, slavic) and how many exceptions it have - it can be easy or more demanding.

Implementing unit tests will be really helpful for you, I encourage you to create them first (TDD paradigm), before developing new changes in the code. You can run them in terminal with ./gradlew test or green button in Intellij code editor.

New language needs to have implementation for Container. Depending on how your language works, having conjugation, gender forms, custom chunking (typically divider is for 3 numbers) etc it may be needed to define more advanced container with custom implementations for counting, for example turkish. Tests will really be helpful for you to see if it needs custom implementations or not.

Also define Values - translations for base numers and for plural forms (thousands, millions etc).
Feel free to ask if you have more questions, we will try to help you.
https://github.com/allegro/tradukisto/wiki/How-to-start-contributing

Add support for Maltese

Tradukisto is the library what converts numbers to human-readable words - for example from 14 to fourteen. This issue was created to add support for counting in new language. Depending on how numeral system in your language is similar to other languages (english, arabic, german, slavic) and how many exceptions it have - it can be easy or more demanding.

Implementing unit tests will be really helpful for you, I encourage you to create them first (TDD paradigm), before developing new changes in the code. You can run them in terminal with ./gradlew test or green button in Intellij code editor.

New language needs to have implementation for Container. Depending on how your language works, having conjugation, gender forms, custom chunking (typically divider is for 3 numbers) etc it may be needed to define more advanced container with custom implementations for counting, for example turkish. Tests will really be helpful for you to see if it needs custom implementations or not.

Also define Values - translations for base numers and for plural forms (thousands, millions etc).
Feel free to ask if you have more questions, we will try to help you.
https://github.com/allegro/tradukisto/wiki/How-to-start-contributing

Issue with MoneyConverters(French)

Hi there, I've been looking all over the web for a library that fits my needs.
I was pleasantly surprised to come across yours.
The issue I'm facing now is the following:
I would like to convert a number(currency value) to its word representation, so I follow the steps as described in the README file. But for some reason the MoneyConverters enum does not contain a value for French even though a Container is available for it.
Is this an oversight or is it done on purpose?

My best regards

JDVB

Add support for Hindi

Tradukisto is the library what converts numbers to human-readable words - for example from 14 to fourteen. This issue was created to add support for counting in new language. Depending on how numeral system in your language is similar to other languages (english, arabic, german, slavic) and how many exceptions it have - it can be easy or more demanding.

Implementing unit tests will be really helpful for you, I encourage you to create them first (TDD paradigm), before developing new changes in the code. You can run them in terminal with ./gradlew test or green button in Intellij code editor.

New language needs to have implementation for Container. Depending on how your language works, having conjugation, gender forms, custom chunking (typically divider is for 3 numbers) etc it may be needed to define more advanced container with custom implementations for counting, for example turkish. Tests will really be helpful for you to see if it needs custom implementations or not.

Also define Values - translations for base numers and for plural forms (thousands, millions etc).
Feel free to ask if you have more questions, we will try to help you.
https://github.com/allegro/tradukisto/wiki/How-to-start-contributing

Add support for Greek

Tradukisto is the library what converts numbers to human-readable words - for example from 14 to fourteen. This issue was created to add support for counting in new language. Depending on how numeral system in your language is similar to other languages (english, arabic, german, slavic) and how many exceptions it have - it can be easy or more demanding.

Implementing unit tests will be really helpful for you, I encourage you to create them first (TDD paradigm), before developing new changes in the code. You can run them in terminal with ./gradlew test or green button in Intellij code editor.

New language needs to have implementation for Container. Depending on how your language works, having conjugation, gender forms, custom chunking (typically divider is for 3 numbers) etc it may be needed to define more advanced container with custom implementations for counting, for example turkish. Tests will really be helpful for you to see if it needs custom implementations or not.

Also define Values - translations for base numers and for plural forms (thousands, millions etc).
Feel free to ask if you have more questions, we will try to help you.
https://github.com/allegro/tradukisto/wiki/How-to-start-contributing

Add longConverter for Dutch

It would be good, if we will have support for long number conversion for Dutch. Currently it is not implemented.
Integer and Money conwerters for Dutch were implemented in #69.

Additional context
Unit tests are already written in DutchValuesTest, but currently marked as @Ignore. See: def "should convert long #value to '#words' in Dutch"() { // test cases}

Add methods to ValueConverters getByLocale and getByLanguageCode

It is often necessary to return a ValueConverters based on the locale that is set on the system. It would be cool to add the ability to take the necessary converter by locale or language code to ValueConverters.

Like this:

    public ValueConverters getByLocale(Locale locale) {

        if (locale == null) {
            throw new IllegalArgumentException("Locale is null");
        }

        return getByLanguageCode(locale.getLanguage());
    }

    public ValueConverters getByLanguageCode(String languageCode) {

        if (languageCode == null || languageCode.isEmpty()) {
            throw new IllegalArgumentException("Language code is null or empty: " + languageCode);
        }

        switch( languageCode.toLowerCase(Locale.ENGLISH) ){
            case "ru":
                return ValueConverters.RUSSIAN_INTEGER;
            case "cs":
                return ValueConverters.CZECH_INTEGER;
            case "fr":
                return ValueConverters.FRENCH_INTEGER;
            case "de":
                return ValueConverters.GERMAN_INTEGER;
            case "it":
                return ValueConverters.ITALIAN_INTEGER;
            case "uk":
                return ValueConverters.UKRAINIAN_INTEGER;
            case "tr":
                return ValueConverters.TURKISH_INTEGER;
            case "kk":
                return ValueConverters.KAZAKH_INTEGER;
            case "lv":
                return ValueConverters.LATVIAN_INTEGER;
            case "pt":
            case "pt-br":
                return ValueConverters.BRAZILIAN_PORTUGUESE_INTEGER;
            case "pl":
                return ValueConverters.POLISH_INTEGER;
            case "sr":
                return ValueConverters.SERBIAN_INTEGER;
            case "sk":
                return ValueConverters.SLOVAK_INTEGER;
            default:
                return ValueConverters.ENGLISH_INTEGER;
        }
    }

Add support for Lithuanian

Tradukisto is the library what converts numbers to human-readable words - for example from 14 to fourteen. This issue was created to add support for counting in new language. Depending on how numeral system in your language is similar to other languages (english, arabic, german, slavic) and how many exceptions it have - it can be easy or more demanding.

Implementing unit tests will be really helpful for you, I encourage you to create them first (TDD paradigm), before developing new changes in the code. You can run them in terminal with ./gradlew test or green button in Intellij code editor.

New language needs to have implementation for Container. Depending on how your language works, having conjugation, gender forms, custom chunking (typically divider is for 3 numbers) etc it may be needed to define more advanced container with custom implementations for counting, for example turkish. Tests will really be helpful for you to see if it needs custom implementations or not.

Also define Values - translations for base numers and for plural forms (thousands, millions etc).
Feel free to ask if you have more questions, we will try to help you.
https://github.com/allegro/tradukisto/wiki/How-to-start-contributing

Some of the slavic languages can share class PluralForms

copied from #65 (comment):
I see that identical logic is in other slavic languages - russian, ukrainian, bulgarian - so this class in future could be refactored into shared one class. In polish 121 000 000 is plural (sto dwadzieścia jeden milionów), because for polish people every number over 1 is plural. It looks that in other slavic languages numbers ending on 1 (but not 11) is singular:

HR: sto dvadeset jedan milijun
RU: сто двадцать один миллион
UK: сто двадцять один мільйон
So I think we could move polish code into PolishPluralForms and other slavic into SlavonicPluralForms.

Add support for Hungarian

Tradukisto is the library what converts numbers to human-readable words - for example from 14 to fourteen. This issue was created to add support for counting in new language. Depending on how numeral system in your language is similar to other languages (english, arabic, german, slavic) and how many exceptions it have - it can be easy or more demanding.

Implementing unit tests will be really helpful for you, I encourage you to create them first (TDD paradigm), before developing new changes in the code. You can run them in terminal with ./gradlew test or green button in Intellij code editor.

New language needs to have implementation for Container. Depending on how your language works, having conjugation, gender forms, custom chunking (typically divider is for 3 numbers) etc it may be needed to define more advanced container with custom implementations for counting, for example turkish. Tests will really be helpful for you to see if it needs custom implementations or not.

Also define Values - translations for base numers and for plural forms (thousands, millions etc).
Feel free to ask if you have more questions, we will try to help you.
https://github.com/allegro/tradukisto/wiki/How-to-start-contributing

Add support for Romanian

Tradukisto is the library what converts numbers to human-readable words - for example from 14 to fourteen. This issue was created to add support for counting in new language. Depending on how numeral system in your language is similar to other languages (english, arabic, german, slavic) and how many exceptions it have - it can be easy or more demanding.

Implementing unit tests will be really helpful for you, I encourage you to create them first (TDD paradigm), before developing new changes in the code. You can run them in terminal with ./gradlew test or green button in Intellij code editor.

New language needs to have implementation for Container. Depending on how your language works, having conjugation, gender forms, custom chunking (typically divider is for 3 numbers) etc it may be needed to define more advanced container with custom implementations for counting, for example turkish. Tests will really be helpful for you to see if it needs custom implementations or not.

Also define Values - translations for base numers and for plural forms (thousands, millions etc).
Feel free to ask if you have more questions, we will try to help you.
https://github.com/allegro/tradukisto/wiki/How-to-start-contributing

Awesome dependency!

I love your code, but I'm trying to extend to create an AmericanValues really based on the EnglishValues except for the pound sign £, and use the $ sign. This would be great if you had this. Again, awesome library much nicer to use than ICU4J.

Issues with French numbers

French is a complicated language, and writing numbers to letters is filled with exceptions.

The library is currently failing on several cases, some of them being very basic.

  • "21" returns vingt-un, should be vingt-et-un (same for 31, 41, etc.)
  • "200" returns deux cent, should be deux cents (same for 300, 400, etc.)

Also, a rectification from 1990 made the syntax more straightforward, with everything being hyphened as long as it's not million or milliard (billions).

A personal preference would therefore to be compatible with the latest update rather than the deprecated version, and "200" would then return deux-cents.

I'll write a PR with lots of failing tests.
I can't tell whether or when I'll be able to fix the production code to make them pass.

Add docs on wiki

For users:

  • Easy "Getting started"

Contributing:

  • How can I contribute?
    -- Reporting Bugs
    -- Adding suggestions in Issues
    -- Pull Requests
    -- How to start contributing: - how to fork, local testing, opening PR

  • Architecture and main flow/algorithm of the translating number to word

  • Gender, PluralForms, chunks, bigNumbersConverter, smallNumbersConverter

  • How to add support for your language?

Maintainers:

  • How to release?

Russian language support

Verified test values:

Value Words
0 ноль
1 один
2 два
3 три
4 четыре
5 пять
6 шесть
7 семь
8 восемь
9 девять
11 одиннадцать
12 двенадцать
13 тринадцать
14 четырнадцать
15 пятнадцать
16 шестнадцать
17 семнадцать
18 восемнадцать
19 девятнадцать
10 десять
20 двадцать
30 тридцать
40 сорок
50 пятьдесят
60 шестьдесят
70 семьдесят
80 восемьдесят
90 девяносто
21 двадцать один
37 тридцать семь
43 сорок три
58 пятьдесят восемь
69 шестьдесят девять
76 семьдесят шесть
82 восемьдесят два
95 девяносто пять
100 сто
200 двести
300 триста
400 четыреста
500 пятьсот
600 шестьсот
700 семьсот
800 восемьсот
900 девятьсот
111 сто одиннадцать
272 двести семьдесят два
387 триста восемьдесят семь
448 четыреста сорок восемь
569 пятьсот шестьдесят девять
625 шестьсот двадцать пять
782 семьсот восемьдесят два
895 восемьсот девяносто пять
999 девятьсот девяносто девять
1 000 одна тысяча
2 000 две тысячи
5 000 пять тысяч
7 634 семь тысяч шестьсот тридцать четыре
24 190 двадцать четыре тысячи сто девяносто
653 000 шестьсот пятьдесят три тысячи
123 454 сто двадцать три тысячи четыреста пятьдесят четыре
700 000 семьсот тысяч
999 999 девятьсот девяносто девять тысяч девятьсот девяносто девять
1 000 000 один миллион
2 000 000 два миллиона
5 000 000 пять миллионов
23 437 219 двадцать три миллиона четыреста тридцать семь тысяч двести девятнадцать
100 000 000 сто миллионов
123 456 789 сто двадцать три миллиона четыреста пятьдесят шесть тысяч семьсот восемьдесят девять
1 000 000 000 один миллиард
2 147 483 647 два миллиарда сто сорок семь миллионов четыреста восемьдесят три тысячи шестьсот сорок семь

1.10.3 version causing dependency issues for com.google.common.collect package

Updating to the latest version of this library 1.10.3 from 1.3.0 causes issues importing the google collect packages when a maven build is run on a project using this library. The build wouldnt work unless an com.google.guava dependency is added to the parent pom.

Some dev notes incase it is useful. There is a difference in pom between the two versions where 1.3.0 included a com.google.guava compile dependency while 1.10.3 is missing that dependency.

com.google.guava guava 23.0 compile org.spockframework spock-core 1.1-groovy-2.4 test

Add support for Finnish

Tradukisto is the library what converts numbers to human-readable words - for example from 14 to fourteen. This issue was created to add support for counting in new language. Depending on how numeral system in your language is similar to other languages (english, arabic, german, slavic) and how many exceptions it have - it can be easy or more demanding.

Implementing unit tests will be really helpful for you, I encourage you to create them first (TDD paradigm), before developing new changes in the code. You can run them in terminal with ./gradlew test or green button in Intellij code editor.

New language needs to have implementation for Container. Depending on how your language works, having conjugation, gender forms, custom chunking (typically divider is for 3 numbers) etc it may be needed to define more advanced container with custom implementations for counting, for example turkish. Tests will really be helpful for you to see if it needs custom implementations or not.

Also define Values - translations for base numers and for plural forms (thousands, millions etc).
Feel free to ask if you have more questions, we will try to help you.
https://github.com/allegro/tradukisto/wiki/How-to-start-contributing

Add support for Slovenian

Tradukisto is the library what converts numbers to human-readable words - for example from 14 to fourteen. This issue was created to add support for counting in new language. Depending on how numeral system in your language is similar to other languages (english, arabic, german, slavic) and how many exceptions it have - it can be easy or more demanding.

Implementing unit tests will be really helpful for you, I encourage you to create them first (TDD paradigm), before developing new changes in the code. You can run them in terminal with ./gradlew test or green button in Intellij code editor.

New language needs to have implementation for Container. Depending on how your language works, having conjugation, gender forms, custom chunking (typically divider is for 3 numbers) etc it may be needed to define more advanced container with custom implementations for counting, for example turkish. Tests will really be helpful for you to see if it needs custom implementations or not.

Also define Values - translations for base numers and for plural forms (thousands, millions etc).
Feel free to ask if you have more questions, we will try to help you.
https://github.com/allegro/tradukisto/wiki/How-to-start-contributing

Remove guava

Tradukisto does not use guava cache - only a few helper methods from com.google.common.*.

todo:

  • Research if it is possible to replace it with plain java (with not reinventing the wheel)
  • Remove guava from dependencies

Enable language independent currency symbol

Allow for:

MoneyConverters converter = MoneyConverters.ENGLISH_BANKING_MONEY_VALUE;
String moneyAsWordsWithCurrency = converter.asWords(new BigDecimal("1234.56", "EUR"));
assertEquals("one thousand two hundred thirty-four EUR 56/100", moneyAsWordsWithCurrency);

Add image for "Social Preview"

Social preview image is image what shows up when someone shares link to the repo. We can customize it to have a nice look.
Screenshot 2023-07-11 at 3 33 48 PM

Note: Image should be at least 640×320px (1280×640px for best display).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.