Results 1 to 4 of 4

Thread: How to retrieve OS Language

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2015
    Posts
    515

    How to retrieve OS Language

    This code will detect the OS Language of your windows

    Just call Debug.Print DetectOSLanguage()

    Code:
    Private Declare Function GetUserDefaultLangID Lib "kernel32" () As Integer
    
    Public Function DetectOSLanguage() As String
       ' #VBIDEUtils#***********************************************************
       ' * Author           :
       ' * Web Site         :
       ' * E-Mail           :
       ' * Date             : 07/26/2005
       ' * Time             : 12:29
       ' * Module Name      : Lib_Module
       ' * Module Filename  : Lib.bas
       ' * Procedure Name   : DetectOSLanguage
       ' * Purpose          :
       ' * Parameters       :
       ' * Purpose          :
       ' **********************************************************************
       ' * Comments         :
       ' *
       ' *
       ' * Example          :
       ' *
       ' * See Also         :
       ' *
       ' * History          :
       ' *
       ' *
       ' **********************************************************************
    
       Select Case GetUserDefaultLangID()
          Case &H0
             DetectOSLanguage = "Language_Neutral"
          Case &H400
             DetectOSLanguage = "Default Language"
          Case &H401, &H801, &HC01, &H1001, &H1401, &H1801, &H1C01, &H2001, &H2401, &H2801, &H2C01, &H3001, &H3401, &H3801, &H3C01, 16385
             DetectOSLanguage = "Araabic"
          Case &H402
             DetectOSLanguage = "Bulgarian"
          Case &H403
             DetectOSLanguage = "Catalan"
          Case &H404, &H804, &HC04, 4100
             DetectOSLanguage = "Chinese"
          Case &H405
             DetectOSLanguage = "Czech"
          Case &H406
             DetectOSLanguage = "Danish"
          Case &H407, &H807, &HC07, &H1007, 5127
             DetectOSLanguage = "German"
          Case &H408
             DetectOSLanguage = "Greek"
          Case &H409, &H809, &HC09, &H1009, &H1409, &H1809, &H1C09, &H2009, &H2409, &H2809, 11273
             DetectOSLanguage = "English"
          Case &H40A, &H80A, &HC0A, &H100A, &H140A, &H180A, &H1C0A, &H200A, &H240A, &H280A, &H2C0A, &H300A, &H340A, &H380A, &H3C0A, &H400A, &H440A, &H480A, &H4C0A, 2049
             DetectOSLanguage = "Spanish"
          Case &H40B
             DetectOSLanguage = "Finnish"
          Case &H40C, &H80C, &HC0C, &H100C, 5132
             DetectOSLanguage = "French"
          Case &H40D
             DetectOSLanguage = "Hebrew"
          Case &H40E
             DetectOSLanguage = "Hungarian"
          Case &H40F
             DetectOSLanguage = "Icelandic"
          Case &H410, 2064
             DetectOSLanguage = "Italian"
          Case &H411
             DetectOSLanguage = "Japanese"
          Case &H412, 2066
             DetectOSLanguage = "Korean"
          Case &H413, 2067
             DetectOSLanguage = "Dutch"
          Case &H414, 2068
             DetectOSLanguage = "Norwegian"
          Case &H415
             DetectOSLanguage = "Polish"
          Case &H416, 2070
             DetectOSLanguage = "Portuguese"
          Case &H418
             DetectOSLanguage = "Romanian"
          Case &H419
             DetectOSLanguage = "Russian"
          Case &H41A
             DetectOSLanguage = "Croatian"
          Case &H81A, 3098
             DetectOSLanguage = "Serbian"
          Case &H41B
             DetectOSLanguage = "Slovak"
          Case &H41C
             DetectOSLanguage = "Albanian"
          Case &H41D, 2077
             DetectOSLanguage = "Swedish"
          Case &H41E
             DetectOSLanguage = "Thai"
          Case &H41F
             DetectOSLanguage = "Turkish"
          Case &H421
             DetectOSLanguage = "Indonesian"
          Case &H422
             DetectOSLanguage = "Ukrainian"
          Case &H423
             DetectOSLanguage = "Belarusian"
          Case &H424
             DetectOSLanguage = "Slovenian"
          Case &H425
             DetectOSLanguage = "Estonian"
          Case &H426
             DetectOSLanguage = "Latvian"
          Case &H427
             DetectOSLanguage = "Lithuanian"
          Case &H429
             DetectOSLanguage = "Farsi"
          Case &H42A
             DetectOSLanguage = "Vietnamese"
          Case &H42D
             DetectOSLanguage = "Basque"
          Case &H436
             DetectOSLanguage = "Afrikaans"
          Case &H438
             DetectOSLanguage = "Faeroese"
       End Select
    End Function

  2. #2
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    671

    Re: How to retrieve OS Language

    That is wrong.
    GetUserDefaultLangID returns a language set to use with controls not supporting the unicode. It is not OS installation language and not a display language.

    See the correct sample here.

    My test system:
    Language in dialogues: 1033 EN English
    Language of OS inslallation: 1033 EN English
    Language for non-Unicode programs: 1041 ja-JP Japanese
    Also, for name dereferencing you can use GetLocaleInfo
    Code:
    Private Declare Function GetLocaleInfo Lib "kernel32.dll" Alias "GetLocaleInfoW" (ByVal lcid As Long, ByVal LCTYPE As Long, ByVal lpLCData As Long, ByVal cchData As Long) As Long
    
    Public Const LOCALE_SENGLANGUAGE = &H1001&
    
    Private Function GetLangNameFullByCultureCode(lcid As Long) As String
        Dim buf As String
        Dim lr  As Long
        buf = String$(1000, vbNullChar)
        lr = GetLocaleInfo(lcid, LOCALE_SENGLANGUAGE, StrPtr(buf), ByVal 1000&)
        If lr Then
            GetLangNameFullByCultureCode = Left$(buf, lr - 1)
        End If
    End Function
    Malware analyst, VirusNet developer, HiJackThis Fork author || my CodeBank works

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2015
    Posts
    515

    Re: How to retrieve OS Language

    You are right.
    For my needs the code I posted is good.
    But for other part in the world replacing,
    Private Declare Function GetUserDefaultLangID Lib "kernel32" () As Integer

    By
    Private Declare Function GetUserDefaultUILanguage Lib "kernel32.dll" () As Long

    Should give you the right result

  4. #4
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    671

    Re: How to retrieve OS Language

    That is a common practice to change language for non-unicode controls only when other two language settings remain untouched.
    Such a way a program with ANSI controls designed in e.g. for Japan / German e.t.c. languages able to display most characters correctly by mapping local-specific characters to extended ASCII space.
    Malware analyst, VirusNet developer, HiJackThis Fork author || my CodeBank works

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width