Regional Setting


Is it possible to get the country the Regional Setting in OS X is set to? Mac only! (may be with declares)
I have searched the Forum and Google but couldn’t find anything.

The idea is to present the user a list of Zip codes and City names depending on the country
he selected in Regional Setting.

Thanks for any ideas.

NSLocale Class Reference

Thank’s Eli,

I have checked the NSLocale Reference and also looked into MacOsLib, but to be honest, I don’t know
how to use Declares to get the Country name/code from NSLocale.

I saw an example from you getting the name of the weekday using NSLocale (Feb24)

By any chance, do you have a piece of code using Declares to get the country name and/or country code?

I use the MBS plugin for NSLocale. A simple language or local detection is this:

  • add a module to your project

  • add a constant to your

  • add all needed languages and a value to the constant
    Default => EN
    English => EN
    Germany = DE
    Default => 001
    English = > 001
    German => 049

  • add a method to your project

Sub LanguageCheck()
select case LocaleDetection

case “EN”
set ZIPArea = 402030

case “DE”
set ZIPArea = 70000

end select
End Sub

I use the MBS plugins in my application <Worldwide ZIP Code Finder>. It detects the current locale and shows all zip codes from this country.


I have found a solution to get the regional setting from the OS:
Code goes into a Module.

Constant FoundationLib “Foundation.framework” as String

#if TargetMacOS
Declare Function NSClassFromString Lib FoundationLib (ClassName As CFStringRef) As Ptr
Declare Function currentLocale Lib FoundationLib Selector “currentLocale” (NSLocale As Ptr) As Ptr

Dim locale As Ptr = currentLocale(NSClassFromString("NSLocale"))

Declare Function localeIdentifier Lib FoundationLib Selector "localeIdentifier" (locale As Ptr) As CFStringRef
return localeIdentifier(locale)

return “”

The Function returns the LocaleIdentifier in the format: language_regionl setting
en_CH (englisch language, regional setting Switzerland) or
de_FR (german language, regional setting France)