1

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."

Dan
  • 101
  • 1
  • 15

1 Answers1

0

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.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • I changed the line so it included new ResourceManager("myApp.ui.resx", typeof(myForm).Assembly); and it still is erroring out. – Dan Sep 22 '15 at 14:57
  • @dan remove that .resx from first parameter and pass `"MyApp.ui"` – Reza Aghaei Sep 22 '15 at 15:02
  • @Dan let me know if it fixed the problem. – Reza Aghaei Sep 22 '15 at 15:04
  • Can I ask another related question... how do you generate the files? I have tried everything I can think of. Creating new resx files and such but I just cant get it to properly reference the localized files. Is there some walkthrough online somewhere for this? – Brandon Sep 30 '15 at 22:52
  • 1
    @Brandon add resource files using Add New Item window and then edit those files in designer for example add strings.resx, then for other cultures you want to support, add strings.es.resx, strings.fr.resx, strings.fa.resx, ... . You can also take a look at [How to: Create a Localized Version of a Resource File](https://msdn.microsoft.com/en-us/library/vstudio/aa992030.aspx) Hope you find the answer helpful:) – Reza Aghaei Oct 01 '15 at 07:39
  • @RezaAghaei Thanks, I did finally figure it out after I posted that. I was making copies of the resources.resx file and thought it had something to with the backing cs file not generating any code. As it turns out it was just a namepace issue. I was referencing it by [projectnamespace].[folderwithresxfiles] but my files were called Language.[culture].resx. I didn't realize that it adds the file name "Language" to the namespace by convention. So I had to use [projectnamespace].[folder].Language. The convention stuff is great if you know what, or why, it is happening but a pain if you don't! lol – Brandon Oct 01 '15 at 14:55