On Tue, 27 Apr 2004 10:39:02 +0900, Phil Tomson wrote: [...] > In article <887E6B64-97BA-11D8-9038-000502FDD5CC / mac.com>, Mark Hubbart > <discord / mac.com> wrote: [...] >> 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: [...] > I thought a bit more about this approach, it I think I see a flaw: If you > change the text in your program, you need to also change the text in your > translation file. The approach that I use is a tag-based system similar to this. It has flaws -- but they are flaws shared with the approach mentioned above. The program is configured like so: wiki.config.language = Ruwiki::Lang::EN Ruwiki::Config#language= is defined thus: def language=(l) #:nodoc: @language = l @message = l::Message @message.default = l::Message.default end Ruwiki::Lang::EN is a module that contains a single Hash, Message: Message = { # The encoding for the webpages. This should match the encoding # used to create these messages. :encoding => "iso-8859-1", # Backend-related messages. :no_webmaster_defined => "Error: Webmaster is unset.", :backend_unknown => "Backend %s is unknown.", :cannot_create_project => "Cannot create project %s: %s", :cannot_destroy_project => "Cannot destroy project %s: %s", :cannot_destroy_topic => "Cannot destroy %s::%s: %s", } When I want to display a message, I do: puts @config.message[:no_webmaster_defined] raise @config.message[:backend_unknown] % ["madaleine"] The latter illustrates a rather large problem with this approach, though. I believe that the only proper answer is tagged-templated translation, but this is a very heavyweight response. Most messages are NOT fixed messages, but include information from the program. printf-formats (like I use) are positional, but that won't work for all languages in all contexts. Ideally, a fast format would be available that allows me to do: :message_1 => "The <:subject> is <:object>." Then, it could be translated as (I'm going from a very rusty memory here, so please forgive me): :message_1 => "<:object> ga <:subject> desu." This is made more difficult, of course, because I believe that the choice of the marker ("wa" or "ga") in Japanese depends on the word(s) involved, even though "wa" and "ga" are semantically null in English. I find that this works quite well for me, but it does have limitations that I have yet to work around satisfactorily. -austin -- austin ziegler * austin / halostatue.ca * Toronto, ON, Canada software designer * pragmatic programmer * 2004.04.26 * 23.18.08