开发者

Are string resource ID values guaranteed to be consistent over different projects?

开发者 https://www.devze.com 2023-01-02 07:21 出处:网络
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 mes

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?


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 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.


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");
0

精彩评论

暂无评论...
验证码 换一张
取 消