Sascha Ebach
2005-Apr-03 15:12 UTC
[ANN] New Manual: Using Gettext To Translate Your Rails Application
Hi, I have just published a new manual which I have been working on last week. It is called "Using Gettext To Translate Your Rails Application" and it is supposed to show you exactly, well, that. http://manuals.rubyonrails.com/read/book/16 As this is my first stab at doing this with Rails I would greatly appreaciate any comments. Maybe you spot an error, an ill formed sentence or you have an idea to make this appraoch even better. Just let me know and we can try to make this guide even better. Now, people have been talking that Rails is going to have its own integrated way of doing translation and localization / internationalization in the future which "might" make this approach an "alternative" by the time we will see the new functionality. Nevertheless, this approach works today and tries to leverage as many existant tools as possible. So, if you need translation right now, like I do, this might just be something you might want to look into. Have fun reading it. Sascha Ebach
Dane Jensen
2005-Apr-04 01:44 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your RailsApplication
> I have just published a new manual which I have been working on last > week. It is called "Using Gettext To Translate Your Rails Application" > and it is supposed to show you exactly, well, that. > > http://manuals.rubyonrails.com/read/book/16I can not thank you enough for this excellent guide! You just removed what may be the last barrier to ditching Zope in favor of Rails for my employer! Thanks! -Dane
Sascha Ebach
2005-Apr-04 01:52 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your RailsApplication
Dane Jensen wrote:>>I have just published a new manual which I have been working on last >>week. It is called "Using Gettext To Translate Your Rails Application" >>and it is supposed to show you exactly, well, that. >> >>http://manuals.rubyonrails.com/read/book/16 > > > I can not thank you enough for this excellent guide! You just removed > what may be the last barrier to ditching Zope in favor of Rails for my > employer!Thank you, I am glad it is of so much use to you, so all the time invested was not for nothing. Sascha
Tobias Luetke
2005-Apr-04 02:18 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your RailsApplication
Thanks a lot for this. I''m sure some day in the future I''ll be enormously thankful for having read this :) UTF-8 it is On Apr 3, 2005 9:52 PM, Sascha Ebach <se-eFwX6J65rk9VioaHkBSlcw02NpfuEekPhC4ANOJQIlc@public.gmane.org> wrote:> Dane Jensen wrote: > >>I have just published a new manual which I have been working on last > >>week. It is called "Using Gettext To Translate Your Rails Application" > >>and it is supposed to show you exactly, well, that. > >> > >>http://manuals.rubyonrails.com/read/book/16 > > > > > > I can not thank you enough for this excellent guide! You just removed > > what may be the last barrier to ditching Zope in favor of Rails for my > > employer! > > Thank you, > > I am glad it is of so much use to you, so all the time invested was not > for nothing. > > Sascha > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Tobi http://www.snowdevil.ca - Snowboards that don''t suck http://www.hieraki.org - Open source book authoring http://blog.leetsoft.com - Technical weblog
Josef Pospisil
2005-Apr-04 07:07 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Hi, thanks alot for this informative article. I always forget DRY. So why make another lib or so, where there is ol'' good way to do things. I''ll still need some code for czech specific stuff, but the main problem with messages is out :-). Now I only need how to break Mac OSX to use utf-8 in terminal with vim. Trying for hour now, and still don''t have luck. -- Pepe On 3.4.2005, at 17:12, Sascha Ebach wrote:> Hi, > > I have just published a new manual which I have been working on last > week. It is called "Using Gettext To Translate Your Rails Application" > and it is supposed to show you exactly, well, that. > > http://manuals.rubyonrails.com/read/book/16 > > As this is my first stab at doing this with Rails I would greatly > appreaciate any comments. Maybe you spot an error, an ill formed > sentence or you have an idea to make this appraoch even better. Just > let me know and we can try to make this guide even better. > > Now, people have been talking that Rails is going to have its own > integrated way of doing translation and localization / > internationalization in the future which "might" make this approach an > "alternative" by the time we will see the new functionality. > Nevertheless, this approach works today and tries to leverage as many > existant tools as possible. So, if you need translation right now, > like I do, this might just be something you might want to look into. > > Have fun reading it. > > Sascha Ebach > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Tomas Jogin
2005-Apr-04 08:05 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Thank you so much, this is really appreciated. Just what I needed. /Tomas On Apr 3, 2005 5:12 PM, Sascha Ebach <se-eFwX6J65rk9VioaHkBSlcw02NpfuEekPhC4ANOJQIlc@public.gmane.org> wrote:> Hi, > > I have just published a new manual which I have been working on last > week. It is called "Using Gettext To Translate Your Rails Application" > and it is supposed to show you exactly, well, that. > > http://manuals.rubyonrails.com/read/book/16 > > As this is my first stab at doing this with Rails I would greatly > appreaciate any comments. Maybe you spot an error, an ill formed > sentence or you have an idea to make this appraoch even better. Just let > me know and we can try to make this guide even better. > > Now, people have been talking that Rails is going to have its own > integrated way of doing translation and localization / > internationalization in the future which "might" make this approach an > "alternative" by the time we will see the new functionality. > Nevertheless, this approach works today and tries to leverage as many > existant tools as possible. So, if you need translation right now, like > I do, this might just be something you might want to look into. > > Have fun reading it. > > Sascha Ebach > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Pelle Braendgaard
2005-Apr-04 09:24 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Absolutely fantastic work. This was exactly what I have been looking for. On Apr 3, 2005 5:12 PM, Sascha Ebach <se-eFwX6J65rk9VioaHkBSlcw02NpfuEekPhC4ANOJQIlc@public.gmane.org> wrote:> Hi, > > I have just published a new manual which I have been working on last > week. It is called "Using Gettext To Translate Your Rails Application" > and it is supposed to show you exactly, well, that. > > http://manuals.rubyonrails.com/read/book/16 > > As this is my first stab at doing this with Rails I would greatly > appreaciate any comments. Maybe you spot an error, an ill formed > sentence or you have an idea to make this appraoch even better. Just let > me know and we can try to make this guide even better. > > Now, people have been talking that Rails is going to have its own > integrated way of doing translation and localization / > internationalization in the future which "might" make this approach an > "alternative" by the time we will see the new functionality. > Nevertheless, this approach works today and tries to leverage as many > existant tools as possible. So, if you need translation right now, like > I do, this might just be something you might want to look into. > > Have fun reading it. > > Sascha Ebach > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- http://talk.org + Geek blog http://SoapBX.com + Get on the box and shout
Julian ''Julik'' Tarkhanov
2005-Apr-04 14:40 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
I don''t know how it works with Vim, but on my Powerbook the terminals are automatically UTF-ed like so: in my ~/.inputrc set convert-meta Off set input-meta On set output-meta On in my ~/.profile LANG="ru_RU.UTF-8" export LANG On 4-apr-05, at 9:07, Josef Pospisil wrote:> Hi, > > thanks alot for this informative article. I always forget DRY. So why > make another lib or so, where there is ol'' good way to do things. I''ll > still need some code for czech specific stuff, but the main problem > with messages is out :-). Now I only need how to break Mac OSX to use > utf-8 in terminal with vim. Trying for hour now, and still don''t have > luck.-- Julian "Julik" Tarkhanov
Zach Thompson
2005-Apr-04 17:40 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
On Apr 4, 2005, at 12:07 AM, Josef Pospisil wrote:> Hi, > > thanks alot for this informative article. I always forget DRY. So why > make another lib or so, where there is ol'' good way to do things. I''ll > still need some code for czech specific stuff, but the main problem > with messages is out :-). Now I only need how to break Mac OSX to use > utf-8 in terminal with vim. Trying for hour now, and still don''t have > luck.I found this info on encoding with vim: http://vim.sourceforge.net/tips/tip.php?tip_id=246 Then I compiling vim 6.3 with: ./configure --enable-rubyinterp --enable-multibyte make sudo make install Then put this code in my .vimrc: if has("multi_byte") set encoding=utf-8 setglobal fileencoding=utf-8 set bomb set termencoding=utf-8 set fileencodings=ucs-bom,iso-8859-15,iso-8859-3,utf-8 else echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte" endif Now /usr/local/bin/vim seems to be showing multibyte characters (instead of "?") in Terminal. Hopefully this technique will work for you, or at least get you a little closer... Zach
Josef Pospisil
2005-Apr-05 20:49 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Yes but in vim < 7 it''s imposible. And 7 is alpha :-). It didn''t even work with recompiling as Zach said. ---- Pepe On 4.4.2005, at 16:40, Julian ''Julik'' Tarkhanov wrote:> I don''t know how it works with Vim, but on my Powerbook the terminals > are automatically UTF-ed like so: > > in my ~/.inputrc > > set convert-meta Off > set input-meta On > set output-meta On > > in my ~/.profile > > LANG="ru_RU.UTF-8" > export LANG > > On 4-apr-05, at 9:07, Josef Pospisil wrote: > >> Hi, >> >> thanks alot for this informative article. I always forget DRY. So why >> make another lib or so, where there is ol'' good way to do things. >> I''ll still need some code for czech specific stuff, but the main >> problem with messages is out :-). Now I only need how to break Mac >> OSX to use utf-8 in terminal with vim. Trying for hour now, and still >> don''t have luck. > > -- > Julian "Julik" Tarkhanov > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Jonas Montonen
2005-Apr-06 06:26 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Sascha Ebach wrote:> Hi, > > I have just published a new manual which I have been working on last > week. It is called "Using Gettext To Translate Your Rails Application" > and it is supposed to show you exactly, well, that. > > http://manuals.rubyonrails.com/read/book/16 > > As this is my first stab at doing this with Rails I would greatly > appreaciate any comments. Maybe you spot an error, an ill formed > sentence or you have an idea to make this appraoch even better. Just > let me know and we can try to make this guide even better. > > Now, people have been talking that Rails is going to have its own > integrated way of doing translation and localization / > internationalization in the future which "might" make this approach an > "alternative" by the time we will see the new functionality. > Nevertheless, this approach works today and tries to leverage as many > existant tools as possible. So, if you need translation right now, > like I do, this might just be something you might want to look into. > > Have fun reading it. > > Sascha Ebach > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >Excellent work Sascha!! I have hade some problems getting the whole thing to work on my Windows XP machine. Installed all software needed and created the folders etc... But when i run the "ruby script\localize" it get stuck on the second file, that happends to be by application.rb controller. Outout: D:\Binaries\RailAppz\T2MRails>ruby script\localize Processing app/controllers/account_controller.rb Processing app/controllers/application.rb The CPU usage goes high (75-90%), I even left it over night with no progress. Anyone else experienced this problem? Regards JoNtE
Erik Terpstra
2005-Apr-06 09:10 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
> But when i run the "ruby script\localize" it get stuck on the second > file, that happends to be by application.rb controller. > Outout: > D:\Binaries\RailAppz\T2MRails>ruby script\localize > Processing app/controllers/account_controller.rb > Processing app/controllers/application.rb > > The CPU usage goes high (75-90%), I even left it over night with no > progress. > Anyone else experienced this problem?Yes, a lot of the files in the archive at the end of the article are MS-DOS files (or some other horrible format). Try to fix the files (or retype them) and it will work fine. Kind regards, Erik Terpstra.
Sascha Ebach
2005-Apr-06 10:39 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Jonas Montonen wrote:> I have hade some problems getting the whole thing to work on my Windows > XP machine. > Installed all software needed and created the folders etc... > > But when i run the "ruby script\localize" it get stuck on the second > file, that happends to be by application.rb controller. > Outout: > D:\Binaries\RailAppz\T2MRails>ruby script\localize > Processing app/controllers/account_controller.rb > Processing app/controllers/application.rb > > The CPU usage goes high (75-90%), I even left it over night with no > progress. > Anyone else experienced this problem?For some reason I had the same problem. What fixed it for me was that I opened the file that "hung" the system in gvim and saved it as utf-8 with unix line endings. On the next run they were properly processed. Sascha
Sascha Ebach
2005-Apr-06 10:54 UTC
Re: Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Erik Terpstra wrote:>> But when i run the "ruby script\localize" it get stuck on the second >> file, that happends to be by application.rb controller. >> Outout: >> D:\Binaries\RailAppz\T2MRails>ruby script\localize >> Processing app/controllers/account_controller.rb >> Processing app/controllers/application.rb >> >> The CPU usage goes high (75-90%), I even left it over night with no >> progress. >> Anyone else experienced this problem? > > > Yes, a lot of the files in the archive at the end of the article are > MS-DOS files (or some other horrible format). Try to fix the files (or > retype them) and it will work fine.I will look into that and fix it. Thanks for pointing it out. I guess that happens because I always switch working environments between Windows and Linux. Thank you
Julian ''Julik'' Tarkhanov
2005-Apr-06 12:13 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Do your other programs work with UTF in the terminal? (ls, mkdir etc..) If the do then the problem is in vim itself. Besides, I got no idea how to enable UTF in Apple''s X11 (if Vim is an X app) - it seems to me that it was spooged from the beginning beyound any recovery. On 5-apr-05, at 22:49, Josef Pospisil wrote:> Yes but in vim < 7 it''s imposible. And 7 is alpha :-). > > It didn''t even work with recompiling as Zach said. > > ------Julian "Julik" Tarkhanov
Josef Pospíšil
2005-Apr-06 12:46 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Everything except vim. I can list files with utf, and it''s only that half of accented letters are good, half are realy weird. But I found, I''m not only one in this position here and only solution seems to be using 7 alpha, which on the other side works great so :-). But poEdit on mac os x anyone? I compiled everything but after starting application it shows to me only window that I must fill email and name for catalog header, but window is "untouchable" like there is another one, which is hidden or something. Not showstopper so ... -- Ing. Josef Pospisil On 6.4.2005, at 14:13, Julian ''Julik'' Tarkhanov wrote:> Do your other programs work with UTF in the terminal? (ls, mkdir etc..) > If the do then the problem is in vim itself. > > Besides, I got no idea how to enable UTF in Apple''s X11 (if Vim is an > X app) - it seems to me that it was spooged from the beginning beyound > any recovery. > > On 5-apr-05, at 22:49, Josef Pospisil wrote: > >> Yes but in vim < 7 it''s imposible. And 7 is alpha :-). >> >> It didn''t even work with recompiling as Zach said. >> >> ------ > Julian "Julik" Tarkhanov > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Michael Campbell
2005-Apr-06 12:57 UTC
Re: Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
On Apr 6, 2005 6:54 AM, Sascha Ebach <se-eFwX6J65rk9VioaHkBSlcw02NpfuEekPhC4ANOJQIlc@public.gmane.org> wrote:> Erik Terpstra wrote: > >> But when i run the "ruby script\localize" it get stuck on the second > >> file, that happends to be by application.rb controller. > >> Outout: > >> D:\Binaries\RailAppz\T2MRails>ruby script\localize > >> Processing app/controllers/account_controller.rb > >> Processing app/controllers/application.rb > >> > >> The CPU usage goes high (75-90%), I even left it over night with no > >> progress. > >> Anyone else experienced this problem? > > > > > > Yes, a lot of the files in the archive at the end of the article are > > MS-DOS files (or some other horrible format). Try to fix the files (or > > retype them) and it will work fine. > > I will look into that and fix it. Thanks for pointing it out. I guess > that happens because I always switch working environments between > Windows and Linux.That may fix a symptom, but is not the problem something with file I/O and DOS line-endings? (Or is it the ^Z at the end?) What''s actually /causing/ the hang?
Sascha Ebach
2005-Apr-06 13:01 UTC
Re: Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Michael Campbell wrote:> On Apr 6, 2005 6:54 AM, Sascha Ebach <se-eFwX6J65rk9VioaHkBSlcw02NpfuEekPhC4ANOJQIlc@public.gmane.org> wrote: > >>Erik Terpstra wrote: >> >>>>But when i run the "ruby script\localize" it get stuck on the second >>>>file, that happends to be by application.rb controller. >>>>Outout: >>>> D:\Binaries\RailAppz\T2MRails>ruby script\localize >>>> Processing app/controllers/account_controller.rb >>>> Processing app/controllers/application.rb >>>> >>>>The CPU usage goes high (75-90%), I even left it over night with no >>>>progress. >>>>Anyone else experienced this problem? >>> >>> >>>Yes, a lot of the files in the archive at the end of the article are >>>MS-DOS files (or some other horrible format). Try to fix the files (or >>>retype them) and it will work fine. >> >>I will look into that and fix it. Thanks for pointing it out. I guess >>that happens because I always switch working environments between >>Windows and Linux. > > > > That may fix a symptom, but is not the problem something with file I/O > and DOS line-endings? (Or is it the ^Z at the end?) > > What''s actually /causing/ the hang?I haven''t investigated further. The hangs must have come from the rails generator because they only happened before I resaved them. I had a hang on a file with 2 lines. I guess someone could investigate by creating a new rails directory and running the script in it. I will do it eventually, but I am a little time pressed right now. Sascha
Mischa Molhoek
2005-Apr-06 13:26 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Erik Terpstra wrote:>> But when i run the "ruby script\localize" it get stuck on the second >> file, that happends to be by application.rb controller. >> Outout: >> D:\Binaries\RailAppz\T2MRails>ruby script\localize >> Processing app/controllers/account_controller.rb >> Processing app/controllers/application.rb >> >> The CPU usage goes high (75-90%), I even left it over night with no >> progress. >> Anyone else experienced this problem? > > > Yes, a lot of the files in the archive at the end of the article are > MS-DOS files (or some other horrible format). Try to fix the files (or > retype them) and it will work fine. > > Kind regards, > > Erik Terpstra.Another problem occurs when running script/localize: it seems that in line 18 : ''RGettext.new.start files, potfile'' , "RGettext.new.start" starts in the background, which causes the rest of the script to fail, because there is not filled potfile yet. i assume it does work under windows, because threading is working different there....:) any suggestions on how to make "RGettext.new.start" finish beefore proceeding? tanx in advance, Mischa Molhoek.
Erik Terpstra
2005-Apr-06 14:21 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Mischa Molhoek wrote:> Another problem occurs when running script/localize: > > it seems that in line 18 : ''RGettext.new.start files, potfile'' , > "RGettext.new.start" starts in the background, which causes the rest of > the script to fail, because there is not filled potfile yet. > > i assume it does work under windows, because threading is working > different there....:) > > any suggestions on how to make "RGettext.new.start" finish beefore > proceeding?It is not a threading problem, the IO instance called ''@out'' is opened, but never closed. So it is only closed when the Ruby process ''./script/localize'' has finished. As a consequence the po files aren''t merged correctly. You have to fix the file: script/rgettext.rb Add this line: @out.close just above the ''end'' statement of ''def start(files=ARGV, output = nil)'' (line: 73) Erik Terpstra.
Sascha Ebach
2005-Apr-06 14:55 UTC
Re: Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Erik Terpstra wrote:> Mischa Molhoek wrote: > >> Another problem occurs when running script/localize: >> >> it seems that in line 18 : ''RGettext.new.start files, potfile'' , >> "RGettext.new.start" starts in the background, which causes the rest of >> the script to fail, because there is not filled potfile yet. >> >> i assume it does work under windows, because threading is working >> different there....:) >> >> any suggestions on how to make "RGettext.new.start" finish beefore >> proceeding? > > > It is not a threading problem, the IO instance called ''@out'' is opened, > but never closed. So it is only closed when the Ruby process > ''./script/localize'' has finished. As a consequence the po files aren''t > merged correctly. > > You have to fix the file: script/rgettext.rb > > Add this line: > > @out.close > > just above the ''end'' statement of ''def start(files=ARGV, output = nil)'' > (line: 73)Ahh, thank you, I applied the patch and uploaded the new archive http://digitale-wertschoepfung.de/artikel/gettext/using-gettext-with-rails.tgz Sascha
Erik Terpstra
2005-Apr-06 15:12 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Sascha Ebach wrote:> Ahh, thank you, I applied the patch and uploaded the new archiveAnd thank you for providing localization support in Rails :-)> > http://digitale-wertschoepfung.de/artikel/gettext/using-gettext-with-rails.tgz > > > Sascha
Raphael Bauduin
2005-Apr-06 15:34 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
On Apr 3, 2005 5:12 PM, Sascha Ebach <se-eFwX6J65rk9VioaHkBSlcw02NpfuEekPhC4ANOJQIlc@public.gmane.org> wrote:> Hi, > > I have just published a new manual which I have been working on last > week. It is called "Using Gettext To Translate Your Rails Application" > and it is supposed to show you exactly, well, that. > > http://manuals.rubyonrails.com/read/book/16Thanks, very interesting. I have an internationalised site for which I have a dedicated solution which has some benefits: all data is stored in a db and translations can be managed via a web interface (so I can tell a translator "go to that url and you have the tool", and there''s no exchange of translation files, everything is immediately on the server). Do you know if something similar is possible with gettext? Raph
Sascha Ebach
2005-Apr-06 16:09 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
> I have an internationalised site for which I have a dedicated solution > which has some benefits: > all data is stored in a db and translations can be managed via a web > interface (so I can tell a translator "go to that url and you have the > tool", and there''s no exchange of translation files, everything is > immediately on the server). > > Do you know if something similar is possible with gettext?Gettext is a file-based solution, so I would say no. You could certainly built something that wraps around Gettext. Also, as it is, the server has to be restarted for new translations to show up. I guess you could hack around this. A solution like you are talking about is being developed, but it will still take some time before we see a finished version. The author is not planning to use Gettext in it, so the approach I introduced will be an "alternative" sometime in the future. He will probably use some YAML based file for holding the strings. It all depends on how integrated and comfortable it will be to use this solution when doing updates and merges. The project is in its planning stages so I am inclined to say no more about it ;) Maybe you can find out more on the channel. Ask Ulysses ;) Sascha
Raphael Bauduin
2005-Apr-06 18:40 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
On Apr 6, 2005 6:09 PM, Sascha Ebach <se-eFwX6J65rk9VioaHkBSlcw02NpfuEekPhC4ANOJQIlc@public.gmane.org> wrote:> > I have an internationalised site for which I have a dedicated solution > > which has some benefits: > > all data is stored in a db and translations can be managed via a web > > interface (so I can tell a translator "go to that url and you have the > > tool", and there''s no exchange of translation files, everything is > > immediately on the server). > > > > Do you know if something similar is possible with gettext? > > Gettext is a file-based solution, so I would say no. You could certainly > built something that wraps around Gettext. Also, as it is, the server > has to be restarted for new translations to show up. I guess you could > hack around this. > > A solution like you are talking about is being developed, but it will > still take some time before we see a finished version. The author is not > planning to use Gettext in it, so the approach I introduced will be an > "alternative" sometime in the future. He will probably use some YAML > based file for holding the strings. > > It all depends on how integrated and comfortable it will be to use this > solution when doing updates and merges. The project is in its planning > stages so I am inclined to say no more about it ;) > > Maybe you can find out more on the channel. Ask Ulysses ;)ok. I''ll certainly have to develop a simple solution myself to fit my needs (db bakend, web interface to translate). I''ll be happy to share it and will communicate about it on this ML when it eventually materializes in some weeks time. thanks for the precisions about gettext. Raph> > Sascha > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Luben Manolov
2005-Apr-07 13:16 UTC
Re: Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Hi Sascha, Sascha Ebach wrote:>> It is not a threading problem, the IO instance called ''@out'' is >> opened, but never closed. So it is only closed when the Ruby process >> ''./script/localize'' has finished. As a consequence the po files aren''t >> merged correctly. >> >> You have to fix the file: script/rgettext.rb >> >> Add this line: >> >> @out.close >> >> just above the ''end'' statement of ''def start(files=ARGV, output = nil)'' >> (line: 73) > > Ahh, thank you, I applied the patch and uploaded the new archive > > http://digitale-wertschoepfung.de/artikel/gettext/using-gettext-with-rails.tgz > > SaschaThank you very much for the excellent manual. I have found only one little annoyance: when I open the messages.po file in poEdit and click on a string I can open the ruby source file from "References:" if the string is used in a .rb file. But when the string is used in RHTML file this is not possible, because in "References:" I get the name of the temporary file generated with erb. To fix this I have created a small patch, which replaces temporary file with the original RHTML filename in the tokens, returned by RubyParser.parse. Now I can see the real references for strings contained in RHTML files too :) diff rgettext.rb rgettext-patched.rb: 60a61> old_index = ary.size - 161a63,68> #replace tokens with /tmp/... with real file names > for i in old_index..ary.size-1 > for j in 0..ary[i].size-1 > ary[i][j] = ary[i][j].gsub("#{tf.path}", file) > end > end(Just insert the lines above after tf.close statement) Best regards, Luben
Sascha Ebach
2005-Apr-07 13:57 UTC
Re: Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Hello Luben,> Thank you very much for the excellent manual. > I have found only one little annoyance: when I open the messages.po file > in poEdit and click on a string I can open the ruby source file from > "References:" if the string is used in a .rb file. But when the string > is used in RHTML file this is not possible, because in "References:" I > get the name of the temporary file generated with erb. To fix this I > have created a small patch, which replaces temporary file with the > original RHTML filename in the tokens, returned by RubyParser.parse. Now > I can see the real references for strings contained in RHTML files too :) > > diff rgettext.rb rgettext-patched.rb: > > 60a61 > >> old_index = ary.size - 1 > > 61a63,68 > >> #replace tokens with /tmp/... with real file names >> for i in old_index..ary.size-1 >> for j in 0..ary[i].size-1 >> ary[i][j] = ary[i][j].gsub("#{tf.path}", file) >> end >> endThanks for the patch. It doesn''t seem to fully work for me though. It seems to work on some strings but not on others. Haven''t looked into it further. If this would work I''d be glad to include it. I haven''t attempted this myself because I didn''t investigate if the line numbers are still accurate after Erb has compiled the templates. Thx Sascha
Sascha Ebach
2005-Apr-07 14:35 UTC
Re: Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Oops, I meant to paste this: #: /tmp/erb-gettext4595.0:8 msgid "No" msgstr "" #: app/views/layouts/account.rhtml:8 msgid "Yes" msgstr "" Sascha
Mischa Molhoek
2005-Apr-07 16:08 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Sascha Ebach wrote:> Erik Terpstra wrote: > >> Mischa Molhoek wrote: >> >>> Another problem occurs when running script/localize: >>> >>> it seems that in line 18 : ''RGettext.new.start files, potfile'' , >>> "RGettext.new.start" starts in the background, which causes the rest of >>> the script to fail, because there is not filled potfile yet. >>> >>> i assume it does work under windows, because threading is working >>> different there....:) >>> >>> any suggestions on how to make "RGettext.new.start" finish beefore >>> proceeding? >> >> >> >> It is not a threading problem, the IO instance called ''@out'' is >> opened, but never closed. So it is only closed when the Ruby process >> ''./script/localize'' has finished. As a consequence the po files aren''t >> merged correctly. >> >> You have to fix the file: script/rgettext.rb >> >> Add this line: >> >> @out.close >> >> just above the ''end'' statement of ''def start(files=ARGV, output = nil)'' >> (line: 73) > > > Ahh, thank you, I applied the patch and uploaded the new archive > > http://digitale-wertschoepfung.de/artikel/gettext/using-gettext-with-rails.tgz > > > SaschaHi Sascha, I have a question for you: how doe you translate the error message RoR generates, without losing them in an update of RoR Tanx in Advance, Mischa
Sascha Ebach
2005-Apr-07 22:20 UTC
Re: Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
> I have a question for you: how doe you translate the error message RoR > generates, without losing them in an update of RoRI suppose you mean the validation error messages? You can override those. For example I have this in a model: validates_uniqueness_of :title, :message => _(''Every page in the system has to have a unique title. A page with this title already exists.'') Sascha
Mischa Molhoek
2005-Apr-12 09:36 UTC
Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Sascha Ebach wrote:>> I have a question for you: how doe you translate the error message RoR >> generates, without losing them in an update of RoR > > > I suppose you mean the validation error messages? You can override > those. For example I have this in a model: > > validates_uniqueness_of :title, :message => _(''Every page in the system > has to have a unique title. A page with this title already exists.'') > > SaschaNope, I mean the messages generated by the error_messages_for method from the module active_record_helper. Those messages are like this: ''# errors prohibited this <model> from being saved'', and they occur when invalid data is entered in a form. I came up with the following solution: In my app/helpers/application_helper.rb I overruled error_messages_for like this: #overrule error_messages_for from actionpack-1.5.1/lib/action_view/helpers/active_record_helper.rb module ActionView module Helpers module ActiveRecordHelper def error_messages_for(object_name, options = {}) options = options.symbolize_keys object = instance_eval "@#{object_name}" unless object.errors.empty? content_tag("div", content_tag( options[:header_tag] || "h2", "#{object.errors.count} #{_(''error(s) prohibited this'')} #{object_name.gsub("_", " ")} #{_(''from being saved'')}" ) + content_tag("p", "#{_(''There were problems with the following fields:'')}") + content_tag("ul", object.errors.full_messages.collect { |msg| content_tag("li", "#{_(msg.split[0])} #{_(msg.split[1..-1].join('' ''))}") }), "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation" ) end end end end end This does the trick just fine for me, maybe you should include in in your module? Or should it be done in a different way? Greetings, Mischa.
Sascha Ebach
2005-Apr-12 10:58 UTC
Re: Re: [ANN] New Manual: Using Gettext To Translate Your Rails Application
Mischa Molhoek wrote:> Sascha Ebach wrote: > >>>I have a question for you: how doe you translate the error message RoR >>>generates, without losing them in an update of RoR >> >> >>I suppose you mean the validation error messages? You can override >>those. For example I have this in a model: >> >>validates_uniqueness_of :title, :message => _(''Every page in the system >>has to have a unique title. A page with this title already exists.'') >> >>Sascha > > > Nope, I mean the messages generated by the error_messages_for method from the module active_record_helper. > Those messages are like this: ''# errors prohibited this <model> from being saved'', and they occur when invalid data is entered in a form. > > I came up with the following solution: > > In my app/helpers/application_helper.rb I overruled error_messages_for like this: > > #overrule error_messages_for from actionpack-1.5.1/lib/action_view/helpers/active_record_helper.rb > module ActionView > module Helpers > module ActiveRecordHelper > def error_messages_for(object_name, options = {}) > options = options.symbolize_keys > object = instance_eval "@#{object_name}" > unless object.errors.empty? > content_tag("div", > content_tag( > options[:header_tag] || "h2", > "#{object.errors.count} #{_(''error(s) prohibited this'')} #{object_name.gsub("_", " ")} #{_(''from being saved'')}" > ) + > content_tag("p", "#{_(''There were problems with the following fields:'')}") + > content_tag("ul", object.errors.full_messages.collect { |msg| content_tag("li", "#{_(msg.split[0])} #{_(msg.split[1..-1].join('' ''))}") }), > "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation" > ) > end > end > end > end > end > > > This does the trick just fine for me, maybe you should include in in your module? Or should it be done in a different way? > > Greetings, > > Mischa.Hi Mischa, I see. This should be done in a different way. From a translation perspective it should be possible to override any language string that is used in Rails. The problem with your solution is that you have to make sure that in future updates to Rails this class doesn''t change. And if it does you have to adapt it. I think this is worthy of a ticket. Do you want to add it to http://dev.rubyonrails.com/newticket ? You could call it: "Provide a way to override any language relevant string" Sascha