Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android string plurals with dot separated identifier names

I'm currently developing an Android app which heavily uses the android resource strings for internationalization. Every string identifier name has a specific format such as

<string name="example.string.name.identifier">Example</string>

in code I can reference the string with:

R.string.example_string_name_identifier

and this works perfectly fine for normal strings. But as soon as I use this format for plural identifier names, I get the following error:

error: Error retrieving parent for item: No resource found that matches the given name 'example.plural.name'

The string plural definition is as follows:

<plurals name="example.plural.name.identifier">
    <item quantity="one">Example</item>
    <item quantity="other">Examples</item>
    <item quantity="zero">Examples</item>
</plurals>

and in code I reference the plural with:

// _amount is a function parameter
String exampleString = getResources().getQuantityString(R.plurals.example_plural_name_identifier, _amount, _amount);

Unfortunately the company I'm working in, really wants me to stick with this pattern. Is there any possibility to use this pattern with string plurals or do we have to rename the identifier?

like image 878
blackfizz Avatar asked Jun 17 '14 08:06

blackfizz


1 Answers

How do you retrieve the plural?

Example:

int number=2;
Resources res = getResources();
String quantityString = res.getQuantityString(R.plurals.example.plural.name.identifier, number, number);

Well It seems that you can use only '_' in name. Any dot int he name gives me the same problem beside dot as the first character of name.

like image 102
Nexowski Avatar answered Oct 21 '22 03:10

Nexowski