我正在尝试使用 Rails 3 启动并运行 Gitorious,但我遇到了一个交叉问题。
我在 View 中有这条线。
<p><%= t("views.commits.message").call(self, tree_path(@commit.id)) %></p>
相应的语言环境行如下所示 [
config/locales/en.rb
] :message => lambda { |this, path| "This is the initial commit in this repository, " +
this.link_to( "browse the initial tree state", path ) + "." }
这里的问题是没有使用
#call
调用 lambda 方法。在 View 中,它正在被其他人调用,这意味着 this
不是 self
正在传递给它。this
包含 views.commits.message
和 path
包含 {:rescue_format=>:html}
.Gitorious 团队在整个应用程序中都使用了这种方法,这意味着我不能在不花一天时间的情况下将逻辑移到辅助方法中。
我做了一些研究,发现 this关于确切的线的线程。
这是问题的答案。
This seems to indicate you have the i18n gem installed on your system; this gem is incompatible with Gitorious. Uninstalling it with Rubygems should resolve the issue.
我试过卸载
i18n
,但正在运行 bundle install
只需再次安装它。我应该如何在不重构 700 行语言环境文件的情况下解决这个问题?
最佳答案
这是一个常见的问题,如何分解复杂的嵌套文本。
使用 Markdown 来简化它
This is the initial commit in this repository
[browse the initial tree state](http://example.com/some/path)
.
也许用中文你会说
这是第一个提交在这个知识库
[看初始状态](http://example.com/some/path)
。
我们必须考虑三件事;
如果链接相对于文本的位置不需要更改,则@WattsInABox 正确。
views.commits.message: "This is the initial commit in this repository"
views.commits.browse: "browse the initial tree state"
然后我们就组成
<p>
<%= t "views.commits.message" %>
<%= link_to t("views.commits.browse"), tree_path(@commit.id) %>
.
</p>
但有时顺序和位置确实很重要,
在这种情况下,我们可以尝试变得更聪明。
views.commits.message: "This is the initial commit in this repository %{link}"
views.commits.browse: "browse the initial tree state"
然后我们可以在正确的位置插入链接
<p>
<%= t "views.commits.message", link: link_to(t("views.commits.browse"), tree_path(@commit.id)) %>
</p>
关于ruby-on-rails - 在语言环境文件中使用辅助方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9104455/