David Celis
7db0b073fe
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-30 21:49:18 -07:00
Xavier Noria
58c83d4c61
make sure the inflection rules are loaded when cherry-picking active_support/core_ext/string/inflections.rb [ fixes #6884 ]
2012-06-29 21:29:14 +02:00
Anuj Dutta
bc51ad957a
Fix an issue with inflection where my_analyses (in plular form) incorrectly converted to my_analyasis(in singular form).
2012-05-16 22:58:03 +01:00
Wes Morgan
16e7f2f809
fix inflector bug where -ice gets pluralized into -ouse
...
This should happen for mouse or louse, but not slice or pumice.
2012-02-25 14:22:15 -07:00
Xavier Noria
fd5d9b366c
fixes a regression introduced by 532cd4, and a bogus test in AP the regression uncovered
2012-02-10 22:17:30 -08:00
Mark McSpadden
532cd49530
Add Inflection test (and fixes) to ensure singularizing a singular actually give you the correct singular in more cases
2012-01-27 02:20:13 -06:00
Mark Rushakoff
6f253fb440
Fix inflection regexes for mouse, mice
2011-12-07 23:14:02 -08:00
Gregg Pollack
554232e481
Added irregular zombie inflection, so zombies no longer gets singularized into zomby
2011-08-07 14:20:03 -04:00
Dan Pickett
1754bd9b20
handle double pluralization for irregular plurals
...
[#6363 ]
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-02-16 15:08:25 -02:00
Rolf Bjaanes
4eab983b95
Changed the way inflections for uncountables work for 'funky jeans' [ #3576 state:resolved]
...
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-04-05 23:54:42 +02:00
Jiri Zajpt
7ed2e6c463
Adding inflection of databases (usually we wouldn't amend the current defaults, but this seems to obvious) [ #1942 state:committed]
...
Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
2009-02-12 14:31:27 +01:00
Joshua Peek
c08547d226
Namespace Inflector, Dependencies, OrderedOptions, and TimeZone under ActiveSupport [ #238 state:resolved]
2008-06-03 13:32:53 -05:00
David Heinemeier Hansson
46b0e7d1d7
Added support for pluralization with a different starting letter than the singular version (cow/kine) ( closes #4929 ) [norri_b/hasmanyjosh]
...
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7092 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2007-06-23 16:47:47 +00:00
Jeremy Kemper
af2ebb29da
Inflections: MatrixTest -> MatrixTests instead of MatricesTest. Closes #8496 .
...
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6886 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2007-05-29 02:40:34 +00:00
Jeremy Kemper
7635facdc8
Inflections: don't singularize -ies plurals.
...
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4868 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-08-30 13:04:37 +00:00
David Heinemeier Hansson
01e389c965
Remove unnecessary brackets in regex ( closes #5715 )
...
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4668 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-08-05 20:44:35 +00:00
Jeremy Kemper
1a44b9cf1a
r3214@asus: jeremy | 2005-11-20 02:03:05 -0800
...
Parenthesize args in Inflections
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3126 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2005-11-21 07:28:59 +00:00
Jeremy Kemper
8210f70c7c
Fix status pluralization bug so status_codes doesn't get pluralized as statuses_code. Closes #2758 .
...
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2900 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2005-11-07 01:20:54 +00:00
David Heinemeier Hansson
9105cd1064
Fixed inflections for status, quiz, move #2056 [deirdre@deirdre.net]
...
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2214 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2005-09-12 05:29:47 +00:00
David Heinemeier Hansson
ffbaf1c5ff
Added irregular inflection sex => sexes #1826 [rails@electricvisions.com]
...
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2200 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2005-09-11 09:30:11 +00:00
David Heinemeier Hansson
9bbb195c03
You will never sleep again!
...
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2113 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2005-09-03 10:33:18 +00:00
David Heinemeier Hansson
1e145099a7
Added String#at, String#from, String#to, String#first, String#last in ActiveSupport::CoreExtensions::String::Access to ease access to individual characters and substrings in a string serving basically as human names for range access. Added easy extendability to the inflector through Inflector.inflections (using the Inflector::Inflections singleton class)
...
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2110 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2005-09-03 07:11:47 +00:00