3

I'm encountering problems when using quantity string (plurals) in Android XML to get the appropriate pluralization if I need to default from an unsupported language.

Android plurals support creating multiple strings that are used as appropriate for the number quantity provided, so I have this in my strings.xml:

<plurals name ="hours">
    <item quantity="one">1 hour ago</item>
    <item quantity="other">%d hours ago</item>
</plurals>

and this in my code:

getQuantityString(R.plurals.hours, time, time);

This works fine if my device is set to English, but if I set my device to, say, Japanese, a language I don't yet support, it only uses the "other" quantity string and can produce the output

1 hours ago

Is there any way to have plurals give grammatical output while defaulting from an unsupported language?

Matt
  • 43
  • 4

2 Answers2

0

Japanese has no singular or plural form but it only has one unified form. With plurals Android uses other with Japanese all the time no matter that the count is. There is no way to turn this off. The best solution would be give a proper Japanese translation

%d時間前
Jaska
  • 1,007
  • 10
  • 9
  • While that works for Japanese, the issue here is that supporting every possible language is simply unfeasible. I want to be able to correctly default when defaulting from any unsupported language. – Matt Aug 11 '14 at 19:50
0

The main problem here is that it takes the plurals rules for the current locale, but applies them to the default strings which happen to be consistent with English.

What you can try here is to maintain a list of supported locales in the app and check if the current locale is supported. If it is, you do nothing. If it isn't, you can set the locale to English. This should make the system apply the rules for English. Changing Locale within the app itself can help you do that.

Community
  • 1
  • 1
Malcolm
  • 41,014
  • 11
  • 68
  • 91