-
Notifications
You must be signed in to change notification settings - Fork 341
Open
Description
From @joelpresence on May 13, 2015 18:53
According to the default auto-generated config/application.rb that comes from rails new toy_app in Rails 4.2.1 using Ruby 2.2.2p95 (for Heroku compatibility):
...
module ToyApp
class Application < Rails::Application
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
...
end
end
all locales in config/locales are autoloaded. However, this is clearly not true and here are the repro steps:
1. Create a file config/locales/fr.yml as follows:
fr:
hello: "Bonjour"
2. Run bundle exec console rails.
3. Execute the statement:
I18n.locale = :fr
4. Get the stack trace:
I18n::InvalidLocale: :fr is not a valid locale
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/i18n-0.7.0/lib/i18n.rb:284:in `enforce_available_locales!'
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/i18n-0.7.0/lib/i18n/config.rb:13:in `locale='
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/i18n-0.7.0/lib/i18n.rb:35:in `locale='
from (irb):1
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/railties-4.2.1/lib/rails/commands/console.rb:110:in `start'
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/railties-4.2.1/lib/rails/commands/console.rb:9:in `start'
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/railties-4.2.1/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
from /Users/joel/src/hartl/toy_app/bin/rails:8:in `<top (required)>'
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/joel/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
from /Users/joel/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/joel/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
Now, if you go to that default auto-generated application.rb that claims that all locales are auto-loaded and uncomment the line:
# Uncomment this line
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# ... and change it to be
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s]
then everything works:
shell> bundle exec rails console
rails console> I18n.locale = :fr
=> :fr
rails console> I18n.t 'hello'
=> "Bonjour"
So there are two or more bugs here:
- Either the autoloading is failing for the rails console.
- Or the comments in the auto-generated
application.rbabout all locales being auto-loaded are wrong and also the Rails Docs at Configuring the i18n module are also wrong.
This buggy behavior is very confusing for somebody first trying to internationalize a Rails app since the console is a great place to test translations and localizations.
Thanks.
Copied from original issue: rails/rails#20144
Metadata
Metadata
Assignees
Labels
No labels