[katello-devel] Gettext - string with parameters
Ivan Nečas
inecas at redhat.com
Tue Aug 16 16:34:16 UTC 2011
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
More information about the katello-devel
mailing list