diff --git a/config/initializers/kaminari_config.rb b/config/initializers/kaminari_config.rb index b1d87b01b..45c2b70e4 100644 --- a/config/initializers/kaminari_config.rb +++ b/config/initializers/kaminari_config.rb @@ -8,3 +8,50 @@ Kaminari.configure do |config| # config.page_method_name = :page # config.param_name = :page end + + +# Overrides for making Kaminari handle i18n pluralization correctly +# +# Remove everything below once https://github.com/amatsuda/kaminari/pull/694 is +# merged in Kaminari and we have updated +module Kaminari + + module ActionViewExtension + def page_entries_info(collection, options = {}) + entry_name = if options[:entry_name] + options[:entry_name].pluralize(collection.size) + else + collection.entry_name(:count => collection.size).downcase + end + + if collection.total_pages < 2 + t('helpers.page_entries_info.one_page.display_entries', entry_name: entry_name, count: collection.total_count) + else + first = collection.offset_value + 1 + last = collection.last_page? ? collection.total_count : collection.offset_value + collection.limit_value + t('helpers.page_entries_info.more_pages.display_entries', entry_name: entry_name, first: first, last: last, total: collection.total_count) + end.html_safe + end + end + + module ActiveRecordRelationMethods + def entry_name(options = {}) + model_name.human(options.reverse_merge(default: model_name.human.pluralize(options[:count]))) + end + end + + module MongoidCriteriaMethods + def entry_name(options = {}) + model_name.human(options.reverse_merge(default: model_name.human.pluralize(options[:count]))) + end + end + + class PaginatableArray < Array + ENTRY = 'entry'.freeze + + def entry_name(options = {}) + I18n.t('helpers.page_entries_info.entry', options.reverse_merge(default: ENTRY.pluralize(options[:count]))) + end + end + +end diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index e587a1f65..004ec04f8 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -1,12 +1,33 @@ es: activerecord: models: - comment: Comentario - debate: Debate - tag: Tema - user: Usuario - vote: Voto - organization: Organización + comment: + one: Comentario + other: Comentarios + debate: + one: Debate + other: Debates + tag: + one: Tema + other: Temas + user: + one: Usuario + other: Usuarios + moderator: + one: Moderador + other: Moderadores + administrator: + one: Administrador + other: Administradores + vote: + one: Voto + other: Voto + organization: + one: Organización + other: Organizaciones + proposal: + one: Propuesta ciudadana + other: Propuestas ciudadanas attributes: comment: body: Comentario @@ -16,7 +37,7 @@ es: description: Opinión terms_of_service: Términos de servicio title: Título - propuesta: + proposal: author: Autor title: Título question: Pregunta diff --git a/config/locales/kaminari.en.yml b/config/locales/kaminari.en.yml index e73c82637..e2a79c6b1 100644 --- a/config/locales/kaminari.en.yml +++ b/config/locales/kaminari.en.yml @@ -8,10 +8,14 @@ en: truncate: "…" helpers: page_entries_info: + entry: + zero: "entries" + one: "entry" + other: "entries" one_page: display_entries: zero: "No %{entry_name} found" one: "Displaying 1 %{entry_name}" other: "Displaying all %{count} %{entry_name}" more_pages: - display_entries: "Displaying %{entry_name} %{first} - %{last} of %{total} in total" \ No newline at end of file + display_entries: "Displaying %{entry_name} %{first} - %{last} of %{total} in total" diff --git a/config/locales/kaminari.es.yml b/config/locales/kaminari.es.yml index 50a2fe90c..ab3f8b71f 100644 --- a/config/locales/kaminari.es.yml +++ b/config/locales/kaminari.es.yml @@ -8,10 +8,14 @@ es: truncate: "…" helpers: page_entries_info: + entry: + zero: "entradas" + one: "entrada" + other: "entradas" one_page: display_entries: zero: "No se han encontrado %{entry_name}" - one: "Encontrado 1 %{entry_name}" - other: "Encontrados %{count} %{entry_name}" + one: "Hay 1 %{entry_name}" + other: "Hay %{count} %{entry_name}" more_pages: - display_entries: "Se muestran del %{first} al %{last} de un total de %{total} %{entry_name}" \ No newline at end of file + display_entries: "Mostrando %{first} - %{last} de un total de %{total} %{entry_name}"