在英文桌面C#.NET应用程序阿拉伯语言本地化阿拉伯、英文、应用程序、桌面

2023-09-04 00:22:22 作者:笑意似烟暮

我建立一个企业C#.NET应用程序的要求是将有阿拉伯语和英语两个版本。 2选项从客户端给,要么写英文加阿拉伯文共同的标签和说明,或放置一个组合框开始有英文和阿拉伯文选择并继续进行该语言。 我要救我的时间,并希望我可以只建立一个英文版本和阿拉伯文必须是自动翻译。

I am building an enterprise C#.net application, the requirement is there will be Arabic and English version both. 2 options are given from client, either to write English plus Arabic together for labels and descriptions or to place a combo box in start having English and Arabic to select and to proceed with that language. I want to save my time and want that i could just build an English version and Arabic must be auto translated.

在此先感谢。

推荐答案

首先,你不需要选择任何东西,它会被选中,如果有人设置阿拉伯语语言环境中的他/她的操作系统。为了检测用什么语言(如果需要此信息,通常你不这样做),你只会读 System.Globalization.CultureInfo.CurrentUICulture 属性。

First of all, you do not need to select anything, it would be already selected if somebody set Arabic Locale in his/her Operating System. To detect what language is used (if you need this information, usually you don't) you would simply read System.Globalization.CultureInfo.CurrentUICulture property.

然而,在的WinForms,你可以实际使用内置的本地化支持。要做到这一点,你需要切换表格本地化属性为true。假设您已经阿拉伯语字符串提供,你需要从(默认)切换窗体的语言属性阿拉伯语 你完成你的英语布局和地点后,翻译在适当的地方。这是最简单的方法。您还需要而在阿拉伯语窗体的从右至左属性切换到是和 RightToLeftLayout 为True。 如果你这样做正确,你会看到这种形式被镜像。这是需要的情况下,不要惊慌。

However, in WinForms you could actually use built-in Localization support. To do that, you need to switch Form Localizable property to true. Assuming that you have Arabic strings provided, you would need to switch Form's Language property from (default) to Arabic after you complete you English layout and place the translations in appropriate places. That is the easiest way. You would also need to switch Form's RightToLeft property to Yes and RightToLeftLayout to True while on Arabic. If you do that properly, you would see that form is mirrored. That's desired situation, do not panic.

更糟的是,你会偶尔需要显示消息框。这里的问题是,这取决于语言类型使用的是,你实际上需要做它以不同的方式,为阿拉伯语(和其他RTL语言)要求RTLReading不断被使用:

The worse part is that you would occasionally need to display Message Boxes. The problem here is, that depending on what language type you are using, you actually would need to do it in a different way, for Arabic (and other RTL languages) require that RTLReading constant be used:

if (CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft)
{
    MessageBox.Show(text, caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
}
else
{
    MessageBox.Show(text, caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
}

这就是它的高层次...

That's it on the high level...