我是rails新手。我想爲page_entries_info顯示我的自定義消息。我已經通過以下鏈接,但不能理解太多。任何人都可以請詳細解釋。給rails中的will_paginate的page_entries_info自定義消息
how-do-i-specify-custom-wording-in-a-will-paginate-view-helper
我是rails新手。我想爲page_entries_info顯示我的自定義消息。我已經通過以下鏈接,但不能理解太多。任何人都可以請詳細解釋。給rails中的will_paginate的page_entries_info自定義消息
how-do-i-specify-custom-wording-in-a-will-paginate-view-helper
另一種選擇是你可以在你的ApplicationHelper
中定義你的page_entries_info()
方法,並像平常一樣使用它。這會給你更多的靈活性,如果你知道你不需要覆蓋邊緣案例(就像我的情況那樣),它甚至可以更加清潔和高效。你可以參考原始方法定義here,看看你需要實現什麼。下面的代碼會運行你的問題的大部分!
def page_entries_info(collection, options = {})
entry_name = options[:entry_name] || (collection.empty?? 'item' :
collection.first.class.name.split('::').last.titleize)
if collection.total_pages < 2
case collection.size
when 0; "No #{entry_name.pluralize} found"
else; "Displaying all #{entry_name.pluralize}"
end
else
%{Displaying %d - %d of %d #{entry_name.pluralize}} % [
collection.offset + 1,
collection.offset + collection.length,
collection.total_entries
]
end
end
這就是默認加載,從project wiki
en:
will_paginate:
page_entries_info:
single_page:
zero: "No %{model} found"
one: "Displaying 1 %{model}"
other: "Displaying all %{count} %{model}"
single_page_html:
zero: "No %{model} found"
one: "Displaying <b>1</b> %{model}"
other: "Displaying <b>all %{count}</b> %{model}"
multi_page: "Displaying %{model} %{from} - %{to} of %{count} in total"
multi_page_html: "Displaying %{model} <b>%{from} - %{to}</b> of <b>%{count}</b> in total"
您需要更改multi_page_html
和multi_page
,最後2項服用。
在en.yml
文件(或者不管它是什麼)把這樣的:
en:
will_paginate:
line_item:
page_entries_info:
multi_page: "Displaying %{from} - %{to} of %{count} of %{model}"
multi_page_html: "Displaying <b>%{from} - %{to}</b> of <b>%{count}</b> of %{model}"
如果您有關於YML文件困難rails i18n guide有點先進的,但提供了有關如何使用陽明文件好的信息 - 只需向下滾動一點:)。
我希望它有幫助。
除了使用國際化以外沒有別的辦法嗎? – 2012-08-01 12:05:43
默認情況下,您的軟件已經「國際化」。這不是「硬道路」。只是試一試.. – 2012-08-01 12:47:13
我正在使用rails引擎,並且在配置中我找不到locale目錄。將創建一個目錄爲我工作 – 2012-08-03 05:14:57
你究竟想要自定義什麼?你能解釋一下嗎? – 2012-08-01 11:13:02
實際上對我來說默認的消息是「顯示總共57的話題1-5」,我想把它作爲「顯示主題57中的1 - 5」。我已經通過鏈接,但不明白在哪裏添加Yaml文件。怎麼運行的? – 2012-08-01 11:20:36