如何在Android中按名称动态获取语言环境字符串?

如何在Android中按名称动态获取语言环境字符串?,android,localization,xamarin.android,Android,Localization,Xamarin.android,我正在使用一个库,它提供了一个本地化接口ILocalize,它有一个方法 string GetLocale(string constant); 在Android上,我使用的是一个标准的资源文件。如果常量是“TestString”,并且我的资源文件的字符串将被访问r.strings.TestString——但这显然只适用于硬编码,那么我如何从常量(从字符串常量映射到Android字符串资源ID)动态获取字符串呢?有时很容易错过它: int resId = context.Resources.Ge

我正在使用一个库,它提供了一个本地化接口
ILocalize
,它有一个方法

string GetLocale(string constant);

在Android上,我使用的是一个标准的资源文件。如果
常量
是“TestString”,并且我的资源文件的字符串将被访问
r.strings.TestString
——但这显然只适用于硬编码,那么我如何从
常量
(从字符串常量映射到Android字符串资源ID)动态获取字符串呢?

有时很容易错过它:

int resId = context.Resources.GetIdentifier(constant, "string", context.PackageName);
if(resId == 0)
{
    return constant;
}
return context.GetString(resId);