配置文件全球化
我有多个描述系统插件的配置文件。 我正在寻找一种方法来全球化配置文件中的一些标签(即 - 支持多种语言)
例如:在文件activity.xml中我想全球化一些属性:
<?xml version="1.0" encoding="UTF-8"?>
<Resource
type="Activity"
id="123456.ConcatenateStrings"
version="1.0.0"
group="String Manipulation"
shortName="$$Concatenate_Strings"
description="$$Concatenates_Strings_Description"
assembly="VTDBasicActivities.dll"
className="ConcatenateStringsActivity"
visible="true">
</Resource>
I希望从不同的配置文件(可能是 resx)中获取某些属性(shotName、description)的值,其中这些值可以用任何语言编写。
我需要一种方法来标记某些属性的值,以便 xml 解析器知道从配置文件中获取它们的值(在我的示例中,我在这些值之前写了“$$”)
执行此操作的最佳方法是什么? 我正在用 C# 解析 xml 文件,
谢谢!
I have multiple configuration files describing Addins to my system.
I'm looking for a way to globalize some of the tags in the configuration file (i.e - support multiple languages)
for example: in the file activity.xml i want to globalize some of the attributes:
<?xml version="1.0" encoding="UTF-8"?>
<Resource
type="Activity"
id="123456.ConcatenateStrings"
version="1.0.0"
group="String Manipulation"
shortName="$Concatenate_Strings"
description="$Concatenates_Strings_Description"
assembly="VTDBasicActivities.dll"
className="ConcatenateStringsActivity"
visible="true">
</Resource>
I want the values of some of the attributes (shotName, description) to be taken from a different configuration file (resx probably) where the values could be written in any language.
I need a way to mark the values of some attributes, so that the xml parser would know to take their value from a configuration file (in my example I wrote "$$" before those values)
what is the best way for doing this?
I'm parsing the xml file with C#
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用资源文件代替
在配置中提供实际字符串,而是提供资源密钥并将字符串保留在具有不同翻译的资源文件中。这就是资源文件的用途,您也应该使用它们。 不要重新发明轮子。
资源如何运作(简而言之)?
Resources.resx
具有所有非本地化语言默认的默认翻译。然后为您想要支持的每种语言创建单独的资源文件:因此,当西班牙人访问您的应用程序时,他们将获得默认语言,斯洛文尼亚人将获得他们自己的翻译,爱尔兰和德国用户也将...所有这些文件将具有相同的资源密钥,但提供不同的翻译。您需要做的就是在配置文件中使用这些键。单一 - 语言中立。
Use Resource files instead
Instead of providing the actual string in configuration, rather provide Resource key and keep strings in resource files with different translations. That's what Resource files are for and you should use them as well. Don't reinvent the wheel.
How Resources work (in a nutshell)?
Have
Resources.resx
with default translation that all non localised languages will default to. Then create separate resource files for each language you'd like to support:So when a spanish person would access your application they will get default language, Slovenians will get their own translation, so will Irish and German users... All of these files will have the same resource keys but provide different translations. All you need to do is to use these keys inside of your configuration file. Single one - language neutral.
您需要使用资源文件。请参阅此处:http://ondotnet.com/pub/a /dotnet/2002/09/30/manager.html
You need to use resource files. See here: http://ondotnet.com/pub/a/dotnet/2002/09/30/manager.html
来自我与 IT/支持朋友的对话。通常配置文件以英文保存。它不是最友好的解决方案,但是配置映射是硬编码到程序本身中的指定信息。 (是键,而不是值)
您还必须记住:使用配置文件的人员通常是知情用户,因此修改文件的用户群较小。
From my conversations with my IT/Support friend. Typically configuration files are kept in English. Its not the most friendly solution, however the configuration mapping is specified information that is hard coded into the program its self. (The keys are, not the values)
Also you have to remember: The people who are working with the configuration file are typically informed users, so your user base that is modifying the files are smaller.