Android Question Get language-specific Quantity strings (plurals)?

Jerryk

Member
Licensed User
Longtime User
I analyze the duration according to ISO 8601. (3M - means three months, 8W - eight weeks,...). But there is a problem of declination of time units depending on the number of units. E.g.

ENG : 1 month, 3 months ; 1 week, 8 weeks
CZ - 1 měsíc, 3 měsíce, 100 měsíců ; 1 týden, 8 týdnů

  • Can I get these language-specific inflectional units from Android (GetQuantityString?) or another library such as Mozilla's Fluent or ICU4J?
  • Alternatively, can I get abbreviated versions (mo, wk, yr, min,...) also depending on the language?
  • Or how to solve it elegantly?
 

drgottjr

Expert
Licensed User
Longtime User
i know nothing about icu4j, but it was trivial to cobble together an example which seems to do what you're looking to do.
it may be simple enough to use the library directly with a javaobject.
download the latest icu4j.jar from maven and put it in your additional libraries folder.
build the attached example. the output should be similar to what you see below.
on the down side, the library adds some 13MB's to your project, which is kind of a high price to pay for 1 function.
you may have to consider a different library. if your only purpose relates to plurals, it might be possible to extract the
relevant class from source and use that class alone. wrapping the whole library is a big project, given all the classes
and methods in it. it's still going to be enormous, wrapped or unwrapped.

if you are not familiar with the project or if the size of the library is too big for your purposes, then please disregard this post
and wait for someone else to comment on a different solution.

also, note: although you can use icu4j directly, android supports a sub-set, called android.icu. you can use this already with b4a without importing icu4j, but it does not handle all the methods and classes of icu4j. it does, however, support your interest in pluralization. just substitute "android.icu" where you see "com.ibm.icu" in the example.
 

Attachments

  • icu4j.zip
    9.1 KB · Views: 35
  • icu4j.txt
    196 bytes · Views: 31
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…