在.NET中的文本文件资源本地化文本文件、资源、NET

2023-09-03 15:12:54 作者:失眠

本地化/全球化是pretty的易于使用RESX文件的Visual Studio。我只是添加一个资源文件,如 MyTextSnippets.resx ,添加键/值对,并为每一种语言的副本,我想支持像 MyTextSnippets.de.resx MyTextSnippets.fr.resx 等。

Localization/Globalization is pretty easy in Visual Studio using RESX files. I just add a resource file, like MyTextSnippets.resx, add key/value pairs, and create copies for every language I'd like to support like MyTextSnippets.de.resx, MyTextSnippets.fr.resx etc.

现在想想较长的文本,其中字符串资源编辑器网格没有很好地工作。没问题,只要选择添加资源|添加新的文本文件,从设计师,只要你想,你可以编辑尽可能多的文本文件。例:我想补充 MyTemplates.resx ,并为此RESX我添加了一个名为 SomeEmailTemplate.txt 。做工精细,到目前为止,但是当一个创建的resx文件的副本,比如 MyTemplates.de.resx ,然后打开 SomeEmailTemplate.txt 从那里,它会打开的总是相同的文件的。如果你看一下细节,文本文件将不被嵌入在RESX容器,但它是一个全球性的文件夹中创建资源和RESX文件只是抱着一个参考,一切以相同的文件。

Now think of longer texts, where the String resource editor grid doesn't work very well. No problem, just choose "Add Resource | Add New Text File" from the designer, and you can edit as many text files as you want. Example: I add MyTemplates.resx, and to this RESX I add a file called SomeEmailTemplate.txt. Works fine so far, however when a create a copy of the resx file, say MyTemplates.de.resx, and open SomeEmailTemplate.txt from there, it will open always the same file. If you look at the details, the text file will not be embedded in the resx container, but it is created in a global folder "Resources", and the resx files just hold a reference, all to the same file.

我无法弄清楚如何定位它。你知道吗?

I can't figure out how to localize it. Any idea?

当然,我可以嵌入每种语言添加一个文本文件,并在运行时,枚举可用文本文件,并试图找到当前线程的UI文化的最佳匹配。然而,这感觉不对,因为所有的魔法可用出来的字符串和设计师的属性框。

Of course, I could embed add a text file for every language, and at runtime, enumerate the available text files and try to find the best match for UI culture of the current thread. However this doesn't feel right, as all that magic is available out of the box for strings and designer properties.

推荐答案

你希望每个本地化语言创建一个文件夹,把该文件夹中的相应TXT文件和引用。

Create a folder for each localized language you want, place the respective txt file in the folder and reference that.

了解更多关于全球化/本地化的最佳做法这里。

Read about globalization/localization best practices here.