views:

1395

answers:

3

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:

  • ResCore.resx
  • ResCore.es.resx
  • ResCore.es-PE.resx

Any help is appreciated.

A: 

Why you are not using GetLocalResourceObject or GetLocalResourceObject?

arbiter
I was under the impression that to use GetGlobalResourceObject the resource file must be in the App_GlobalResources folder at the root of the web application. I would like to keep the resource file embedded in the assembly.
The App_GlobalResources route is inaccessible to tests exercising your code. Embedding your resources into a dll makes your code testable.
Adam Kahtava
A: 

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.

Dominic Zukiewicz
A: 

If you want to use resources, you can change your second parameter from

System.Threading.Thread.CurrentThread.CurrentCulture

to

System.Threading.Thread.CurrentThread.CurrentUICulture
intangible02