Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby On Rails: pluralize for other languages

I am building apps for a non-english audience. Right now, I use english nouns to name my models, yet I prefer to use native dutch ones. As the convention uses the plural of the class name for tables, I assume it is the pluralize method inside Rails (where it resides, I wouldn't know). How can I change the pluralize method and where is it located? Would this break Rails?

I am using Rails 2.3.5 and Ruby 1.8.7

Example: The Book class becomes books now. My Boek class becomes boeks, but it is grammatically correct to use boeken

like image 416
Shyam Avatar asked Jun 08 '10 15:06

Shyam


People also ask

What is pluralize in Ruby?

Plural. rubies. A ruby (gem).

What is locale in Ruby?

Ruby-Locale is the pure ruby library which provides basic APIs for localization.


3 Answers

Add your rules to an inflections.rb file in config/initializers. See the API documentation:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.plural 'boek', 'boeken'
end
like image 144
Christian Lescuyer Avatar answered Oct 19 '22 02:10

Christian Lescuyer


Perhaps won't help you because you want Dutch language, but for Spanish, French, Kazakh, Turkish or Norwegian, there is this:

https://github.com/davidcelis/inflections

like image 23
Mr_LinDowsMac Avatar answered Oct 19 '22 03:10

Mr_LinDowsMac


This is not answering the question specifically, but if a language has too much irregularities one can disable the inflector according to the discussion.

ActiveRecord::Base.pluralize_table_names = false

like image 1
lulalala Avatar answered Oct 19 '22 03:10

lulalala