[futurebasic] RE: Priority language

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 2006 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Sat, 19 Aug 2006 08:34:28 -0400
Yoshiyuki asked:

>How is whether the priority language of OSX is English or Japanese examined?

Languages are listed by priority at:

Apple Menu-> System Prefereneces-> International-> Language

The first language in the list will be the default language.

You can examine this list in the Terminal with:

    defaults read -g AppleLanguages

This returns an array of language codes. The 
array elements may be on one line or on separate 
lines depending on your version of OS X. On my 
Mac (OS X 10.3.9) I get:

(en, ja, fr, de, es, it, nl, sv, no, da, fi, pt, "zh_CN", "zh_TW", ko)

You can parse the array like this:

clear local mode
local fn DefaultAppleLanguage$
dim as str255 temp, lang

open "Unix", 1, "defaults read -g AppleLanguages"
do : line input #1, temp
lang += temp
until eof (1) : close 1

lang = mid$( lang, 2, instr( 1, lang, "," ) -2 )
select case ( lang )
case "en"        : lang = "English"
case "ja"        : lang = "Japanese"
case "fr"        : lang = "French"
case "de"        : lang = "German"
case "es"        : lang = "Spanish"
case "it"        : lang = "Italian"
case "nl"        : lang = "Dutch"
case "sv"        : lang = "Svenska"
case "no"        : lang = "Norsk"
case "da"        : lang = "Dansk"
case "fi"        : lang = "Suomen kieli"
case "pt"        : lang = "Portuguese"
case """zh_CN""" : lang = "Chinese Simplified"
case """zh_TW""" : lang = "Chinese Traditional"
case "ko"        : lang = "Korean"
end select

end fn = lang

print fn DefaultAppleLanguage$

until gFBQuit

According to:


there are helper functions that are supposed to work in newer versions of OS X.

In Mac OS X v10.3:


In Mac OS X v10.4:


However, under OS X 10.3.9 my machine does not 
appear to have access to the first. At any rate, 
below is the code I used to test the concept if 
anyone would like to try to see if it is fixable.

I have had very little FB coding time this year, so don't laugh too hard.



include "Tlbx CFString.incl"

toolbox fn CFPreferencesCopyAppValue(CFStringRef key,¬
        CFStringRef applicationID) = CFPropertyListRef

toolbox fn CFArrayGetCount(CFArrayRef theArray) = CFIndex
toolbox fn CFArrayGetValueAtIndex(CFArrayRef theArray,¬
                            CFIndex idx) = CFStringRef
toolbox fn CFArrayGetTypeID = CFTypeID
toolbox fn CFLocaleCreateCanonicalLocaleIdentifierFromString¬
( CFAllocatorRef alloc, CFStringRef localeIdentifier ) = CFStringRef

local fn DefaultAppleLanguage$
dim as CFPropertyListRef	localizationList
dim as CFStringRef		      languageName
dim as CFStringRef		      localeName
dim as CFStringRef	       kCFPreferencesCurrentApplication
dim as str255             defaultLanguage
dim as boolean            languageFound

localizationList = fn CFPreferencesCopyAppValue(¬
fn CFSTR( "AppleLanguages" ), kCFPreferencesCurrentApplication )
long if (localizationList != 0)
  long if ( fn CFGetTypeID( localizationList ) ==¬
fn CFArrayGetTypeID and fn CFArrayGetCount( localizationList ) > 0 )
languageName = fn CFArrayGetValueAtIndex( localizationList, 0 )
long if ( languageName != 0 and¬
fn CFGetTypeID( languageName ) ==¬
  fn CFStringGetTypeID() )
localeName =¬
fn CFLocaleCreateCanonicalLocaleIdentifierFromString(¬
_kCFAllocatorDefault, languageName )
long if ( localeName != 0 )
languageFound =¬
  fn CFStringGetPascalString( localeName,¬
@defaultLanguage, 256, _kCFStringEncodingASCII )
CFRelease( localeName )
CFRelease( localizationList)
long if ( languageFound == 0 )
// Default to en_US if not found
// defaultLanguage = "en_US"
end if
end if
end if
end if
end if

end fn = defaultLanguage

window 1

print fn DefaultAppleLanguage$

until gFBQuit