[fxruby-users] i18n messages

Michel Demazure michel at demazure.com
Thu Apr 29 02:53:43 EDT 2010



First I have a labels.yaml file looking like


## YAML 



  :entry: 'Marche/Arrêt'

  :pages: 'Pages'



  :entry: 'GO/STOP'

  :pages: 'Pages'



I load it with


labels = nil

File.open(this_file,“r:utf-8”){ |f| labels = YAML.load(f) }


I fix the language


@strings = labels[“fr”]


Then I use for instance FXLabel(@strings[:entry] ….)


Actually, the chosen language also comes from a user config file (another YAML file)


@strings = labels[config[“language”]]


Two comments on YAML.


First, you always can choose between Strings and Symbols for keys and values. As you see, I mixed Symbols for labels and Strings for the language key. It looks strange. The reason is that *I* write the label file and Symbols are neater and more rubyesque, but *the user* has to write his config file and is seems simpler to have him write


language: en




language: :en


or even


:language: :en


The second remark is a small trick. I always forget the precise syntax of a YAML file. So I open irb, type for instance

{ a => { :b => c}}.to_yaml and look.


By the way, you may have to ‘require ‘yaml’’.


A last word. I have been using FXRuby for more than two years. One thing to remember : when after a change, suddenly nothing appears on the screen when you start your app, it means you forgot to ‘create’ something (font.create, canvas.create, image.create …).


I hope this helps. 



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 20:58
À : fxruby-users at rubyforge.org
Objet : Re: [fxruby-users] i18n messages


Hello Michel, I don't want to bother with the unicode table codes.  I just followed the example from the unicode.rb script (from Ruby 1.8) and since it worked I moved on.  I'm still working on getting the main guts of the app working, so i haven't had a chance to go back to the strings and find a better way of doing it.


I have taken a break from working on my app for a few weeks now.  I am interested in your yaml solution. Could you please send me some simple examples - like the "hello world" one I sent in my previous post?


That would be great.  I'd like to avoid using the unicode character codes in my strings file if I can.


Thanks.  Cheers!  Paul.


(P.S., Sorry Reginaldo that I didn't understand your problem correctly.)


On 28 April 2010 03:13, Michel Demazure wrote:

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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100429/4dc643fd/attachment.html>

More information about the fxruby-users mailing list