I'm using a Sphinx search engine开发者_如何学编程 to perform my searches in a Rails project, through Thinking Sphinx gem. My site is in spanish, so I need to have text obtained from Sphinx translated too.
I'm using page_entries_info
helper to retrieve the search results stats, getting messages such as
Displaying services 1 - 10 of 412 in total
That message is what I'd like to have translated into spanish. No success googling or searching the docs for a configuration item.
Any idea?
This is just a helper from Will Paginate, not Thinking Sphinx. If you want to customise it, I suggest just writing your own helper method (I don't know spanish, but here's a quick English rewrite you can perhaps adapt):
def page_entries_info(collection)
if collection.total_pages < 2
return "Displaying services #{collection.offset + 1} - #{collection.offset + collection.length} of #{collection.total_entries} in total"
end
case collection.size
when 0
'No services found'
when 1
'Displaying 1 service'
else
"Displaying all #{collection.size} services"
end
end
Of course, it doesn't handle different objects, so it may need to get more complicated (if you look at Will Paginate, I've really just stolen the last 10 lines of that method and simplified it - you could just take the code from there and translate it instead for a more extensive implementation).
As suggested by pat, I ended up monkeypatching the will_paginate *page_info_entries ViewHelper*.
I created an initializer under config/initializers directory. You can have a look at it here.
I am using Gettext, but there are some solutions for i18n in the will_paginate github issue.
精彩评论