[fpc-pascal] SysLocale.PriLangID vs Mac OS X localization

Jonas Maebe jonas.maebe at elis.ugent.be
Mon Jun 23 11:11:08 CEST 2008


On 23 Jun 2008, at 10:41, Bent Normann Olsen wrote:

> Yup, I know, but it's a 1-1 port from Win32 to Mac,

That's really a very bad idea, unless you are only interested in  
supporting Windows users switching to a Mac (although even for them  
the application will feel weird after a while).

> and it does have a
> little Carbon feel and look, but the application applies its own  
> dynamic
> language structure based on a default language setting retrieved from
> PriLangID.


http://www.google.com/search?hl=en&q=site%3Adeveloper.apple.com+obtain+user+language 
  -> fourth link

-> http://developer.apple.com/documentation/MacOSX/Conceptual/BPInternational/Articles/ChoosingLocalizations.html#/ 
/apple_ref/doc/uid/20002397-DontLinkElementID_1 :


"There may be situations where you want to get the preferred locale ID  
or the list of languages directly from the user preferences. Mac OS X  
stores each user's list of preferred languages in that user's defaults  
database. The list of preferred languages is identified by the  
defaults key AppleLanguages and is stored in the global variable  
NSGlobalDomain. You can access that list using the NSUserDefaults  
class in Cocoa or the Core Foundation preferences functions."

-> CF preferences reading code: http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFPreferences/Tasks/UsingHighAPI.html#/ 
/apple_ref/doc/uid/20001169-TPXREF106


->
CFArrayRef langArray =  
(CFArrayRef)CFPreferencesCopyAppValue(CFSTR("AppleLanguages"),  
kCFPreferencesCurrentApplication );

Or in Pascal:

var
   longArray: CFArrayRef;
begin
    
langArray 
:=CFArrayRef(CFPreferencesCopyAppValue(CFSTR('AppleLanguages'),  
kCFPreferencesCurrentApplication))
end;

Then use CFArrayGetCount to get the number of elements in the array,  
CFArrayGetValueAtIndex to get the actual values (they are CFStrings).  
And keep in mind those are not canonical names (as mentioned in the  
last link, you may want to call  
CFLocaleCreateCanonicalLanguageIdentifierFromString() to get the  
canonical name; although you'll have to import this function manually,  
as it does not yet exist in MacOSAll)


Jonas



More information about the fpc-pascal mailing list