views:

75

answers:

3

I have some messages being passed back from my server through php. The problem is that the messages are in English and if the user is using another language they will still get the message in English.

So I had an idea that maybe instead of passing back the message I would instead pass the String resource Id from the android app, that way the app will get the correct string id for their language. I will use this in a number of apps so I just want to know if the string id is guaranteed to be the same across different android projects?

+4  A: 

No.

The string resource IDs are likely not even guaranteed to be the same between re-compilations of the same application (e.g. differences between versions of aapt).

Christopher
A: 

Christopher is right, but you can pass a parameter to your server like http://example.com/script.php?lang=en or lang=fr ....

This way the php scripts can use this parameter to return messages in the relevant locale.

Gautier Hayoun
A: 

You can get the resource ID from a string:

int resID = getResources().getIdentifier("org.my.package:strings/my_string",     null, null);
// or
int resID = getResources().getIdentifier("my_string", "strings", "org.my.package");
Moss