Hi everybody, I''m Reginaldo (from Brazil), and this is my first message at fxruby-users list (actually, I''m "digging" FXRuby and its API only four days ago). My interest is to popularize desktop development with Ruby here in my region and I think FXRuby will help me very much in this task. 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, Reginaldo Francisco naldo_ds at yahoo.com.br
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>
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'' $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/646d59e4/attachment-0001.html>
I don''t think that''s what Reginaldo meant.> constant messages (texts of buttons and labels of a FXPrintDialog, for example)(I don''t know how to do it myself, just pointing out) -- Matma Rex - http://matma-rex.prv.pl/
This was an interesting question, what it looks like happens (atleast for FXPrintDialog) is use the FXTranslator object. --- C++ snippets --- /* FXPrintDialog.cpp */ FXGroupBox *dest = new FXGroupBox(contents, tr("Print Destination"), GROUPBOX_TITLE_LEFT|FRAME_RIDGE|LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0, 10,10,5,5 10,5); ---- Looking through the tr() functions appears to do this: --- /* FXWindow.cpp */ const FXchar *FXWindow::tr(const FXchar *message, const FXchar* hint) const { FXTranslator *translator = getApp()->getTranslator(); if(translator){ return translator->tr(getClassName(), message, hint); } return message; } --- Translator tr() --- /* FXTranslator.cpp */ const FXchar *FXTranslator::tr(const FXchar* context,const FXchar* message, const FXchar* hint) const { FXTRACE((200,"tr context ''%s'' message: ''%s'' hint: ''%s''.\n",context,message,hint?hint:"")); return message; } ------------------------------------ Ok, so looking through that it doesn''t seem to actually map anything... (This was fox-1.6.35 source code.) So, I''m not really sure how to do translations on const values. Someone with more experience in the Fox/FXRuby libraries might be able to guide you though. Glancing through the FXRuby source I don''t see anything additional or different being done for the FXTranslator object. but that''s just a glance.. Further investigation could yield something else. I hope this helps in some way. Thanks, -J 2010/4/28 Bartosz Dziewo?ski <matma.rex at gmail.com>> I don''t think that''s what Reginaldo meant. > > > constant messages (texts of buttons and labels of a FXPrintDialog, for > example) > > (I don''t know how to do it myself, just pointing out) > > -- > Matma Rex - http://matma-rex.prv.pl/ > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users >-- If you are not the intended recipient, you are hereby notified that any dissemination, distribution, copying or other use of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100428/95100ca0/attachment.html>
Thanks Paul and Michel, your resource string file solutions are very interesting and i''ll certain use them at some moment in my projects, but what i really want (thanks Bartosz) is to modify the content of a FXPrintDialog (e.g. I''d like to change english caption texts of buttons, labels, groups like "Print", "Pages", "Size" to portuguese expressions "Imprimir", "P?ginas", "Tamanho"). The problem is that I don''t have access to those widgets on the FXPrintDialog public interface (In the file C:\Program Files\Ruby\lib\ruby\gems\1.9.1\gems\fxruby-1.6.20-x86-mingw32\swig-interfaces\FXPrintDialog.i they seem to be private attributes) Is there any manner to do that? P.S. in my last post i was trying to mention FXTranslator, and not FXTranslation. Does anybody know something about it? Reginaldo Francisco naldo_ds at yahoo.com.br Em 28/04/2010 07:38, Bartosz Dziewo?ski escreveu:> I don''t think that''s what Reginaldo meant. > > >> constant messages (texts of buttons and labels of a FXPrintDialog, for example) >> > (I don''t know how to do it myself, just pointing out) > >
> Glancing through the FXRuby source I don''t see anything additional or > different being done for the FXTranslator object. but that''s just a > glance.. Further investigation could yield something else.It''s that Joey, I did not find anything to do that, even how to use a FXTranslator! Reginaldo Francisco naldo_ds at yahoo.com.br
After further investigation, it''s as easy as this: require ''fox16'' include Fox # Create a Translation Class class ExampleTranslator < FXTranslator # tr() is called to translate the text # c = context # m = message # h = hint def tr(c, m, h) # here you would probably do something like Paul did with a file to map stuff, but for an example I just matched on # one string. if(m == "Print Destination") # if text matches "Print Destination" translate to "Something totally different" return ("Something totally different") end # otherwise we just return the message. return (m) end end # End example Translation class. # Basic stuff.. app = FXApp.new("Test", "Test") # Set the translator for our application to be our Translator app.translator = ExampleTranslator.new(app) # More basic stuff. win = FXMainWindow.new(app, "Test App", :opts => DECOR_ALL) pd = FXPrintDialog.new(win, "Test") app.create win.show pd.show app.run -------------------------------------------- I realized after sending my email that the tr() function in FXTranslator was virtual, and intended to be overwritten by self-written algorithms. Good luck :) On Wed, Apr 28, 2010 at 10:28 AM, Reginaldo Francisco <naldo_ds at yahoo.com.br> wrote:> > Glancing through the FXRuby source I don''t see anything additional or >> different being done for the FXTranslator object. but that''s just a glance.. >> Further investigation could yield something else. >> > > It''s that Joey, I did not find anything to do that, even how to use a > FXTranslator! > > > Reginaldo Francisco > naldo_ds at yahoo.com.br > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users >-- If you are not the intended recipient, you are hereby notified that any dissemination, distribution, copying or other use of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100428/1add72ac/attachment.html>
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/20100428/f78f2d95/attachment-0001.html>
Paul, First I have a labels.yaml file looking like ## YAML --- fr: :entry: ''Marche/Arr?t'' :pages: ''Pages'' <more> en: :entry: ''GO/STOP'' :pages: ''Pages'' <more> 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 than 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. Michel 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>
Joey, your FXTranslator sample code solved completely my problem! Thank you very much, and everybody who helped me too. Reginaldo Francisco naldo_ds at yahoo.com.br Em 28/04/2010 12:43, Joey Kinsella escreveu:> After further investigation, it''s as easy as this: > > require ''fox16'' > include Fox > > # Create a Translation Class > class ExampleTranslator < FXTranslator > # tr() is called to translate the text > # c = context > # m = message > # h = hint > def tr(c, m, h) > # here you would probably do something like Paul did with a file > to map stuff, but for an example I just matched on > # one string. > if(m == "Print Destination") > # if text matches "Print Destination" translate to "Something > totally different" > return ("Something totally different") > end > > # otherwise we just return the message. > return (m) > end > end > # End example Translation class. > > # Basic stuff.. > app = FXApp.new("Test", "Test") > > # Set the translator for our application to be our Translator > app.translator = ExampleTranslator.new(app) > > # More basic stuff. > win = FXMainWindow.new(app, "Test App", :opts => DECOR_ALL) > pd = FXPrintDialog.new(win, "Test") > > app.create > win.show > pd.show > > app.run > > -------------------------------------------- > > I realized after sending my email that the tr() function in > FXTranslator was virtual, and intended to be overwritten > by self-written algorithms. > > Good luck :) > > On Wed, Apr 28, 2010 at 10:28 AM, Reginaldo Francisco > <naldo_ds at yahoo.com.br <mailto:naldo_ds at yahoo.com.br>> wrote: > > > Glancing through the FXRuby source I don''t see anything > additional or different being done for the FXTranslator > object. but that''s just a glance.. Further investigation could > yield something else. > > > It''s that Joey, I did not find anything to do that, even how to > use a FXTranslator! > > > Reginaldo Francisco > naldo_ds at yahoo.com.br <mailto:naldo_ds at yahoo.com.br> > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org <mailto:fxruby-users at rubyforge.org> > http://rubyforge.org/mailman/listinfo/fxruby-users > > > -- > If you are not the intended recipient, you are hereby notified > that any dissemination, distribution, copying or other use of > this communication is strictly prohibited. If you have > received this communication in error, please notify us > immediately. > > > > > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100501/ba4633e8/attachment-0001.html>