Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: locale Re: Re: %Maoww_english.r

From: zokie:libero:it at: 24-Aug-2002 18:20

Hello [mh983--attbi--com] 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 3.x!! 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 more 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. For example: ; 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" /default my-list [block!] /force language /local catname cat ] [ if default = TRUE [return cat: make object! my-list] cat: none if exists? %catalog/ [ either force = TRUE [catname: join %catalog/ join app-name join "-" join language .cat ] [ 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 ] ] return cat ] rdui: make-catalog "RebolDex" ;and from now on we may access to localized strings by using a mnemonical code like this: print rdui/hello-msg .... 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 purpose. 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 modified :)
> Just my two cents.
This is just my old experiment :) ; locale-english.cat [greetings: "regards" ] ; locale-italiano.cat [greetings: "saluti"] ... ui: make-catalog/force "locale" "english" print ui/greetings -- "Where did you get all those facts!?!"