Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Localize entry_name in page_entries_info helper #352

Closed
wants to merge 1 commit into from

4 participants

@pavolzbell

Hi, I'm having trouble localizing the entry_name when using the page_entries_info helper.

config/locales/sk.yml

sk:
  helpers:
      more_pages:
        display_entries: "Zobrazuje sa %{total} %{entry_name}."
  judge:
    one: "sudca"
    few: "sudcovia"
    other: "sudcov"

In my views I would like to have:

<%= page_entries_info @judges %>

to produce "Zobrazuje sa 10 sudcov.", but it always outputs "Zobrazuje sa 10 judges.", I've tried some things, like this:

<%= page_entries_info @judges, entry_name: t(:judge, count: @judges.count) %>

but nothing seems to work. Any suggestions?

Then I looked at the code and I think my commit pretty much solves the thing.

@pavolzbell

Maybe a check if the translation exists will be required, or adding a new options key like localized_entry_name would be better -- not breaking existing clients. What do you think?

@lazing

the model_name.human also accept a hash option parameter

http://apidock.com/rails/ActiveModel/Name/human

collection.model_name.human :collection=> total_count

is it better?

@zzak
Collaborator

Duplicate of #309

@zzak zzak closed this
@galievruslan

How to add a translation for the cases when displayed 2, 3, 4 essence?

Like this not working:

helpers:
  page_entries_info:
    one_page:
      display_entries:
        zero: "Не найдено записей<br />"
        one: "Отображена <b>1</b> запись<br />"
        few: "Отображены <b>%{count}</b> записи<br />"
        other: "Отображены <b>%{count}</b> записей<br />"
      more_pages:
        display_entries: "Отображены <b>%{first}&nbsp;-&nbsp;%{last}</b> из <b>%{total}</b> записей"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 3, 2013
  1. @pavolzbell
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/kaminari/helpers/action_view_extension.rb
View
2  lib/kaminari/helpers/action_view_extension.rb
@@ -97,7 +97,7 @@ def page_entries_info(collection, options = {})
collection.model_name.human.downcase
end
end
- entry_name = entry_name.pluralize unless collection.total_count == 1
+ entry_name = t(entry_name, count: collection.total_count)
if collection.total_pages < 2
t('helpers.page_entries_info.one_page.display_entries', :entry_name => entry_name, :count => collection.total_count)
Something went wrong with that request. Please try again.