Localization of Text File resources in .NET

回眸只為那壹抹淺笑 提交于 2019-12-06 08:22:32

问题


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.

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?

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.


回答1:


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.



来源:https://stackoverflow.com/questions/3307466/localization-of-text-file-resources-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!