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

[gnc-ui-utils.cpp] use icu::RBNF to convert numbers to long strings #1913

Draft
wants to merge 2 commits into
base: stable
Choose a base branch
from

Conversation

christopherlam
Copy link
Contributor

result:

Number 123456789.010000 in words: one hundred twenty-three million four hundred fifty-six thousand seven hundred eighty-nine point zero one

Number 12.000000 in words: 十二

Number 123456789.010000 in words: 一億二千三百四十五万六千七百八十九・〇一

Number 2345.23 in words: deux mille trois cent quarante-cinq virgule deux trois

Number 2345.23 in words: 二千三百四十五・二三

@jralls
Copy link
Member

jralls commented Apr 11, 2024

Is there a use-case for this other than printing checks? Does anybody besides Americans write out the check's value in words as well as write the numerals? (Back in 1972 when my family went to England for 4 months my mom got a bank account there and wrote checks. I think they were pretty much like American ones, but that was more than 50 years ago.)

When writing a check in the USA we write (using your shorter example) "Two thousand three hundred forty-five and 23/100". "Dollars" is pre-printed at the end of the line.
I've never encountered anyone writing out "point", though it would make sense if the string was destined for an audio function that was going to speak it.

@christopherlam
Copy link
Contributor Author

rewritten in the much nicer boost::locale

@christopherlam
Copy link
Contributor Author

https://www.co-operativebank.co.uk/help-and-support/payments/cheques/

They advocate writing "only" irrespective of the amount...

@jralls
Copy link
Member

jralls commented Apr 12, 2024

And also writing out "pounds", "and" and "pence", with the number of pence written out as words, rather different from the custom in the USA. How do you write the amount in Australia?
@fellen How do you do it in Germany?

Incidentally some in the US recommend when handwriting checks to draw a line from the fraction to the end if there's space, for example https://www.thebalancemoney.com/how-to-write-a-check-4019395, though only one of the half-dozen or so "how to write a check" sites I looked at did that, but all of them inserted "and" before the fraction.

It seems we should create a US format string and make it translatable with instructions on the placeholders in a translator comment.

@christopherlam christopherlam force-pushed the icu-rbnf branch 4 times, most recently from d180161 to b118339 Compare April 13, 2024 10:47
@christopherlam
Copy link
Contributor Author

@jralls see word substitution for check printing

@jralls
Copy link
Member

jralls commented Apr 13, 2024

@christopherlam That's not localized, and what's the point of concocting a private formatting function? Use boost::locale::format.

There's a much better formatting and I/O library, {fmt} that's being piecewise added to the C++ standard as std::format beginning with C++20, but both inclusion and implementation in libc++ and libstdc++ have been slow. We should aim towards replacing boost::locale::format with it in the near term and all use of std::iostreams in the longer term.

@christopherlam
Copy link
Contributor Author

I didn't use boost format because it requires that all format variables are used. And I felt it would be better to have more flexibility, allowing eg integer words, integer numbers, fraction words, fraction numbers as options.

@jralls
Copy link
Member

jralls commented Apr 14, 2024

OK, but that doesn't do any good unless you mark the string for translation and document the construction thoroughly for translators with a translator comment. Not only can most translators not understand code, they can't even see it in Weblate without significant effort.

@christopherlam
Copy link
Contributor Author

The format string would be best IMHO be a global preference rather than a translatable string. I figure most users would prefer being able to fine tune rather than rely on random translators. I felt this branch would be a temporary until we plug into the preference mechanism.

@jralls
Copy link
Member

jralls commented Apr 14, 2024

The format string would be best IMHO be a global preference rather than a translatable string. I figure most users would prefer being able to fine tune rather than rely on random translators. I felt this branch would be a temporary until we plug into the preference mechanism.

OK, that might be true at least for some users. Temporary tends to stay for a long time around here so at least comment it thoroughly including a FIXME or TODO about creating a preference.

It does occur to me that @cstim commented about the untranslatability 17 years ago and there are no bugs about it so maybe only English speakers (maybe even only Americans) use the check printing and there's no actual point to localizing it. Maybe you should add one as an enhancement request to create another reminder to add the preference.

@cstim
Copy link
Member

cstim commented Apr 14, 2024

Yes, I would claim this isn't used in any other country anyway. Hence you can quite safely ignore the translatability here.

@jralls
Copy link
Member

jralls commented Apr 14, 2024

Yes, I would claim this isn't used in any other country anyway. Hence you can quite safely ignore the translatability here.

Hmm, it kind of follows that localizing the number-strings doesn't make sense either and it should be just left alone.

@jralls
Copy link
Member

jralls commented May 16, 2024

@christopherlam Do you still want to pursue this?

@christopherlam
Copy link
Contributor Author

@christopherlam Do you still want to pursue this?

This branch aims to use ICU instead of hand rolling the number->string routine... It could be limited to English words and two decimal places only if you like

@jralls
Copy link
Member

jralls commented May 17, 2024

The problem is that we have a particular use for that conversion and the ICU wording doesn't fit it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants