[fxruby-users] i18n messages

Michel Demazure michel at demazure.com
Wed Apr 28 03:13:00 EDT 2010

Reginaldo, I do the same thing Paul does, slightly differently. I have a yaml file with the different languages describing a two-levels hash :


language => {name => string}


Then I read the file, build @strings = hash[language], and then use @strings[name].


Paul, I always work in ruby 1.9 and UTF8 (code file and data files), and my files contain accented letters of all kinds. Why do you need bother with U+… ?


Michel  Demazure

michel at demazure.com




De : fxruby-users-bounces at rubyforge.org [mailto:fxruby-users-bounces at rubyforge.org] De la part de Paul Carvalho
Envoyé : mercredi 28 avril 2010 06:30
À : fxruby-users at rubyforge.org
Objet : Re: [fxruby-users] i18n messages


On 26 April 2010 21:50, Reginaldo Francisco wrote:

So, starting it, how could I translate FXRuby constant messages (texts of buttons and labels of a FXPrintDialog, for example) from english to any other language (portuguese, spanish, french, italian, german)? Should I use a FXTranslation instance? How can I use it?

Thanks in advance,



Hello Reginaldo, I faced a similar problem when designing an app a few months ago.  I solved it using 2 tricks.


The first was to take ALL the strings out of the app script/code and put them into a separate strings file.  Then from the main app I call the strings file and all of the elements use the variables instead.  This way I can change the strings and labels to be whatever I want (in whatever language I want) and I don't have to update the app - just change the strings file.


The second problem was how to print special characters.  I don't know what FXTranslation instance is, so I didn't use that.  In the FXRuby examples folder I found a script called "unicode.rb".  On my windows box, the path is: C:\ruby\lib\ruby\gems\1.8\gems\fxruby-1.6.12-mswin32\examples


I copied the module from unicode.rb into my app and modified the strings files to include a 'u' at the start of the lines with unicode characters.  There might be other ways to do this, but I'm okay with this solution for now.  The strings aren't so easy to read with the "U+0000" for every accented character, but it worked so I moved on.


I've included some sample scripts below.  Try them to see if it works for what you want to do.


Hope this helps.  Let me know if you find a different way to do this.


Cheers.  Paul.


------- File 1: strings_PT_BR.rb -------

$app_title = u"OlU+00E1"

$button_label = u"&OlU+00E1 mundo!"


$another_label = "This string has no accented characters and so it doesn't have a 'u' before the quotation marks."


# end of file


------- File 2: hello_i18n.rb -------

require 'fox16'

include Fox


# Accented Unicode characters need special handling to display correctly in the UI:

require 'jcode'


module Kernel

            def u( str )

                        String.new str.gsub(/U\+([0-9a-fA-F]{4,4})/u){["#$1".hex ].pack('U*')}




# load the strings:

require "strings_PT_BR"


application = FXApp.new($app_title, "FoxTest")

main = FXMainWindow.new(application, $app_title, nil, nil, DECOR_ALL)


FXButton.new(main, $button_label, nil, application, FXApp::ID_QUIT)






# end of file


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100428/646d59e4/attachment-0001.html>

More information about the fxruby-users mailing list