Reputation: 45
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.
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
What is the best method for OS detection using VB.NET/Visual Studio 2012, with an app targeted to .NET 3.5 framework?
Upvotes: 1
Views: 1573
Reputation: 4561
You can use the Thread.CurrentThread.CurrentCulture.Name
to 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.
One form for all languages should be sufficient, but however it might be an idea to create a language class for each supported language.
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
Note that you also need to import the System.Threading namespace with Imports System.Threading
to access Thread.CurrentThread.CurrentCulture.Name
.
Upvotes: 2