检测操作系统语言和提供不同的语言下拉菜单 [英] Detect OS Language & Provide Different Language Dropdown Menu

查看:42
本文介绍了检测操作系统语言和提供不同的语言下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小应用程序,用于更新Active Directory中的用户详细信息.该应用程序可以用英语正常运行.但我现在想对其进行修改,以开始将其用于法语,意大利语和&德国用户.因此,我希望能够检测OS语言,然后以这些语言提供现有的下拉选项.我可能还应该翻译选择框&输入框标签也可以使用这些语言.

I have a small application to update user's details in Active Directory. The application works fine in English. But I now want to modify it to start using it for French, Italian & German users. So I'd like to be able to detect the OS language, and then provide the existing dropdown options in those languages. I should probably also translate the select box & input box labels into those languages as well.

我认为一旦检测到操作系统,就可以将选择选项设置为变量,即,如果language = EN,则select1 = English_Option1 ... elseif language = FR,然后select1 = French_Option1等

I think once I've detected the OS, I can just set the select options as variables, i.e. if language = EN, then select1 = English_Option1... elseif language = FR, then select1 = French_Option1 etc

使用VB.NET/Visual Studio 2012(针对.NET 3.5框架的应用程序)进行OS检测的最佳方法是什么?

What is the best method for OS detection using VB.NET/Visual Studio 2012, with an app targeted to .NET 3.5 framework?

推荐答案

您可以使用 Thread.CurrentThread.CurrentCulture.Name 获取该语言的代码,例如:

You can use the Thread.CurrentThread.CurrentCulture.Nameto get the language's code, for example:

  • 法语: fr-FR
  • 德语: de-DE
  • 西班牙语: es-ES

您可能希望在应用程序首次启动时显示选择语言"表格,但是会自动突出显示操作系统的语言.

You would probably want to have a 'select language' form shown the first time the application starts up, but have it automatically highlight the OS' language.

所有语言的一种形式就足够了,但是为每种受支持的语言创建语言 class 可能是一个主意.

One form for all languages should be sufficient, but however it might be an idea to create a language class for each supported language.

大多数主要程序(通常是游戏)都使用语言包,并引用诸如 @m_Welcome 之类的单词或句子;这些变量是完全根据操作系统的语言预先设置的.

Most major programs (usually games) use language packs, and reference a word or sentence such as @m_Welcome; these variables are preset depending completely on the OS' language.

您可能想要类似的东西:

You might want something similar to this:

Private m_Start As String
Private m_helloMessage As String 'We obviously want to declare this first so it can be accessed.

Private Sub SetLanguagePack()
    Select Case (Thread.CurrentThread.CurrentCulture.Name)
        Case "fr-FR"
            m_helloMessage = "Bonjour là, accueillir." 'Hello there, welcome.
            m_Start = "Cliquez ici pour commencer." 'Click here to start.
            Return
        Case "de-DE"
            m_helloMessage = "Hallo, willkommen."
            m_Start = "Klicken Sie hier um zu starten"
            Return
    End Select
    'If the OS' language isn't supported, then default to English.
    m_helloMessage = "Hello there, welcome."
    m_Start = "Click here to start."
End Sub

请注意,您还需要使用 Imports System.Threading 导入System.Threading命名空间,以访问 Thread.CurrentThread.CurrentCulture.Name .

Note that you also need to import the System.Threading namespace with Imports System.Threading to access Thread.CurrentThread.CurrentCulture.Name.

这篇关于检测操作系统语言和提供不同的语言下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆