Reputation: 45
I need to set the default locale to spanish on my application.
These are the lines of my file application.rb:
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
Rails.application.config.i18n.default_locale = :es
end
But, when I generate the scaffold the inflection is wrong. It´s english locale.
rails g scaffold Preparado nombre:string
I get the wrong plural: Preparadoes, It must be: Preparados.
On the console I tried this:
irb(main):015:0> I18n.locale = 'es'
=> "es"
irb(main):016:0> 'preparado'.pluralize()
=> "preparadoes"
irb(main):017:0> 'preparado'.pluralize(:es)
=> "preparados"
irb(main):018:0>
My gemFile contains:
gem 'inflections'
In summary, I need to create an scaffold with the correct pluralization.
Sorry by my english. I know it ´s not the best.
Thanks.
Upvotes: 1
Views: 615
Reputation: 1598
i18n does not affect pluralization here, rails uses inflections for it, and there is only one method I know to customize it:
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'preparado', 'preparados'
end
to config/initializers/inflections.rb
There is Spanish locale for #pluralize
, but you need to set it explicitly every time you call it. And generator calls it without parameters.
Upvotes: 1