Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pt-BR inflections file for Ruby on Rails applications
# encoding: utf-8
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
ActiveSupport::Inflector.inflections do |inflect|
inflect.clear
inflect.plural(/$/, 's')
inflect.plural(/(s)$/i, '\1')
inflect.plural(/^(paí)s$/i, '\1ses')
inflect.plural(/(z|r)$/i, '\1es')
inflect.plural(/al$/i, 'ais')
inflect.plural(/el$/i, 'eis')
inflect.plural(/ol$/i, 'ois')
inflect.plural(/ul$/i, 'uis')
inflect.plural(/([^aeou])il$/i, '\1is')
inflect.plural(/m$/i, 'ns')
inflect.plural(/^(japon|escoc|ingl|dinamarqu|fregu|portugu)ês$/i, '\1eses')
inflect.plural(/^(|g)ás$/i, '\1ases')
inflect.plural(/ão$/i, 'ões')
inflect.plural(/^(irm|m)ão$/i, '\1ãos')
inflect.plural(/^(alem|c|p)ão$/i, '\1ães')
# Sem acentos...
inflect.plural(/ao$/i, 'oes')
inflect.plural(/^(irm|m)ao$/i, '\1aos')
inflect.plural(/^(alem|c|p)ao$/i, '\1aes')
inflect.singular(/([^ê])s$/i, '\1')
inflect.singular(/^(á|gá|paí)s$/i, '\1s')
inflect.singular(/(r|z)es$/i, '\1')
inflect.singular(/([^p])ais$/i, '\1al')
inflect.singular(/eis$/i, 'el')
inflect.singular(/ois$/i, 'ol')
inflect.singular(/uis$/i, 'ul')
inflect.singular(/(r|t|f|v)is$/i, '\1il')
inflect.singular(/ns$/i, 'm')
inflect.singular(/sses$/i, 'sse')
inflect.singular(/^(.*[^s]s)es$/i, '\1')
inflect.singular(/ães$/i, 'ão')
inflect.singular(/aes$/i, 'ao')
inflect.singular(/ãos$/i, 'ão')
inflect.singular(/aos$/i, 'ao')
inflect.singular(/ões$/i, 'ão')
inflect.singular(/oes$/i, 'ao')
inflect.singular(/(japon|escoc|ingl|dinamarqu|fregu|portugu)eses$/i, '\1ês')
inflect.singular(/^(g|)ases$/i, '\1ás')
# Incontáveis
inflect.uncountable %w( tórax tênis ônibus lápis fênix )
# Irregulares
inflect.irregular "país", "países"
end
@hallison

This comment has been minimized.

Copy link

@hallison hallison commented Sep 20, 2011

Obrigado! Esse código também funciona com o Sequel.infletions.

@mateusg

This comment has been minimized.

Copy link
Owner Author

@mateusg mateusg commented Sep 27, 2011

Legal. :)
Se não me engano, peguei esse arquivo do Brazilian Rails.

@theo-bittencourt

This comment has been minimized.

Copy link

@theo-bittencourt theo-bittencourt commented Feb 6, 2012

Daria pra não flexionar os models? Pois está dando erro no ActiveRecord.
Estou usando o ActiveAdmin e só gostaria de flexionar as traduções feitas pelo pt-BR.yml

@mateusg

This comment has been minimized.

Copy link
Owner Author

@mateusg mateusg commented Mar 7, 2012

Você quer dizer não flexionar os nomes das tabelas?
Se sim, dá uma olhada nesse post: http://devilelephant.blogspot.com/2007/01/rails-plural-table-names-lame.html?m=1
Que erro do ActiveRecord é esse?

@theo-bittencourt

This comment has been minimized.

Copy link

@theo-bittencourt theo-bittencourt commented Mar 7, 2012

Desculpe, não me recordo do erro.

@hebergentilin

This comment has been minimized.

Copy link

@hebergentilin hebergentilin commented Nov 10, 2013

De grande ajuda, parabéns pelo código!

@felipero

This comment has been minimized.

Copy link

@felipero felipero commented Apr 11, 2014

Fases fica como Fas por causa dessa linha: https://gist.github.com/mateusg/924574#file-inflections-rb-L46

@dtelaroli

This comment has been minimized.

Copy link

@dtelaroli dtelaroli commented Oct 13, 2016

Faltou o mês => meses

@MarceloCajueiro

This comment has been minimized.

Copy link

@MarceloCajueiro MarceloCajueiro commented Oct 6, 2017

Extras:

  inflect.plural(/^m(ã|a)o$/i, 'm\1os')
  inflect.singular(/^t(ê|e)nis$/i, 't\1nis')
  inflect.singular(/^(ó|o)culos$/i, '\1culos')
  inflect.singular(/^fases$/i, 'fase')
  inflect.singular(/^m(ê|e)s$/i, 'm\1ses')
  inflect.singular(/^l(á|a)pis$/i, 'l\1pis')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.