Forum: Ruby on Rails better dummy method for gettext + rails 2.2

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F3158b6c62d112e4aba9579953e925db?d=identicon&s=25 Wybo Wiersma (wybo)
on 2008-11-26 00:27
(Received via mailing list)
Here's a better dummy method that also handles the
"this is %{jo}" % {:jo => "so"} cases.

class Object
  def self._(msg)
    return msg
  end
  def _(msg)
    return msg
  end
end

class String
  alias :__old_format_m :%
  def %(hash = {})
    if hash.kind_of?(Hash)
      ret = dup
      hash.keys.each do |key, value|
        ret.gsub!("\%\{#{key}\}", value.to_s)
      end
      return ret
    else
      ret = gsub(/%\{/, '%%{')
      ret.__old_format_m(hash)
    end
  end
end

Wybo

- Looking forward to a working rails 2.2 gettext plugin.
8d1abb557a221370f99faf31f4953f82?d=identicon&s=25 James Red (rubyforum)
on 2009-02-21 13:44
fast+threadsave+simple Gettext http://github.com/grosser/fast_gettext

2.2+ rails plugin for gettext and i18n
http://github.com/grosser/gettext_i18n_rails

Example 2.3 application fast_gettext+i18n
http://github.com/grosser/gettext_i18n_rails_example
This topic is locked and can not be replied to.