I am using embedded .resx to localize an asp.net application. It seems that no matter what the current culture is, the neutral culture resource is always returned. The code I am using to retrieve the value is as follows:
protected string GetResource(string name)
{
return Localization.ResCore.ResourceManager.GetString(name, System.Threading.Thread.CurrentThread.CurrentCulture);
}
I've specified in one page that the culture is "es-PE" (Peru). When I break in the GetResource function, I can verify that CurrentCulture is "es-PE" and that the ResourceManager contains a ResourceSet corresponding this culture. However, the string returned is always from the neutral culture set.
The files I am embedding are named as follows:
Any help is appreciated.
Upvotes: 0
Views: 5327
Reputation: 993
If you want to use resources, you can change your second parameter from
System.Threading.Thread.CurrentThread.CurrentCulture
to
System.Threading.Thread.CurrentThread.CurrentUICulture
Upvotes: 1
Reputation: 8444
Just wondering why you need to embed it? Can't you just add to to the App-LocalResources and App-GlobalResources and use it from there?
Also, you'll find that if you don't call base.InitializeCulture(), the language will work erratically. You would create a base page and inherit from that. Like this:
protected class BasePage : System.Web.UI.Page
{
protected override void InitializeCulture(object sender, EventArgs e)
{
this.Culture = Resources.Culture = Thread.CurrentThread.CurrentUICulture;
base.InitializeCulture();
}
}
I hope this helps.
Upvotes: 0
Reputation: 9575
Why you are not using GetLocalResourceObject or GetLocalResourceObject?
Upvotes: 0