Reputation: 33048
I'm using a library that offers a localization interface ILocalize
which has a method
string GetLocale(string constant);
On Android I am working with a standard resource file. If the constant
is "TestString" and my resource file's string would be accessed r.strings.TestString
- but that obviously only works hardcoded, how can I dynamically get to the string from the constant
(map from a string constant to an Android string resource ID)?
Upvotes: 0
Views: 438
Reputation: 33048
Sometimes it's so easy to miss it:
int resId = context.Resources.GetIdentifier(constant, "string", context.PackageName);
if(resId == 0)
{
return constant;
}
return context.GetString(resId);
Upvotes: 2