[fxruby-users] i18n messages

Paul Carvalho tester.paul at gmail.com
Wed Apr 28 00:29:51 EDT 2010


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'
$KCODE = 'UTF8'
module Kernel
def u( str )
String.new str.gsub(/U\+([0-9a-fA-F]{4,4})/u){["#$1".hex ].pack('U*')}
end
end

# 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)

application.create()
main.show(PLACEMENT_SCREEN)
application.run()

# end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100428/e7233a74/attachment.html>


More information about the fxruby-users mailing list