Jon*_*nas 3 monkeypatching ruby-on-rails-3 rails-i18n
我想改变现有项目中的I18n.translate方法.
require 'I18n'
module I18n
  alias_method :old_translate, :translate
  def translate(*args)
    old_translate(*args) + 'blabla'
  end
  alias_method :t, :translate
end
这会产生:
未捕获的异常:缺少帮助文件助手/ I18n.rb
我做错了什么以及我应该把这段代码放在哪里?
配置/区域设置/ en.yml:
en:
  wtfblabla: hello
test.rb:
require 'i18n'
module I18n
  class<< self
    alias_method :old_translate, :translate
    def translate(*args)
      old_translate(*args) + 'blabla'
    end
    alias_method :t, :translate
  end
end
I18n.load_path += p(Dir[File.join(File.dirname(__FILE__), 'config', 'locales', '*.yml').to_s])
p I18n.t "wtfblabla"
输出:
[ "./config/locales/en.yml"]
"helloblabla"
| 归档时间: | 
 | 
| 查看次数: | 5914 次 | 
| 最近记录: |