C#,本地化,资源和MonoDevelop的 [英] C#, Localization, Resources, and MonoDevelop

查看:274
本文介绍了C#,本地化,资源和MonoDevelop的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索过关于这个明确的答案,但似乎无法找到一个。我可能只是缺少它计算器,以及有关的SharpDevelop和MonoDevelop的搜索讨论要么取得什么。我道歉,如果这已经被问过,但我的搜索想出了什么完全相关的

I've searched for a clear answer on this, but can't seem to find one. I may just be missing it on StackOverflow, and searching discussions regarding SharpDevelop and MonoDevelop have yielded nothing either. I apologize if this has already been asked, but my searches came up with nothing entirely relevant.

我的问题是这样的:使用MonoDevelop的(这是一些我的工作),我试图找出如何使用资源文件本地化消息以及如何正确地包括他们在该项目作为嵌入资源项目的首选环境。

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 localized messages and 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

我有几个问题。

首先,是MonoDevelop中的.resources文件和资源的Visual Studio的概念之间的差异(如果有的话)。据我了解,MonoDevelop的(和SharpDevelop的)允许您创建的.resources文件,而Visual Studio中使用的.resx文件,并将其编译成的.resources文件(二进制文件类型)通过RESGEN工具。当使用的MonoDevelop资源,我需要使用RESGEN编译我资源的开发(如Messages.resources)?当我尝试使用刚刚直的.resources文件的MonoDevelop让我通过他们的向导来创建我收到以下错误:

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:

流不是有效的资源文件。

,一旦我有一个适当生成的资源文件,我可以将其嵌入到我的项目,该项目如果我理解正确,使资源的组件的一部分。如果我有两个文件虽然Messages.resources和Messages.de.resources,MonoDevelop的(至少)为它们分配相同的ID值,当我把它们嵌入。我需要有包括在项目中我的默认定位,然后对每个支持的区域设置一个单独的项目?这个跟进,如何C#我Messages.resources和Messages.de.resources文件(或任何文件,他们是)?

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;
}
...



我觉得我缺少一些基本的在国际化/本地化/全球化等的努力,用C#分。我已经在Java中的国际化项目合作过,但由于某些原因,我不能完全用C#换我的头周围

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.

推荐答案

我不熟悉使用.NET本地化(我使用gettext),但据我所知,的.resources文件是的 二进制格式实际上嵌入到你的DLL。您可以编译 RESX(XML)文本资源的成二进制格式使用RESGEN。文本文件是更易读但只能用于字符串的资源。 XML是更冗长,但可以代表一切,二进制资源。

I'm not familiar with .NET localization (I use gettext), but as I understand it, .resources files are a binary format that's actually embedded into your dll. You can compile resx (XML) or text resources into the binary format using resgen. Text files are more readable but can only be used for string resources. XML is more verbose but can represent everything that binary resources can.

通常的事情就是你的资源存储的.resx形式的项目,MonoDevelop的自动编译它们成的.resources文件建设项目时(你必须手动编译.txt文件)。不幸的是MD没有为RESX文件的特殊编辑工具,所以你必须直接编辑XML。

The usual thing is to store your resources in .resx form in the project, and MonoDevelop will automatically compile them into .resources files when building your project (you'd have to compile .txt files manually). Unfortunately MD doesn't have special editing tools for resx files, so you'd have to edit the XML directly.

MD确实有很好的gettext的本地化工具,但这些目前不支持在Windows上。

MD does have nice localization tools for gettext, but these aren't currently supported on Windows.

这篇关于C#,本地化,资源和MonoDevelop的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆