Localization with SharpDevelop

I am working on a localized app that I am developing in SharpDevelop. Based on the tutorial I ran into the error:

Could not find resources matching the specified culture (or neutral culture) on disk. baseName:

I created a ressource file using Project | Add | The new item corresponds to "Empty ressource file" (I couldn't find "Assembly resource file"). Also, I have set the "Build action" to "EmbeddedResource".

Inside the program, I have a class that does the following

// load the resource file once
resourceManager = ResourceManager.CreateFileBasedResourceManager(file, filePath, null);

// depending on user selection, I set the CultureInfo in the code behind the form, i.e.
Thread.CurrentThread.CurrentUICulture = locales[0];   // which contains "en"

// and that the method of the same class used to lookup the values
public string getValue ( string key )
{
    return resourceManager.GetString(key);
}

      

SharpDevelop 3.0.0.3437 .NET Version 2.0.50727.3053

Even after carefully reviewing comments and googling for a long time, I couldn't find an example or solution. Hence the questions:

  • How to add culture to ressource file?
  • Can you provide an example or link?

Many thanks!

+1


source to share


2 answers


CreateFileBasedResourceManager will only work with binaries .resources (not.resx).

If you insist on loading resources from an external file rather than embedding the resources in an assembly, you will need to run the resgen command line utility to generate the .resources file. So if you haven't, create one for each supported culture.

Otherwise it looks ok.

But if you prefer to embed resources in an assembly, in the properties window set Build Action to Embedded Resource.



If you also want to get a strongly typed class with all the dirty work in mind, set the Custom Tool for the base file (invariant) only to ResXFileCodeGenerator, or PublicResXFileCodeGenerator if you need it (useful when creating satellite assemblies).

Then you don't need to download localized resources yourself. The generated class does all of this for you.

For every resource key in the generated class, a static property is generated and you just call that property, this is a very clean and by far the easiest way.

Unless there is a specific reason to load resources from .resources files, I always recommend embedding them in assembly (s).

+1


source


I'm not sure which version of .NET you are using, but this MSDN article on How the Node Runtime Builds might be helpful to you.



0


source







All Articles