Ruby-GetText-Package FAQ
ruby-gettext-faq
Table of contents
Installation Questions
rgettext or rake updatepo doesn't work with "numeric literal without digits".
If you use ruby-1.8.2, update it to ruby-1.8.3 or later. This is the bug of ruby-1.8.2.
General Questions
rgettext doesn't extract "#{name}" strings.
"#{name}" style isn't supported. Use % style instead.
_("it's #{name}") => _("it's %s") % name
=> _("it's %{name}") % {:name => name}
rgettext doesn't extract "#{_('name')}" strings.
"#{_('name')}" style also isn't supported. Use % style instead.
"I like #{_('ruby')}" => "I like " + _('ruby')
But I recommand not to separate theses words for other languages.
For example, this case should include "I like" as the msgid.
"I like #{_('ruby')}" => _("I like ruby")
rgettext occurs a syntax error with nested quotes in a String
This is a problem of Ruby-1.8.x (but won't fix).
Work arround is to avoid nested quotes.
_("#{Time.now.strftime("%m/%d")}") => _("#{Time.now.strftime('%m/%d')}")
Doesn't translate messages to my locale correctly
Execute ruby with -d option.
If you can find the messages below, the target mo-file is not found. Check the file is copied one of the path correctly.
bind the domain 'hello' to 'hello.rb'. locale is #<Locale::Object:0xb7e29bcc @country="CN", @modifier=nil, @language="zh", @variant=nil, @charset="GB2312", @orig_str="zh_CN", @script=nil> MO file is not found in locale/zh_CN/LC_MESSAGES/hello.mo locale/zh_CN/LC_MESSAGES/hello.mo locale/zh/LC_MESSAGES/hello.mo locale/zh_CN/hello.mo locale/zh_CN/hello.mo locale/zh/hello.mo
If you can find the messages below, the target mo-file was loaded correctly. Check po-file and there is the entry(msgid/msgstr) again and mo-file is updated.
bind the domain 'hello' to 'hello.rb'. locale is #<Locale::Object:0xb7ed1bcc @country="JP", @modifier=nil, @language="ja", @variant=nil, @charset="UTF-8", @orig_str="ja_JP.UTF-8", @script=nil> GetText::TextDomain#load_mo: mo file is locale/ja/LC_MESSAGES/hello.mo
In most cases, you use "zh_CN" as the locale directory, but clients require "zh".
If the client requires "zh_CN", the search path becomes below:
locale/zh_CN/LC_MESSAGES/hello.mo locale/zh_CN/LC_MESSAGES/hello.mo locale/zh/LC_MESSAGES/hello.mo locale/zh_CN/hello.mo locale/zh_CN/hello.mo locale/zh/hello.mo
If the client requires "zh", the search path becomes below:
locale/zh/LC_MESSAGES/hello.mo locale/zh/hello.mo
"zh" is more general(because it matches "zh", "zh_CN", "zh_HK", "zh_TW"). So I recommand to use "zh" not "zh_CN". And if you want to separate "CN", then add "zh_CN".
How can I get msgmerge ?
msgmerge is a part of GNU GetText package. Almost of all Unix-like system, it's been installed or it's been produced the package by their distributors.
On MS Windows, I highly recommand to use GLADE/GTK+ for Windows. Notice to install Development environment, not Runtime environment.
If you install this you can also use Ruby-GNOME2 to install ruby-gtk2 binary package, only ;).
Server application Questions
Why do I need to restart the server application(something like Webrick) after adding/modifying translations?
If you run ruby with -d option, Ruby-GetText checks mo-files everytime and re-load it if the files are changed.
Or you can put it in your application like as:
Gtk::Textdomain.check_mo = true
BTW, on Ruby on Rails, this is set under development mode. So you don't take care about it.
OK, still not updated.
If you use GetText methods(e.g.: _("foo")) in a class context, it won't update automatically. Furthermore you can't changes the message for another request from a new client who requires another locale.
Because the method in a class context is evaluated when the class is loaded. So, you need to call GetText functions as instance methods.
class Test
FOO = _("foo") # This evaluate when the Test class is loaded.
def foo
puts FOO
end
end
An solution:
class Test
FOO = N_("foo")
def foo
GetText.locale = "you can change this on each request"
puts _(FOO)
end
end
Ruby on Rails Questions
Model table/column names are not found in pot file.
Confirm to run your database and connect to it correctly.
"duplicate message definition" errors
If you get this error when execute rake updatepo or makemo, try to write a model per a file(modelname.rb).
<URL:http://www.ruby-forum.com/topic/64971#new>
How to add the messages translation for my locale
Your locale hasn't supported by Ruby-GetText-Package yet, the messages show in English.
But you can add your locale easily as follows:
1. Go ruby-gettext home (if you installed it as gem then /usr/lib/ruby/gems/1.8/gems/gettext-x.x.x/ or c:\ruby\lib\ruby\gems\1.8\gems\gettext-x.x.x\. If you installed it as tar-ball, extract tar-ball and change directory to the top directory).
2. Translate po/rails.pot in your locale to po/yourlocale/rails.po.
3. Run "rake makemo" on the top directory. 4. if you use tar version, run "ruby setup.rb install" after "rake makemo". 5. Your new locale is installed properly.
It's better to help me to translate your locale. It will be included in Next Ruby-GetText-Package.
An error is occured when I do "rake updatepo"
Check model files require other library such as RMagick. "updatepo" task loads the model files. So if the Model doesn't work correctly, "updatepo" task will be failed. Basically, you shouldn't require other libraries in a model itself.
Keyword(s):
References:[Ruby-GetText-Package]