Search code examples
c#resxcultureinfo

Change cultureinfo and get correct resx translation


Im trying to use the following code to get translation from my swedish resx but it will only return the english translation from my default resx. I have the translations in both file with the exact same key. I call this from a command line c# program. Anyone know why it will not translate?

public String GetString(String resxPackageName, String xmlKey)
{            
    Thread.CurrentThread.CurrentCulture = new CultureInfo("sv-SE", false);
    ResourceManager rm = new ResourceManager("MyPackage.CustomerPortal.Followup", this.GetType().Assembly);
    return rm.GetString("CurrentPriceTagTranslation");
}

Solution

  • I think that if you don't specify a culture in GetString method it will use the CurrentUICulture of the calling thread, if you change it everything should work.