[REBOL] Re: locale Re: Re: %Maoww_english.r
From: zokie:libero:it at: 24-Aug-2002 18:20
On 23-Ago-02, [mh983--attbi--com] wrote:
> for what it's worth, I think the last one is the best approach: have one
> file per language and use named constants for the different strings
yes, this is an old idea used with succes by locale.library of AmigaOS
Many months ago I started to make a Rebol Tools to implement any routines of
locale.libray, but after a little experiment I haven't more time to
complete it :(
It is based on external files, collected into a directory called %catalog/.
Each file stores messages definition and its names is obteined by joining
application ID and language ID, to localize a Rebol Script all you need is
at script startup to call:
messages: make-catalog "your applicationname"
Massages becames an object, so each catalog string definition will not
collide with global variables used in the script.
In the file user.r you must add a language definition, which may contain
than a language setup, so application will do automaticaly the best user's
preference match :)
It is possible to add for each message a minimal or/and maximal length so it
will be easy to make a self-formatting user interface or for translator to
choice the best word to unchange user interface layout.
; line to add to %user.r, languages are sorted by preference
user-prefered-languages: ["italiano" "english"]
; at script begin
make-catalog: func [
app-name [string!] "Application name"
/local catname cat
if default = TRUE [return cat: make object! my-list]
if exists? %catalog/
either force = TRUE
[catname: join %catalog/ join app-name join "-" join language
foreach language user-prefered-languages
if exists? catname: join %catalog/ join app-name join "-"
join language ".cat" [break]
if exists? catname
my-list: load catname
cat: make object! my-list
rdui: make-catalog "RebolDex"
;and from now on we may access to localized strings by using a mnemonical
code like this:
How you can see by looking make-catalog source, you may force a language
choice or may give a minimal user interface by using refinements like force
or default. They had been implemented for rapid developing or for degub
To add another "language" you need only to translate text and put it into
%catalog/app-name-"language".cat file, no one source line needs to be
> Just my two cents.
This is just my old experiment :)
[greetings: "regards" ]
ui: make-catalog/force "locale" "english"
"Where did you get all those facts!?!"