“will_paginate”的翻译不起作用。我究竟做错了什么?

时间:2012-10-16 09:35:33

标签: ruby-on-rails ruby internationalization locale will-paginate

基本方案:

= will_paginate @products, :previous_label => t("previous_label"), :next_label => t("next_label")

de.yml

  will_paginate:
    page_gap: "…"
    previous_label: "word for back"
    next_label: "word for next"

en.yml     于:       will_paginate:         page_gap:“......”         previous_label:“上一个”         next_label:“下一步”

但在输出中仍然是名为Previous LabelNext Label的标签。 还有什么问题?另外,我以为我没有重启服务器......但重启后仍然是相同的标签,而不是我的翻译

2 个答案:

答案 0 :(得分:6)

您可以在此处抓取以各种语言翻译的YAML文件:https://github.com/tigrish/will-paginate-i18n

在你的例子中,你覆盖了:previous_label和:next_label,但是你并没有把它作为'will_paginate'。

完全删除覆盖并自定义翻译文件中的标签:

will_paginate @products

.t正确调用范围:

will_paginate @products,
  :previous_label => t("will_paginate.previous_label"),
  :next_label     => t("will_paginate.next_label")

答案 1 :(得分:4)

然后,您可以通过将以下内容添加到config/locales/will_paginate.en.yml:

来更改分页链接的文本
en:
  will_paginate:
    page_gap: "…"
    previous_label: "previous"
    next_label: "next"

并在application.rb

中添加以下内容
config.i18n.default_locale = :en