Skip to content

Instantly share code, notes, and snippets.

@maxidr
Created February 22, 2011 03:51
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save maxidr/838188 to your computer and use it in GitHub Desktop.
Save maxidr/838188 to your computer and use it in GitHub Desktop.
Spanish inflectors for rails 3
ActiveSupport::Inflector.inflections do |inflect|
inflect.plural /([aeiou])([A-Z]|_|$)/, '\1s\2'
inflect.plural /([rlnd])([A-Z]|_|$)/, '\1es\2'
inflect.plural /([aeiou])([A-Z]|_|$)([a-z]+)([rlnd])($)/, '\1s\2\3\4es\5'
inflect.plural /([rlnd])([A-Z]|_|$)([a-z]+)([aeiou])($)/, '\1es\2\3\4s\5'
inflect.singular /([aeiou])s([A-Z]|_|$)/, '\1\2'
inflect.singular /([rlnd])es([A-Z]|_|$)/, '\1\2'
inflect.singular /([aeiou])s([A-Z]|_)([a-z]+)([rlnd])es($)/, '\1\2\3\4\5'
inflect.singular /([rlnd])es([A-Z]|_)([a-z]+)([aeiou])s($)/, '\1\2\3\4\5'
# Se agregan inflectores para todos los casos de detalle_ y detalles_
# Ejs.:
# detalle_pendiente_aprobacion -> detalles_pediente_aprobacion
# detalle_rechazo -> detalles_rechazo
inflect.plural /(\bdetalle)(\w+|_|$)/, '\1s\2'
inflect.plural /(\bdetalles)(\w+|_|$)/, '\1\2'
inflect.singular /(\bdetalle)s(\w+|_|$)/, '\1\2'
# Para evitar errores de pluralización utilizados por formtastic al utilizar i18n
# (https://github.com/justinfrench/formtastic/blob/master/lib/formtastic.rb#L1850)
inflect.irregular 'label', 'labels'
inflect.irregular 'title', 'titles'
inflect.irregular 'hint', 'hints'
inflect.irregular 'action', 'actions'
end
@zaknafein99
Copy link

Where do I put this? I tried in environments - Development, Production, Test, etc. but nothing, when I try to create a scaffold for pais it says it's already plural an falls to singular pai, it should be paises (plural)

@grillermo
Copy link

For future reference, you should put this on
config/initializers/inflections.rb
And do not add all these rules if you already built your models with the english inflections, or rails will fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment