The Locale Library
;===================================================================
;
; DTLocaleLib
;
; $VER = 1.0 (17.02.1996 19:24)
;
; by Peter 'dreamy' Traskalik
; dream technologies inc.
;
; succ = DTLocaleOpen{name.s} false -> using built in strings
; txt$ = DTLocaleGetStr{nr,builtin} gives the string
; DTLocaleClose{} do not forget !
;
; requires the to be resident
;
;===================================================================
DEFTYPE.Catalog DTLcat
DEFTYPE.Library DTLlib
Dim DTLtags.TagItem(4)
DTLtags(0)\ti_Tag = #OC_Language
DTLtags(0)\ti_Data = 0 ; wanted language
DTLtags(1)\ti_Tag = #OC_Version
DTLtags(1)\ti_Data = 0 ; required version
DTLtags(2)\ti_Tag = #OC_BuiltInLanguage
DTLtags(2)\ti_Data = 0 ; built in english
DTLtags(3)\ti_Tag = #OC_BuiltInCodeSet
DTLtags(3)\ti_Data = 0 ; always 0
DTLtags(4)\ti_Tag=$00000000 ;TAG_DONE
DTLtags(4)\ti_Data=0
;-------------------------------------------------------------------
Function.b DTLocaleOpen{f$}
SHARED *DTLcat,*DTLlib,DTLtags()
localelibname.s="locale.library"
*DTLlib=OpenLibrary_(&localelibname,38)
succ=False
If *DTLlib<>0
*DTLcat=OpenCatalogA_(0,&f$,&DTLtags(0))
If *DTLcat<>0 Then succ=True
EndIf
Function Return succ
End Function
;-------------------------------------------------------------------
Function.s DTLocaleGetStr{nr,def.s}
SHARED *DTLcat,*DTLlib
DEFTYPE.s tx
If *DTLcat<>0 AND *DTLlib<>0
*tx=GetCatalogStr_(*DTLcat,nr,def.s)
Function Return Peek$(*tx)
Else
Function Return def.s
EndIf
End Function
;-------------------------------------------------------------------
Statement DTLocaleClose{}
SHARED *DTLcat,*DTLlib
If *DTLcat<>0 Then CloseCatalog_(*DTLcat)
If *DTLlib<>0 Then CloseLibrary_(*DTLlib)
End Statement
;===================================================================
;
; DTLocaleLib example
;
; we open the sys/installer.catalog
; try also another catalogs with various id nr...
;
FindScreen 0
Window 0,10,10,300,230,$10000+$400+14,"DTLocaleLib test",0,0
;
; DTLocaleOpen{t$} tries to open the catalog
; the locale.library tries to find the catalog
; for the preffered language (locale-preference)
;
If DTLocaleOpen{"sys/installer.catalog"}
yID.l = ;
; DTLocaleOpen{t$}=true --> catalog sucessfully opened
;
NPrint "using catalog"
NPrint ""
Else
;
; DTLocaleOpen{t$} fails if the locale.library V38 couldn't
; be opened or there is no such catalog in your preffered
; language set in the locale-preference
; Build-in Strings will be used instead.
;
NPrint "couldn't open catalog"
NPrint "or locale.library !"
NPrint "using built-in strings instead !"
NPrint ""
EndIf
;
; read the Localestrings id 0 - 100
;
For a=0 To 100
;
; DTLocaleGetStr{nr,tx$} returns the locale-string
; if DTLocaleOpen{t$} failed or there is no catalog,
; or there is no string it returns
;
;
t$=DTLocaleGetStr{a,"built in string"}
Format "000"
NPrint Str$(a)+" : "+t$
VWait 3
WPrintScroll
Next a
;
; *** NOTE : Do not forget to close a catalog when exiting !
;
; DTLocaleClose{} closes the catalog
; it makes no difference if or why DTLocaleOpen{t$} failed
;
DTLocaleClose{}
Repeat
ev.l=WaitEvent ; Wait for IDCMP_CLOSEWINDOW
Until ev=$200
CloseWindow 0
End