From: Mark Hubbart Date: 2004-04-27T04:47:27+09:00 Subject: Re: Approaches to localization? On Apr 26, 2004, at 11:09 AM, Phil Tomson wrote: > I'm developing a GUI app using Ruby and FLTK. One of the requirements > that's come up lately is that this app should be 'localizable'. I'm > trying > to figure out approaches for doing this as I design the app. > > The approach I'm thinking of is to have some seperate file, maybe in > XML, > that would contain all of the text which is used for things like button > labels, output messages, etc. Then to support different languages all > the > customer would have to do is include a different language specific > file. > > These files might look something like: > > [...] > > So, if they wanted to make a Japanese version of the app, they would > replace each of the strings above with their Japanese counterparts. > While it seems a bit heavy, I'm thinking an XML approach would be good > for > a couple of reasons: > 1) this localization will probably be taking place long after I'm gone > (this is a contract job) and XML is widely known and understood. > 2) it's easy to extract data from it using REXML > > > Does this seem like a reasonable approach? > > Has anyone used alternate approaches? You might look at Apple/NextStep's approach to localization. (probably others use it too) Basically, there's a file that maps english text to the translated text. Then, anywhere in the program where a particular english string is used, it checks for a translation to the appropriate language. So to do this in ruby, you might have a pig-latin translation file, using yaml: --- Enter text here: Enterway exttay erehay Type "yes" to continue: Ypetay "yes" otay ontinuecay Then write a small class: class Localization def initialize(filename) # load yaml data from file to a hash # stored in @translations end def [](text) @translations[text] || text end end localization files are automatically generated for english, that include all the string literals from the source code. For the english files, they just map each string to itself. But then you can easily hand the file over for translation, and add the new one in. HTH, --Mark