c# - 为本地化 C# 动态添加文件

标签 c# .net wpf resx

我需要帮助来本地化我的 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/

相关文章:

c# - 使用 JpegBitmapEncoder 将 WPF BitmapImage 与 Base64 相互转换,无法加载 JPG 文件

WPF DataGrid 行在展开行详细信息后不调整高度

c# - 动态添加 DataGrid 日期时间列

c# - 在 BundleConfig.cs 中找不到 BundleCollection

c# - 使用 lambda 表达式获取属性名称和类型

.net - Windows 10 上的 IExpress.exe 生成与 Windows XP 不兼容的 EXE

c# - 什么是最适合实现具有 1000 多个具体实现的接口(interface)的设计模式?

c# - 在 Windows 上使用 Mono Runtime 而不是 Microsoft 的 Monodevelop

c# - 每个单元格中具有不同 UserControl 的 WPF DataGrid

c# - HTMLAgilityPack 错误 : "Multiple node elements can' t be created.“