2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2017-06-30 01:00:04 -04:00
|
|
|
require_relative "inflector/inflections"
|
2012-06-29 15:29:14 -04:00
|
|
|
|
2014-02-11 03:06:28 -05:00
|
|
|
#--
|
|
|
|
# Defines the standard inflection rules. These are the starting point for
|
2014-02-10 02:50:06 -05:00
|
|
|
# new projects and are not considered complete. The current set of inflection
|
|
|
|
# rules is frozen. This means, we do not change them to become more complete.
|
|
|
|
# This is a safety measure to keep existing applications from breaking.
|
2014-02-11 03:06:28 -05:00
|
|
|
#++
|
2008-06-03 14:32:53 -04:00
|
|
|
module ActiveSupport
|
Make ActiveSupport::Inflector locale aware and multilingual
The Inflector is currently not very supportive of internationalized
websites. If a user wants to singularize and/or pluralize words based on
any locale other than English, they must define each case in locale
files. Rather than create large locale files with mappings between
singular and plural words, why not allow the Inflector to accept a
locale?
This patch makes ActiveSupport::Inflector locale aware and uses `:en`` unless
otherwise specified. Users will still be provided a list of English (:en)
inflections, but they may additionally define inflection rules for other
locales. Each list is kept separately and permanently. There is no reason to
limit users to one list of inflections:
ActiveSupport::Inflector.inflections(:es) do |inflect|
inflect.plural(/$/, 's')
inflect.plural(/([^aeéiou])$/i, '\1es')
inflect.plural(/([aeiou]s)$/i, '\1')
inflect.plural(/z$/i, 'ces')
inflect.plural(/á([sn])$/i, 'a\1es')
inflect.plural(/é([sn])$/i, 'e\1es')
inflect.plural(/í([sn])$/i, 'i\1es')
inflect.plural(/ó([sn])$/i, 'o\1es')
inflect.plural(/ú([sn])$/i, 'u\1es')
inflect.singular(/s$/, '')
inflect.singular(/es$/, '')
inflect.irregular('el', 'los')
end
'ley'.pluralize(:es) # => "leyes"
'ley'.pluralize(:en) # => "leys"
'avión'.pluralize(:es) # => "aviones"
'avión'.pluralize(:en) # => "avións"
A multilingual Inflector should be of use to anybody that is tasked with
internationalizing their Rails application.
Signed-off-by: David Celis <david@davidcelis.com>
2012-07-29 18:31:53 -04:00
|
|
|
Inflector.inflections(:en) do |inflect|
|
2016-08-06 11:58:50 -04:00
|
|
|
inflect.plural(/$/, "s")
|
|
|
|
inflect.plural(/s$/i, "s")
|
2012-02-11 01:17:30 -05:00
|
|
|
inflect.plural(/^(ax|test)is$/i, '\1es')
|
2008-06-03 14:32:53 -04:00
|
|
|
inflect.plural(/(octop|vir)us$/i, '\1i')
|
2011-02-07 21:39:46 -05:00
|
|
|
inflect.plural(/(octop|vir)i$/i, '\1i')
|
2008-06-03 14:32:53 -04:00
|
|
|
inflect.plural(/(alias|status)$/i, '\1es')
|
|
|
|
inflect.plural(/(bu)s$/i, '\1ses')
|
|
|
|
inflect.plural(/(buffal|tomat)o$/i, '\1oes')
|
|
|
|
inflect.plural(/([ti])um$/i, '\1a')
|
2011-02-07 21:39:46 -05:00
|
|
|
inflect.plural(/([ti])a$/i, '\1a')
|
2016-08-06 11:58:50 -04:00
|
|
|
inflect.plural(/sis$/i, "ses")
|
2008-06-03 14:32:53 -04:00
|
|
|
inflect.plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves')
|
|
|
|
inflect.plural(/(hive)$/i, '\1s')
|
|
|
|
inflect.plural(/([^aeiouy]|qu)y$/i, '\1ies')
|
|
|
|
inflect.plural(/(x|ch|ss|sh)$/i, '\1es')
|
|
|
|
inflect.plural(/(matr|vert|ind)(?:ix|ex)$/i, '\1ices')
|
2012-02-25 16:14:38 -05:00
|
|
|
inflect.plural(/^(m|l)ouse$/i, '\1ice')
|
|
|
|
inflect.plural(/^(m|l)ice$/i, '\1ice')
|
2008-06-03 14:32:53 -04:00
|
|
|
inflect.plural(/^(ox)$/i, '\1en')
|
2011-02-07 21:39:46 -05:00
|
|
|
inflect.plural(/^(oxen)$/i, '\1')
|
2008-06-03 14:32:53 -04:00
|
|
|
inflect.plural(/(quiz)$/i, '\1zes')
|
2005-09-03 03:11:47 -04:00
|
|
|
|
2016-08-06 11:58:50 -04:00
|
|
|
inflect.singular(/s$/i, "")
|
2012-01-27 03:20:13 -05:00
|
|
|
inflect.singular(/(ss)$/i, '\1')
|
2008-06-03 14:32:53 -04:00
|
|
|
inflect.singular(/(n)ews$/i, '\1ews')
|
|
|
|
inflect.singular(/([ti])a$/i, '\1um')
|
2012-05-16 17:56:08 -04:00
|
|
|
inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '\1sis')
|
2012-01-27 03:20:13 -05:00
|
|
|
inflect.singular(/(^analy)(sis|ses)$/i, '\1sis')
|
2008-06-03 14:32:53 -04:00
|
|
|
inflect.singular(/([^f])ves$/i, '\1fe')
|
|
|
|
inflect.singular(/(hive)s$/i, '\1')
|
|
|
|
inflect.singular(/(tive)s$/i, '\1')
|
|
|
|
inflect.singular(/([lr])ves$/i, '\1f')
|
|
|
|
inflect.singular(/([^aeiouy]|qu)ies$/i, '\1y')
|
|
|
|
inflect.singular(/(s)eries$/i, '\1eries')
|
|
|
|
inflect.singular(/(m)ovies$/i, '\1ovie')
|
|
|
|
inflect.singular(/(x|ch|ss|sh)es$/i, '\1')
|
2012-02-25 16:14:38 -05:00
|
|
|
inflect.singular(/^(m|l)ice$/i, '\1ouse')
|
2012-01-27 03:20:13 -05:00
|
|
|
inflect.singular(/(bus)(es)?$/i, '\1')
|
2008-06-03 14:32:53 -04:00
|
|
|
inflect.singular(/(o)es$/i, '\1')
|
|
|
|
inflect.singular(/(shoe)s$/i, '\1')
|
2012-02-11 01:17:30 -05:00
|
|
|
inflect.singular(/(cris|test)(is|es)$/i, '\1is')
|
|
|
|
inflect.singular(/^(a)x[ie]s$/i, '\1xis')
|
2012-01-27 03:20:13 -05:00
|
|
|
inflect.singular(/(octop|vir)(us|i)$/i, '\1us')
|
|
|
|
inflect.singular(/(alias|status)(es)?$/i, '\1')
|
2008-06-03 14:32:53 -04:00
|
|
|
inflect.singular(/^(ox)en/i, '\1')
|
|
|
|
inflect.singular(/(vert|ind)ices$/i, '\1ex')
|
|
|
|
inflect.singular(/(matr)ices$/i, '\1ix')
|
|
|
|
inflect.singular(/(quiz)zes$/i, '\1')
|
2009-02-11 11:27:38 -05:00
|
|
|
inflect.singular(/(database)s$/i, '\1')
|
2005-09-03 03:11:47 -04:00
|
|
|
|
2016-08-06 11:58:50 -04:00
|
|
|
inflect.irregular("person", "people")
|
|
|
|
inflect.irregular("man", "men")
|
|
|
|
inflect.irregular("child", "children")
|
|
|
|
inflect.irregular("sex", "sexes")
|
|
|
|
inflect.irregular("move", "moves")
|
|
|
|
inflect.irregular("zombie", "zombies")
|
2005-09-03 03:11:47 -04:00
|
|
|
|
2012-02-25 16:14:38 -05:00
|
|
|
inflect.uncountable(%w(equipment information rice money species series fish sheep jeans police))
|
2008-06-03 14:32:53 -04:00
|
|
|
end
|
2005-11-06 20:20:54 -05:00
|
|
|
end
|