1
votes

I'm trying to get localization working in my application. I have my ui resource files, named "ui.resx" and "ui.de.resx" in my solution. However, something in my implementation is incorrect, and I'm stumped.

ResourceManager res_man;
CultureInfo culture;
string exception;

private void myForm_Load(object sender, EventArgs e)
{
    culture = CultureInfo.CreateSpecificCulture("de");
    res_man = new ResourceManager("MyApp.ui.resx", typeof(myForm).Assembly);
    doTheThing();
}

private void doTheThing()
{
    try
    {
        BTN_save.text = ui.SAVE;
        //Do code here
    }
    catch(Exception e)
    {
        exception = e.toString();
    }
}

When I run the program, it errors out and exception reads:

"Exception: System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "ui.resx.resources" was correctly embedded or linked into assembly "myProgram" at compile time, or that all the satellite assemblies required are loadable and fully signed."

1

1 Answers

0
votes

You should use the full name (with namespace) of your class as first parameter lik:

var resman= new ResourceManager("Sample.Resources", typeof(Resources).Assembly);

To know what name you should use, open ui.cs under the ui.resx node and look at the namespace of the class and the class name and use them as shown above.

Pay attention that you should not pass "MyApp.ui.resx", instead pass "MyApp.ui"

Then you can simply use the manager to get a resource for specific culture like this:

var str = resman.GetString("YourResourceKey", culture);

Note:

Another thing you should notice, there is more simple way to read culture specific resources. You can simply set :

var culture= ...    

System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
System.Threading.Thread.CurrentThread.CurrentCulture = culture;

After setting culture, wherever you use for example MyApp.Ui.Key the value of the Key specific to that culture will be used.