davidraedev / WordToNumber

Convert Words To Numbers
MIT License
3 stars 1 forks source link

Support for French #4

Closed domi41 closed 4 years ago

domi41 commented 5 years ago

Hello !

Support for french won't be as easy as replacing the mapping.

I've added a test-case to my i18n-french branch.

Here's the excerpt :

public function testParseNumberInFrench() {

        $wordToNumber = new WordToNumber();
        $wordToNumber->setLanguage( 'french' );

        $checks = [
            "zéro" => "0",
            "zero" => "0",
            "un" => "1",
            "quarante-deux" => "42",
            "soixante-treize" => "73",
            "soixante treize" => "73",
            "quatre vingt treize" => "93",
            "cent" => "100",
            "cent sept" => "107",
            "cent soixante-dix" => "170",
            "cent soixante treize" => "173",
            "cent soixante treize mille" => "173000",
            "cent soixante treize million" => "173000000",
            "cent soixante treize millions" => "173000000",
            "cent soixante treize millions deux mille" => "173002000",
        ];

        foreach ( $checks as $check => $expected ) {
            $result = $wordToNumber->parse( $check );
            if ( $expected !== $result ) {
                $this->fail( "'$check' yielded '$result' instead of expected '$expected'." );
            }
        }
    }

How do you feel about ISO639 for language codes ? Perhaps one with the variants, such as fr_FR?

Any ideas on how to proceed with I18N using custom parsers for each language ?

To enable I18N, we need to:

domi41 commented 5 years ago

I've pushed to my branch some changes that implement the above, hopefully without breaking too much.

One caveat: things like twenty eleven yield 31 now.


I also pushed some small fixes to the english large number mapping.

davidraedev commented 5 years ago

That's excellent! I'm not familiar with complex numbers in other languages so I couldn't add them, but I figured the easiest way to do it would be to just provide different parsers for each language like you suggested since they are all different and have different edge cases. I'm pretty busy right now, but will take a look when I have a chance. Thanks!

domi41 commented 4 years ago

Merged in #5