NumToText icon indicating copy to clipboard operation
NumToText copied to clipboard

Gender displays incorrectly for Russian fractional units

Open denismosolov opened this issue 6 years ago • 4 comments

In russian language letters at the end of the last digit depend on the gender, ex: один рубль but одна копейка.

        $price = Price::toText(1.01, [['рублей', 'рубль', 'рубля'], ['копеек', 'копейка', 'копейки']], 'RU');
        $this->assertEqualsIgnoringCase(
            'один рубль одна копейка',
            $price
        );
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'один рубль одна копейка'
+'один рубль один копейка'

https://github.com/ivanovsaleksejs/NumToText/blob/master/src/NumToText_RU.php#L51

For russian language it should use $this->digits[$digit + 9] instead of $this->digits[$digit] for decimal part(копейка) if its ($digit == 1 || $digit == 2) && $this->step == 1.

I'm not sure how to check (inside the digitToWord method) if a digit comes from decimal part or the number. @ivanovsaleksejs I wonder if you have an idea how we can check it?

denismosolov avatar Jun 20 '20 13:06 denismosolov

I think there's no way to check the gender which would work in all cases. And for russian there's also "middle" gender (одно песо). This means that there should be the way to tell the gender to the function. I will take a look and add a fix shortly.

ivanovsaleksejs avatar Jun 24 '20 08:06 ivanovsaleksejs

Added genders parameter in https://github.com/ivanovsaleksejs/NumToText/commit/9f36245a028a222ca7cc3b3587ce9c764c487708. Please check if issue still exists.

ivanovsaleksejs avatar Jun 25 '20 19:06 ivanovsaleksejs

Can you pleas confirm it's fixed?

ivanovsaleksejs avatar Jun 30 '20 15:06 ivanovsaleksejs

Sorry for the late reply.

Unit test looks awesome, so I think it would would work as expected. But I will confirm within a few days, please do not close the issue, I'd like to reflect changes in README.md.

I've missed одно пессо, nice catch and thank you very much for the update! It makes my voice assistant which relies on NumToText much more natural.

denismosolov avatar Jul 01 '20 19:07 denismosolov