Android multiple dotted strings with dotted identifier names

I am currently developing an Android application that heavily uses android resource strings for internationalization. Each string identifier name has a specific format, e.g.

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

in the code, I can reference the string with:

 R.string.example_string_name_identifier 

and this works fine for regular strings. But as soon as I use this format for multiple 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 definition of plural lines 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 the code I refer to the plural:

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

Unfortunately, the company I work for really wants me to stick to this picture. Is it possible to use this template with string lines, or do we need to rename the identifier?

+6
source share
1 answer

How do you extract 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 only use the name "_". Any dot int he name gives me the same problem next to the dot as the first character of the name.

+1
source

Source: https://habr.com/ru/post/970933/


All Articles