我终于得到了这个。在我确定我的问题是因为 I18n 对我的语言环境一无所知,因为我要求它翻译一些东西后,我对 rails-breadcrumb 进行了猴子修补以管理本地化本身。
知道我将符号作为第一个参数传递,然后我调用I18n.translate()
rails-breadcrumb
add_breadcrumb (:'breadcrumbs.foo.index'), :foo_url
d
# config/initializers/rails-breadcrumb-fix.rb
module Rails
module Breadcrumbs
class ActionController::Base
protected
def add_breadcrumb(name, url = '')
@breadcrumbs ||= []
# if given `name` is a Symbol, we localize it
if name.is_a?(Symbol)
name = I18n.t(name)
end
url = send(url) if url.is_a?(Symbol)
@breadcrumbs << [name, url]
end
def self.add_breadcrumb(name, url, options = {})
before_filter options do |controller|
controller.send(:add_breadcrumb, name, url)
end
end
end
module Helper
def breadcrumbs(separator = "›")
@breadcrumbs.map do |txt, path|
link_to_unless (path.blank? || current_page?(path)), h(txt), path
end.join(" #{separator} ").html_safe
end
end
end
end
ActionController::Base.send(:include, Rails::Breadcrumbs)
ActionView::Base.send(:include, Rails::Breadcrumbs::Helper)