[MonoDevelop] How Do I...? Localize Messages via Resources and Embedding them Using MonoDevelop
swquinn
swquinn at gmail.com
Mon Jul 4 12:17:10 EDT 2011
I've searched for a clear answer on this, but can't seem to find one; my
quest has taken me through these discussions, StackOverflow.com, and many
other places. It may be that I'm just not searching or the proper terms,
regardless my searches have yielded nothing. I apologize if this has already
been asked, but my searches came up with nothing entirely relevant.
*My problem is this*: 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 localizing messages, as well as how to properly include
them in the project as an embedded resource.
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.
*Messages.resources*
Hello.World = Hello World
Goodbye.Cruel.World = Goodbye, Cruel World
*Messages.de.resources*
Hello.World = Hallo Welt
Goodbye.Cruel.World = Auf Wiedersehen, grausame Welt
I'm having a couple of issues.
*First*, 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 resourses (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:
/"Stream is not a valid resource file."/
*Second*, 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)?
I'm currently trying to resolve my message resources with the following
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;
}
...
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#.
Also, as an aside--what is the "preferred" directory structure for resources
in an internationalized project?
Thanks for any help that anyone can give, I've cross-posted this from
StackOverflow.com
(http://stackoverflow.com/questions/6567964/c-localization-resources-and-monodevelop)
in hopes that I might get an answer from one source or the other.
--
View this message in context: http://mono.1490590.n4.nabble.com/How-Do-I-Localize-Messages-via-Resources-and-Embedding-them-Using-MonoDevelop-tp3643990p3643990.html
Sent from the Mono - MonoDevelop IDE mailing list archive at Nabble.com.
More information about the Monodevelop-list
mailing list