5

Possible Duplicate:
How do I override rails naming conventions?

My app is gonna be in spanish. Say I want to scaffold generate actividad. the plural would be actividades so I want the table and the controller to be named that .... how can I do this?

Community
  • 1
  • 1
nacho10f
  • 5,816
  • 6
  • 42
  • 73

3 Answers3

10

Put the following code in config/environment.rb:

Inflector.inflections do |inflect|
  inflect.irregular 'actividad', 'actividades'
end

Test the code in the console (script/console):

'actividad'.pluralize
'actividades'.singularize

More details can be found here: http://codeidol.com/other/rubyckbk/Web-Development-Ruby-on-Rails/Understanding-Pluralization-Rules/

aceofbassgreg
  • 3,837
  • 2
  • 32
  • 42
Kieran Hayes
  • 641
  • 6
  • 12
7

You can add your own pluralizations to Rails by adding inflections. Rails should have a file called inflections.rb under /config/initializers. You can add it there if it isn't. My file as an example (comments come from Rails):

# Add new inflection rules using the following format
# (all these examples are active by default):
# 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.plural(/rion$/ ,'ria') # criterion => criteria
  inflect.singular(/ria$/, 'rion') # criteria => criterion
end
scottd
  • 7,364
  • 1
  • 24
  • 27
3

I think your best bet is to write your code in English, and use the i18n api to present the content in Spanish and other languages if/when necessary.

hgmnz
  • 13,208
  • 4
  • 37
  • 41
  • This is a very "open-sourceic" POV. In real world applications, you often find yourself coding classes out of the customers business model. Translating them into english is sometimes not just a bad idea, it could also break the agreement! – rhavin Nov 22 '12 at 05:28