国际化问题 - 始终显示英文 DLL 数据
我有一个要求,我的 UI 应该以除英语之外的 5 种不同语言显示。
我创建了两个 DLL
Component.dll
Component.resources.dll
Component.resources.dll
只包含 类
public class PResources
{
private static System.Resources.ResourceManager resourceMgr = new System.Resources.ResourceManager(typeof(PEditResources));
/// <summary>
/// Get NLS String method string method
/// </summary>
/// <param name="identifier"></param>
/// <returns></returns>
public static string GetNLSString(string identifier)
{
return resourceMgr.GetString(identifier, Thread.CurrentThread.CurrentUICulture);
}
/// <summary>
/// Returns the NLS Resource Mgr.
/// </summary>
/// <returns></returns>
public static System.Resources.ResourceManager GetNLSResourceMgr()
{
return resourceMgr;
}
}
UI 和Component.dll 中的
label1.text = PResources.GetNLSString("IDS_LABEL1");
来显示标签文本我使用以下英文它工作正常... 但是,当语言设置更改为法语或任何其他语言时,显示的字符串仍然是英语文本。
注意: Component.Resources.dll
字符串已翻译为所有语言。
当我调试时...我发现GetNLSString
函数的Thread.Current.UICulture
是法语...但是resourceMgr
对象仍然是指向英文.dll 路径,并且Thread.Current.Culture
也是英文!
有什么办法解决这个问题吗?我错过了什么吗?
I have a requirement where my UI should be shown in 5 different languages apart from English.
I have created two DLLs
Component.dll
Component.resources.dll
Component.resources.dll
contains nothing but all the strings that are shown in the UI and a class
public class PResources
{
private static System.Resources.ResourceManager resourceMgr = new System.Resources.ResourceManager(typeof(PEditResources));
/// <summary>
/// Get NLS String method string method
/// </summary>
/// <param name="identifier"></param>
/// <returns></returns>
public static string GetNLSString(string identifier)
{
return resourceMgr.GetString(identifier, Thread.CurrentThread.CurrentUICulture);
}
/// <summary>
/// Returns the NLS Resource Mgr.
/// </summary>
/// <returns></returns>
public static System.Resources.ResourceManager GetNLSResourceMgr()
{
return resourceMgr;
}
}
In Component.dll
to display the label text I use the following
label1.text = PResources.GetNLSString("IDS_LABEL1");
In English it works fine...
But when the language settings is changed to French or any other, the string displayed is still the English text.
Note: The Component.Resources.dll
strings are translated in all languages.
When I debugged... I found that the GetNLSString
function the Thread.Current.UICulture
is French ... but the resourceMgr
object is still pointing to the English .dll path and also the Thread.Current.Culture
is English!
Is there any solution to this ? have I missed anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于每种文化,您应该为您想要支持的每种文化创建一个文件夹(在主程序所在的文件夹中)(id = 两个字母的 iso 代码 + 可选的两个字母区域)。
在此文件夹中,放置 *.resources.dll,其中仅包含目标区域性的字符串/常量。
如果您在同一项目中创建 example.resx 文件(针对默认区域性)和 example.fr.resx 文件(针对法语),Visual Studio 会自动为您执行此操作。
For every culture, you should create a folder (in the folder where the main program is) for every culture you want to support (id = two letter iso code + optional two letter region).
Inside this folder, you place the *.resources.dll, with only the strings/constants for the target culture.
Visual Studio does this automatically for you if you create an example.resx file (for the default culture) and an example.fr.resx file for French, inside the same project.