I want to localize numbers by spelling them out with a locale and ended up using ICU4J. I succeeded in many locales but didn't seem to get it done for a few like Georgian, Turkish or Arabic.
ULocale locale = new ULocale("Tr"); //Turkish
Double d = Double.parseDouble(input);
NumberFormat formatter = new RuleBasedNumberFormat(locale, RuleBasedNumberFormat.SPELLOUT);
String result = formatter.format(d);
When I debug the ruleset inside by formatter object seems empty and it prints out in English(as default I guess).
In ICU website it is written that: ICU provides number spellout rules for several locales, but not for all of the locales that ICU supports, and not all of the predefined rule types. Also, as of release 2.6, some of the provided rules are known to be incomplete.
But it seems ICU's own demo page can do it for that locales too(http://demo.icu-project.org/icu4jweb/numero.jsp)
I also can locate .res files in the icu5j-53.1.jar under my .m2 folder (\icu4j-53.1\com\ibm\icu\impl\data\icudt53b\rbnf)
Would appreciate any help about how the demo page can manage to do it and why I can't?
I've tested your code with version 53.1 and got correct Turkish output. I then retested with version 3.4.4 and got English output as you described in your question.
Most likely, you are pulling in an older version through a transitive maven dependency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With