Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Discovering system language

Discovering system language
Thread Tools
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
Dec 11, 2004, 09:04 PM
 
I was wondering if there's an easy way to discover what the system's default language is, such as an environment variable or something. $LANG is an empty string by default on my machine, so I was hoping someone could point me in the right direction.
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Dec 12, 2004, 04:00 AM
 
In Cocoa:

Code:
[[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0];
It returns "English" for english, and the language code (e.g., "ja" or "de") for the other languages (which is strange, but there it is).
[Wevah setPostCount:[Wevah postCount] + 1];
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Dec 12, 2004, 04:01 AM
 
Also, FWIW, $LANG is "en_US" on my machine.

Edit: Nevermind; I just noticed that $LANG doesn't change when the language order is changed in System Preferences.
[Wevah setPostCount:[Wevah postCount] + 1];
     
wataru  (op)
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
Dec 12, 2004, 05:16 AM
 
I should have specified, this is for a Bash script. And echo $LANG on my system gives me a blank line, even though my system language is Japanese. That's weird.
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Dec 12, 2004, 08:57 PM
 
Oh, hah...sorry. I've gotten used to shell scripting questions appearing in the UNIX forum. You could try calling

Code:
defaults read 'Apple Global Domain' AppleLanguages
and parsing the result. Of course, if this is mean to run on a non OS X system, that won't work so well.
[Wevah setPostCount:[Wevah postCount] + 1];
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:01 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2