[katello-devel] Gettext - string with parameters

Ivan Nečas inecas at redhat.com
Wed Aug 17 09:15:12 UTC 2011


On 08/16/2011 06:34 PM, Ivan Nečas wrote:
> On 08/16/2011 06:08 PM, Mike McCune wrote:
>> On 08/14/2011 11:47 PM, Ivan Nečas wrote:
>>> _("Hello %{w}\n") % {:w =>   'World'}
>>
>> this actually fails for me on F14:
>>
>> $ script/rails console
>> Loading development environment (Rails 3.0.5)
>> ruby: main
>> _("Hello %{w}\n") % {:w =>  'World'}
>> NoMethodError: undefined method `to_sym' for nil:NilClass
>>     from 
>> /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/whiny_nil.rb:48:in 
>> `method_missing'
>>     from 
>> /usr/lib/ruby/gems/1.8/gems/i18n-0.5.0/lib/i18n/core_ext/string/interpolate.rb:92:in 
>> `_fast_gettext_old_format_m'
>>     from 
>> /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/core_ext/string/output_safety.rb:110:in 
>> `gsub'
>>     from 
>> /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/core_ext/string/output_safety.rb:110:in 
>> `gsub'
>>     from 
>> /usr/lib/ruby/gems/1.8/gems/i18n-0.5.0/lib/i18n/core_ext/string/interpolate.rb:88:in 
>> `_fast_gettext_old_format_m'
>>     from 
>> /usr/lib/ruby/gems/1.8/gems/fast_gettext-0.5.10/lib/fast_gettext/vendor/string.rb:70:in 
>> `%'
>>     from (irb):1
>> ruby: main
>>
>> but this obviously does work:
>>
>>
>> _("Hello %s\n") % 'World'
>> # => "Hello World\n"
>>
>> ruby: main
>>
>> See:
>>
>> https://bugzilla.redhat.com/show_bug.cgi?id=727627#c2
>>
>> Mike
> Thats strange: when I use rvm + bundle install (with our repo), it 
> works. When I switch to system ruby and gems (from yum), if falls.
>
> Apparently, there are some differences between gems in our repo, and 
> in rpm packages (despite the same versions).
>
> E.g.:
>
> diff 
> /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/core_ext/string/output_safety.rb 
> ~/.rvm/gems/ruby-1.8.7-p352\@katello/gems/activesupport-3.0.5/lib/active_support/core_ext/string/output_safety.rb 
>
>
> 76d75
> <     UNSAFE_STRING_METHODS = ["capitalize", "chomp", "chop", 
> "delete", "downcase", "gsub", "lstrip", "next", "reverse", "rstrip", 
> "slice", "squeeze", "strip", "sub", "succ", "swapcase", "tr", "tr_s", 
> "upcase"].freeze
> 107,118d105
> <
> <     for unsafe_method in UNSAFE_STRING_METHODS
> <       class_eval <<-EOT, __FILE__, __LINE__
> <         def #{unsafe_method}(*args)
> <           super.to_str
> <         end
> <
> <         def #{unsafe_method}!(*args)
> <           raise TypeError, "Cannot modify SafeBuffer in place"
> <         end
> <       EOT
> <     end
>
>
> This might cause the problem, but it needs some investigation.
>
> Quickfix is:
>
> _("Hello %{w}\n").to_str % {:w =>   'World'}
>
> -- Ivan
>
> _______________________________________________
> katello-devel mailing list
> katello-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/katello-devel
I've made some investigation around this, and it's a bug in fast_gettext 
[1] related to rails 3.0.8 version [2]. - In fact, the diff I've sent in 
previous post caused the problem.

The strange thing is, why we have in RPM package rails 3.0.5 something, 
that was officially released in rails 3.0.8. Going to ask on ruby-sig or 
perhaps Vit Ondruch, when I catch him on IRC. I thing these differences 
in general could cause some serious troubles.

We talked about possible variants for gettext before, [3] - Lukas 
recommends the hash option, because you can swap the order in different 
translations.

[1] - https://github.com/grosser/fast_gettext/issues/23
[2] - https://github.com/rails/rails/issues/1555
[3] - 
https://www.redhat.com/archives/katello-devel/2011-August/msg00139.html





More information about the katello-devel mailing list