tags:

views:

1076

answers:

2

I need to detect the current locale in OS X from the command line. On Linux/Unix I can rely on LANG, but it is not always set:

http://henrik.nyh.se/2007/10/displaying-utf-8-correctly-in-leopard-terminal

I am looking for command line utilities or AppleScript code that allows me to find that information. Ideally they would work from 10.2 onwards

The closest I have found so far is

defaults read -g AppleLocale

which works on 10.3 onwards

+5  A: 

apropos yeilds the command locale

10.4 and later though

Edit:

defaults read .GlobalPreferences AppleLanguages | tr -d [:space:] | cut -c2-3

is mentioned here. I don't have access to a 10.2 system though, so I don't know if it works.

cobbal
Correct, I already ran across it but is only 10.4 and later, as you mention
Daniel Lopez
Thanks for the suggestion. It does work in 10.2, but in returns English, whereas in the 10.3 and later returns the language code
Daniel Lopez
defaults read -g AppleLocale works on 10.3 and later
Daniel Lopez
thats odd, cut should make it always 2 characters
cobbal
What I meant is that the language list in 10.2 is "English, French ..." whereas in 10.3 is "en, fr ..."
Daniel Lopez
+2  A: 
locale

or if that's not disponible

env | grep LC_
vartec
Unfortunately, no LC_ are available either by default in many installs
Daniel Lopez