Note that there are some explanatory texts on larger screens.

plurals
  1. POC#, Localization, Resources, and MonoDevelop
    primarykey
    data
    text
    <p><strong>My problem is this</strong>: Using MonoDevelop (which is the preferred environment for a number of projects I'm working on) I'm trying to figure out how to use resource files for localized messages and how to properly include them in the project as an embedded resource.</p> <p>My goal is to have a resources file with simple name-value pairs for message keys and their values, and have separate files for their localized strings e.g.</p> <p><strong>Messages.resources</strong></p> <pre><code>Hello.World = Hello World Goodbye.Cruel.World = Goodbye, Cruel World </code></pre> <p><strong>Messages.de.resources</strong></p> <pre><code>Hello.World = Hallo Welt Goodbye.Cruel.World = Auf Wiedersehen, grausame Welt </code></pre> <p>I'm having a couple of issues.</p> <p><strong>First</strong>, what is the difference (if any) between MonoDevelop's .resources file and Visual Studio's concept of resources. From what I understand, MonoDevelop (and SharpDevelop) allow you to create .resources files, whereas Visual Studio utilizes .resx files and compiles them into .resources files (a binary file type) through the resgen utility. When using resources in MonoDevelop do I need to compile my resources (e.g. Messages.resources) using resgen? When I try to use just the straight .resources files that MonoDevelop allows me to create through their wizard I get the following error:</p> <p><em>"Stream is not a valid resource file."</em></p> <p><strong>Second</strong>, once I have an appropriately generated resource file, I can embed them to my project, which if I understand it correctly, makes the resources a part of the assembly. If I have two files though, Messages.resources and Messages.de.resources, MonoDevelop (at least) assigns them the same ID value when I embed them. Do I need to have my default localization included in the project and then a separate project for each supported locale? Following up on this, how does C# distinguish between my Messages.resources and Messages.de.resources files (or whatever files they are)?</p> <p>I'm currently trying to resolve my message resources with the following code:</p> <pre><code>... public string Translate(string messageKey, CultureInfo cultureInfo) { ResourceManager resourceManager = new ResourceManager("My.Project.Messages", Assembly.GetExecutingAssembly()); string message = resourceManager.GetString(messageKey, cultureInfo); return message; } ... </code></pre> <p>I feel like I'm missing some fundamental points in the effort of internationalization/localization/globalization etc. with C#. I have worked on internationalized projects in Java before, but for some reason I can't quite wrap my head around it in C#.</p> <p>Also, as an aside--what is the "preferred" directory structure for resources in an internationalized project?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload