我需要帮助来本地化我的 Wpf .net 3.5 应用程序。我打算只将 exe 文件提供给我的 cient,他将使用该文件为他的用户创 build 置。我的客户想自己添加文件进行本地化。
本地化的一般方法是为每种语言创建 .resx 文件并在 CurrentUICulture 中设置语言。但由于他不能使用resgen工具来创建资源文件,我想知道最好的方法让他添加txt、excel、xml格式的文件来进行本地化。
PS:通过流读取并分配 key 是唯一的方法吗?
最佳答案
如果您不能使用 resgen 工具,一个带有键值对的简单文本文件将是最简单的方法。如果你只使用简单的字符串,你应该使用这个。按照默认约定命名它们,名称中的语言用于识别正确的文件以加载并自己编写一个自定义 resourceManager
,在启动时或按需将这些文件加载到字典中以访问它们。
编辑:
我会详细介绍一下......
I would create a resource manager that has static accessors for all used resourcefiles where just the fallback resource is static typed. I guess your language is defined at startup so just load the fallback and the defined language files each into a dictionary and both dictionaries in a static typed for this resource type. Use a GetString("name", Culture) to load a string. You can do the lookups for the culture in the resource dictionary and if one key is missing do a fallback to the static one.
Edit II:
You can ZIP the text-files using one of the .Net libraries out there to prevent anyone from open and change the content. For additional security you can also add a password to the zip. So you end up with smaller files plus the ability to modify the files with any ZIP program. For sure you should also change the file extension.
希望对你有帮助
关于c# - 为本地化 C# 动态添加文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6135826/