fixes kaminari inability to pluralize spanish names

This commit is contained in:
kikito
2015-09-12 18:39:29 +02:00
parent 849a2c83a8
commit 07b99fcf19
4 changed files with 87 additions and 11 deletions

View File

@@ -8,3 +8,50 @@ Kaminari.configure do |config|
# config.page_method_name = :page # config.page_method_name = :page
# config.param_name = :page # config.param_name = :page
end 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

View File

@@ -1,12 +1,33 @@
es: es:
activerecord: activerecord:
models: models:
comment: Comentario comment:
debate: Debate one: Comentario
tag: Tema other: Comentarios
user: Usuario debate:
vote: Voto one: Debate
organization: Organización 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: attributes:
comment: comment:
body: Comentario body: Comentario
@@ -16,7 +37,7 @@ es:
description: Opinión description: Opinión
terms_of_service: Términos de servicio terms_of_service: Términos de servicio
title: Título title: Título
propuesta: proposal:
author: Autor author: Autor
title: Título title: Título
question: Pregunta question: Pregunta

View File

@@ -8,10 +8,14 @@ en:
truncate: "&hellip;" truncate: "&hellip;"
helpers: helpers:
page_entries_info: page_entries_info:
entry:
zero: "entries"
one: "entry"
other: "entries"
one_page: one_page:
display_entries: display_entries:
zero: "No %{entry_name} found" zero: "No %{entry_name} found"
one: "Displaying <b>1</b> %{entry_name}" one: "Displaying <b>1</b> %{entry_name}"
other: "Displaying <b>all %{count}</b> %{entry_name}" other: "Displaying <b>all %{count}</b> %{entry_name}"
more_pages: more_pages:
display_entries: "Displaying %{entry_name} <b>%{first}&nbsp;-&nbsp;%{last}</b> of <b>%{total}</b> in total" display_entries: "Displaying %{entry_name} <b>%{first}&nbsp;-&nbsp;%{last}</b> of <b>%{total}</b> in total"

View File

@@ -8,10 +8,14 @@ es:
truncate: "&hellip;" truncate: "&hellip;"
helpers: helpers:
page_entries_info: page_entries_info:
entry:
zero: "entradas"
one: "entrada"
other: "entradas"
one_page: one_page:
display_entries: display_entries:
zero: "No se han encontrado %{entry_name}" zero: "No se han encontrado %{entry_name}"
one: "Encontrado <b>1</b> %{entry_name}" one: "Hay <b>1</b> %{entry_name}"
other: "Encontrados <b> %{count}</b> %{entry_name}" other: "Hay <b> %{count}</b> %{entry_name}"
more_pages: more_pages:
display_entries: "Se muestran <b> del %{first}&nbsp;al&nbsp;%{last}</b> de un total de <b>%{total}</b> %{entry_name}" display_entries: "Mostrando <b>%{first}&nbsp;-&nbsp;%{last}</b> de un total de <b>%{total}</b> %{entry_name}"