Multilingual apps (was: Re: Beginners global variable pb)

Rob Cozens rcozens at pon.net
Fri Feb 20 17:45:14 EST 2004


>My own preferred option is to go for a simplified manual approach 
>where every string that needs to be changed according to language is 
>set in one particular handler ('setUpParameters'), and I simply read 
>the Welsh (or whatever) text file into a text editor and paste each 
>line directly into the Transcript code, all in one concentrated 
>place in the app. This is crude but in fact works rather well.

Graham, et al:

My approach is to load the entire text file into a library field when 
changing languages, and to load that text field into a library local 
variable when the library is put in use.

Each one-line message in the file is referenced as a constant, eg:

	constant sdbFileMenu=1
	constant sdbEditMenu=2
	constant sdbIOError=3
	constant sdbQuitMenuItem=4
	constant sdbOKTranslated=113

Scripts retrieve the messages via a function call: sdbMessage, along 
the lines of

	function sdbMessage(messageLineNumber)
		local sdbMessages
		return line messageLineNumber of sdbMessages
	end sdbMessage

So my handlers look something like:

on preOpenStack
   set the name of button 1 of group "Stack Menubar" to sdbMessage(sdbFileMenu)
   set the text of button 1 of group "Stack Menubar" to 
sdbMessage(sdbQuitMenuItem)
end preOpenStack

on menuPick thePick
   put sdbMessage(sdbQuitMenuItem) into quitMe
   switch thePick
     case quitMe
       quit
       break
   end switch
end menuPick

on displayError errorDetail
   beep
   answer error sdbMessage(sdbIOError)&&":"&&errorDetail with 
sdbMessage(sdbOKTranslated)
   exit to top
end display error

So handler text is never changed and the message is resolved AT 
RUNTIME either when a new message file is loaded into the library or 
at startup when necessary (eg: for standalones).

With the exception of the fact that each constant must be declared in 
every script that references it, I find this approach effective & 
straightforward.

AND, as I alluded to above, since no script changes need occur, your 
application can be distributed in one version supporting any 
(single-byte character) language without modification....including 
languages not supported in the original distribution.  Viola! your 
application can be translated by any user with a text editor.

There are examples of this in virtually all components of Serendipity 
Library <http://www.oenolog.net/ftp/serendipity_downloader.htm>.
-- 

Rob Cozens
CCW, Serendipity Software Company
http://www.oenolog.net/who.htm

"And I, which was two fooles, do so grow three;
Who are a little wise, the best fooles bee."

from "The Triple Foole" by John Donne (1572-1631)


More information about the use-livecode mailing list