[futurebasic] Re: [FB] Priority language

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

From: Alain Pastor <apastor@...>
Date: Thu, 17 Aug 2006 13:16:53 +0200
Robert Purves a crit :
> 
> Yoshiyuki Hasegawa wrote:
> 
>>>> Hi All,
>>>> How is whether the priority language of OSX is English or Japanese 
>>>> examined?
>>>
>>> General reading:
>>> <http://developer.apple.com/documentation/MacOSX/Conceptual/BPInternational/index.html> 
>>>
>>>
>>> What is your aim? What problem are you trying to solve?
>>>
>>> Robert P.
>>
>> I'm sorry "Examine" is not suitable.
>>
>> The code in which a top priority language is obtained because of the 
>> program is
>> hoped for.
>>
>> It is software of the bilingual that I thinks.
>> The resource is decided and which resource is read in two built-in 
>> priority language for English
>> and for Japanese is decided.
>> It is "vers" resource that becomes an object.
>>
>> I will stop making it to the bilingual to About and Apple menu, etc.
>> The software of Apple such as TextEdit is Maltilingual.
> 
> If you want to detect the primary locale or language at run time, I can 
> suggest only what the code might look like. Perhaps someone can supply 
> the missing details.
> 

Here is a snippet of code that might help for that purpose (I believe it 
is also on the FB4R3 CD )

/*
      Alain Pastor November 2005
*/
'~Should be hidden in a header

#define CFLocaleRef as Ptr

begin globals
dim as Ptr  gCoreFoundationBundle
dim as Ptr  gCFLocaleCopyCurrent, gCFLocaleGetValue
end globals

local fn FBXInitCoreFoundationFramework
'~'1
long if ( gFBSystemVersionHex < 0x1000 )
shutdown "CoreFoundation.framework requires MacOS X"
end if

gCoreFoundationBundle = fn CreateBundleForFramework( 
"CoreFoundation.framework" )
long if ( gCoreFoundationBundle == 0 )
shutdown "CoreFoundation.framework not found"
end if
//  Mach-O function pointers
gCFLocaleCopyCurrent = fn GetMachFunctionFromBundle( 
gCoreFoundationBundle, "CFLocaleCopyCurrent")
gCFLocaleGetValue    = fn GetMachFunctionFromBundle( 
gCoreFoundationBundle, "CFLocaleGetValue")
end fn

register on

local fn CFLocaleCopyCurrent
beginassem
  lwz    r12,^gCFLocaleCopyCurrent
  mtspr  ctr,r12
  mr     r31,r2
  bctrl ; CFLocaleRef in r3
  mr     r2,r31
endassem
end fn


local fn CFLocaleGetValue( locale as CFLocaleRef, key as CFStringRef )
beginassem
  lwz    r12,^gCFLocaleGetValue
  mr     r3,^locale
  mr     r4,^key
  mtspr  ctr,r12
  mr     r31,r2
  bctrl ; CFTypeRef in r3
  mr     r2,r31
endassem
end fn

fn FBXInitCoreFoundationFramework

// Locale Keys
_kCFLocaleIdentifier$           = "locale:id"
_kCFLocaleLanguageCode$         = "locale:language code"
_kCFLocaleCountryCode$          = "locale:country code"
_kCFLocaleScriptCode$           = "locale:script code"
_kCFLocaleVariantCode$          = "locale:variant code"
_kCFLocaleExemplarCharacterSet$ = "locale:exemplar characters"
_kCFLocaleCalendarIdentifier$   = "calendar"
_kCFLocaleCalendar$             = "locale:calendarref"
_kCFLocaleCollationIdentifier$  = "collation"
_kCFLocaleUsesMetricSystem$     = "locale:uses metric"
_kCFLocaleMeasurementSystem$    = "locale:measurement system"
_kCFLocaleDecimalSeparator$     = "locale:decimal separator"
_kCFLocaleGroupingSeparator$    = "locale:grouping separator"
_kCFLocaleCurrencySymbol$       = "locale:currency symbol"
_kCFLocaleCurrencyCode$         = "currency"
// Values for kCFLocaleCalendarIdentifier
_kCFGregorianCalendar$    = "gregorian"
_kCFBuddhistCalendar$     = "buddhist"
_kCFChineseCalendar$      = "chinese"
_kCFHebrewCalendar$       = "hebrew"
_kCFIslamicCalendar$      = "islamic"
_kCFIslamicCivilCalendar$ = "islamic-civil"
_kCFJapaneseCalendar$     = "japanese"



'~Prog starts here

Clear Local Mode
Local Fn GetLocaleValue$( keyStr As Str255 )
'~'9
dim as CFStringRef key
dim as CFLocaleRef localeRef
dim as CFTypeRef   typeRef
dim as str255      symbol

key = fn CFStringCreateWithPascalString( 0, keyStr, 
_kCFStringEncodingASCII )
long if key
localeRef = fn CFLocaleCopyCurrent
long if localeRef
typeRef = fn CFLocaleGetValue( localeRef, key )
long if typeRef
long if fn CFStringGetPascalString( fn CFLocaleGetValue( localeRef, key ), 
                                                                 @symbol, 
                                                          sizeof(symbol), 
                                                 _kCFStringEncodingASCII 
) = _false
symbol = "???"
end if
end if
end if
end if
if key       then CFRelease( key )
if localeRef then CFRelease( localeRef )

end fn = symbol

// main program
print "Locale Identifier: "; fn GetLocaleValue$( _kCFLocaleIdentifier$ )
print "Locale Language Code: "; fn GetLocaleValue$( 
_kCFLocaleLanguageCode$ )
print "Locale Country Code: "; fn GetLocaleValue$( _kCFLocaleCountryCode$ )
print "Locale Script Code: "; fn GetLocaleValue$( _kCFLocaleScriptCode$ )
print "Locale Variant Code: "; fn GetLocaleValue$( _kCFLocaleVariantCode$ )
print "Locale Calendar Identifier: "; fn GetLocaleValue$( 
_kCFLocaleCalendarIdentifier$ )
print "Locale Collation Identifier: "; fn GetLocaleValue$( 
_kCFLocaleCollationIdentifier$ )
print "Locale Measurement System: "; fn GetLocaleValue$( 
_kCFLocaleMeasurementSystem$ )
print "Locale Decimal Separator: "; fn GetLocaleValue$( 
_kCFLocaleDecimalSeparator$ )
print "Locale Grouping Separator: "; fn GetLocaleValue$( 
_kCFLocaleGroupingSeparator$ )
print "Locale Currency Symbol: "; fn GetLocaleValue$( 
_kCFLocaleCurrencySymbol$ )
print "Locale Currency Code: "; fn GetLocaleValue$( 
_kCFLocaleCurrencyCode$ )

// the three statements below produce a crash
//print "Locale Exemplar Character Set: "; fn GetLocaleValue$( 
_kCFLocaleExemplarCharacterSet$ )
//print "Locale Calendar: "; fn GetLocaleValue$( _kCFLocaleCalendar$ )
//print "Locale Uses Metric System: "; fn GetLocaleValue$( 
_kCFLocaleUsesMetricSystem$ )

do
handleevents
until 0

Alain
> '-----------------------
> local fn IsPrimaryLocaleJapanese
>  dim as Boolean  isJapanese
> 
>  DearMacSystemPleaseGetLocaleInfo( ... ) // no such API
>  long if ( userLocaleInfoSaysJapaneseIsPreferredToEnglish ) // no such 
> variable
>   isJapanese = _zTrue
>  xelse
>   isJapanese = _false
>  end if
> 
> end fn = isJapanese
> 
> 
> 
> long if ( fn IsPrimaryLocaleJapanese )
>  fn DoJapaneseTasks
> xelse
>  fn DoEnglishTasks
> end if
> '-----------------------
> 
> 
> Alternatively, consider localizing your program at compile time by 
> providing two versions:
> 
> '-----------------------
> _compilingJapaneseVersionOfMyProgram = 0 // 0 or 1
> 
> #if _compilingJapaneseVersionOfMyProgram
> fn DoJapaneseTasks
> #else
> fn DoEnglishTasks
> #endif
> '-----------------------
> 
> Robert P.
> 
> -- 
> To unsubscribe, send ANY message to: futurebasic-unsubscribe@...
> 
> 
>