繁体   English   中英

在Winforms应用程序中支持多种语言

[英]Supporting multiple languages in a Winforms application

我差不多完成了我的C#应用​​程序; 剩下要做的就是实现多语言支持。

我已经创建了资源文件,其中包含屏幕上显示的所有文本的几种语言的字符串。

我的英文资源文件示例:

Name                    |  Value                       | Comment
------------------------------------------------------------------------------
lblName                 |   Name:                      |  Name EN

我的荷兰资源文件示例:

Name                    |  Value                       | Comment
------------------------------------------------------------------------------
lblName                 |  Naam:                       | Name NL

如何将字段Value绑定到我的LabellblName )的Text属性?

我正在使用.NET Framework 3.5。

我知道很久以前这个问题已被问过,但由于这里没有答案,我建议:

要在C#中访问资源文件,您可以使用ResourceManager 首先根据当前语言创建资源管理器。 你有两种选择。 您可以使用switch或if语句(如果语言由菜单确定)或使用本地化来使用计算机的当前文化。 最后,使用这两种方法,您可以调用GetString()方法,提供我认为在您的情况下为lblName的键。

注意:在下面的示例中,我使用第一种从菜单中检索语言的方法。

string selectedLanguage = comboBoxLang.Text; // Comes from a menu option
string resourceFile = string.Empty;

/***/
Logic to retrieve the proper resourceFile depending on the selectedLanguage.
/***/

ResourceManager rm = new ResourceManager(resourceFile, Assembly.GetExecutingAssembly());

// Set your label text.
lblName.Text = rm.GetString("lblName");

尝试这个:

<asp:Label runat="server" Text="<%$ Resources:DutchLanguage, Value %>"></asp:Label>

将不同语言的值放在一个数据库表中。

让用户选择语言。

根据语言的选择从数据库中获取有关特定语言的数据。

然后用标签文本绑定它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM