如何在will_paginate视图助手中指定自定义措辞?
我正在使用带有Rails 2.3.11的will_paginate 2.3.25。
我希望我的page_entries_info
视图帮助器说“显示所有n [我自己的自定义措辞]”,而不是根据模型自动生成项目名称。
这样做的语法是什么?
设置您的翻译yaml文件,以包括在对其进行分页时要调用的模型。
阅读本文档后: https : //github.com/mislav/will_paginate/wiki/I18n
en: will_paginate: models: line_item: zero: line items one: line item few: line items other: line items
或者对于“只需一次解决方案”,您可以使用page_entries_info
来自RDoc:
page_entries_info(collection, options = {})
呈现有用的消息,其中包含显示的数量与总条目数。 您可以将此作为您自己的类似帮助者的蓝图。
<%= page_entries_info @posts %> #-> Displaying posts 6 - 10 of 26 in total
默认情况下,消息将使用集合中对象的人性化类名称:例如,ProjectType模型的“项目类型”。 使用:entry_name参数覆盖它:
<%= page_entries_info @posts, :entry_name => 'item' %> #-> Displaying items 6 - 10 of 26 in total
使用:entry_name
参数。
= page_entries_info @posts, :entry_name => 'item' #-> Displaying items 6 - 10 of 26 in total