Code: Select all
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Define Buffer$, buflen, bytesread, LC
LC = #LOCALE_SLANGUAGE
;LC = #LOCAL_SLANGUAGE #LOCALE_SINTLSYMBOL ;#LOCALE_SNATIVECTRYNAME ;#LOCALE_SNATIVELANGNAME ;#LOCALE_SISO639LANGNAME
buflen = GetLocaleInfo_(#LOCALE_USER_DEFAULT, LC, @Buffer$, 0) ;MS recommends using GetLocaleInfoEx_() if only supporting Vista and later
Buffer$ = Space(buflen)
bytesread = GetLocaleInfo_(#LOCALE_USER_DEFAULT, LC, @Buffer$, buflen)
If bytesread = 0
Debug "Failed" ;call GetLastError()
Else
Debug "Result=" + Buffer$
EndIf
CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux ;(on #PB_OS_MacOS it also works but tends to only return default of "C")
#LC_CTYPE = 0
#LC_NUMERIC = 1
#LC_TIME = 2
#LC_COLLATE = 3
#LC_MONETARY = 4
#LC_MESSAGES = 5
#LC_ALL = 6
#LC_PAPER = 7
#LC_NAME = 8
#LC_ADDRESS = 9
#LC_TELEPHONE = 10
#LC_MEASUREMENT = 11
#LC_IDENTIFICATION = 12
lcaddr.i = setlocale_(#LC_CTYPE, #Null) ;If the last paramter is Null the function works as GETlocale
If lcaddr
Debug "Result=" + PeekS(lcaddr,-1,#PB_Ascii)
Else
Debug "Failed"
EndIf
CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS ;thanks to mk-soft. Tends to return the full locale, as opposed to just default of "C"
;NSString *language = [[NSLocale currentLocale] localeIdentifier];
;NSLog(@"Language: %@", language)
CurrentLocale = CocoaMessage(0, 0, "NSLocale currentLocale")
LocaleIdentifer = CocoaMessage(0, CurrentLocale, "localeIdentifier")
CocoaMessage(@Language, LocaleIdentifer, "UTF8String")
Debug "Result=" + PeekS(Language, -1, #PB_UTF8)
CompilerEndIf
;// and another way, for Linux and Mac:
;Debug "LANG environment var = " + GetEnvironmentVariable("LANG")
Note also that with both Linux and Mac the default locale is simply "C", so it'd probably be wise to add some fallback support for that.