1
votes

I'm trying to internacionalize my application made with devise, but i'm struggling in some points. I've installe the i18n gem and created the devise.pt-BR.yml file and wrote inside application.rb

  config.i18n.default_locale = :'pt-BR'

Ok, but when i try to anything inside my application, i get the following error message:

undefined method `default_locale=' for nil:NilClass

Rails.root: /home/ubuntu/workspace/aqueleprojetoprivate/medicos Application Trace | Framework Trace | Full Trace

app/controllers/application_controller.rb:8:in <class:ApplicationController>' app/controllers/application_controller.rb:1:in' activesupport (4.2.4) lib/active_support/dependencies.rb:457:in load' activesupport (4.2.4) lib/active_support/dependencies.rb:457:inblock in load_file' activesupport (4.2.4) lib/active_support/dependencies.rb:647:in new_constants_in' activesupport (4.2.4) lib/active_support/dependencies.rb:456:in load_file' activesupport (4.2.4) lib/active_support/dependencies.rb:354:in require_or_load' activesupport (4.2.4) lib/active_support/dependencies.rb:494:in load_missing_constant' activesupport (4.2.4) lib/active_support/dependencies.rb:184:in const_missing' app/controllers/home_controller.rb:1:in' activesupport (4.2.4) lib/active_support/dependencies.rb:457:in load' activesupport (4.2.4) lib/active_support/dependencies.rb:457:inblock in load_file' activesupport (4.2.4) lib/active_support/dependencies.rb:647:in new_constants_in' activesupport (4.2.4) lib/active_support/dependencies.rb:456:in load_file' activesupport (4.2.4) lib/active_support/dependencies.rb:354:in require_or_load' activesupport (4.2.4) lib/active_support/dependencies.rb:494:in load_missing_constant' activesupport (4.2.4) lib/active_support/dependencies.rb:184:in const_missing' activesupport (4.2.4) lib/active_support/inflector/methods.rb:261:in const_get' activesupport (4.2.4) lib/active_support/inflector/methods.rb:261:in block in constantize' activesupport (4.2.4) lib/active_support/inflector/methods.rb:259:in each' activesupport (4.2.4) lib/active_support/inflector/methods.rb:259:in inject' activesupport (4.2.4) lib/active_support/inflector/methods.rb:259:inconstantize' activesupport (4.2.4) lib/active_support/dependencies.rb:566:in get' activesupport (4.2.4) lib/active_support/dependencies.rb:597:in constantize' actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:72:in controller_reference' actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:62:in controller' actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:41:in serve' actionpack (4.2.4) lib/action_dispatch/journey/router.rb:43:inblock in serve' actionpack (4.2.4) lib/action_dispatch/journey/router.rb:30:in each' actionpack (4.2.4) lib/action_dispatch/journey/router.rb:30:inserve' actionpack (4.2.4) lib/action_dispatch/routing/route_set.rb:821:in call' warden (1.2.4) lib/warden/manager.rb:35:inblock in call' warden (1.2.4) lib/warden/manager.rb:34:in catch' warden (1.2.4) lib/warden/manager.rb:34:incall' rack (1.6.4) lib/rack/etag.rb:24:in call' rack (1.6.4) lib/rack/conditionalget.rb:25:incall' rack (1.6.4) lib/rack/head.rb:13:in call' actionpack (4.2.4) lib/action_dispatch/middleware/params_parser.rb:27:incall' actionpack (4.2.4) lib/action_dispatch/middleware/flash.rb:260:in call' rack (1.6.4) lib/rack/session/abstract/id.rb:225:incontext' rack (1.6.4) lib/rack/session/abstract/id.rb:220:in call' actionpack (4.2.4) lib/action_dispatch/middleware/cookies.rb:560:incall' activerecord (4.2.4) lib/active_record/query_cache.rb:36:in call' activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in call' activerecord (4.2.4) lib/active_record/migration.rb:377:in call' actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:29:inblock in call' activesupport (4.2.4) lib/active_support/callbacks.rb:88:in __run_callbacks__' activesupport (4.2.4) lib/active_support/callbacks.rb:778:in_run_call_callbacks' activesupport (4.2.4) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:27:incall' actionpack (4.2.4) lib/action_dispatch/middleware/reloader.rb:73:in call' actionpack (4.2.4) lib/action_dispatch/middleware/remote_ip.rb:78:in call' actionpack (4.2.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in call' web-console (2.2.1) lib/web_console/middleware.rb:31:incall' actionpack (4.2.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in call' railties (4.2.4) lib/rails/rack/logger.rb:38:incall_app' railties (4.2.4) lib/rails/rack/logger.rb:20:in block in call' activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:inblock in tagged' activesupport (4.2.4) lib/active_support/tagged_logging.rb:26:in tagged' activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:intagged' railties (4.2.4) lib/rails/rack/logger.rb:20:in call' actionpack (4.2.4) lib/action_dispatch/middleware/request_id.rb:21:incall' rack (1.6.4) lib/rack/methodoverride.rb:22:in call' rack (1.6.4) lib/rack/runtime.rb:18:incall' activesupport (4.2.4) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in call' rack (1.6.4) lib/rack/lock.rb:17:incall' actionpack (4.2.4) lib/action_dispatch/middleware/static.rb:116:in call' rack (1.6.4) lib/rack/sendfile.rb:113:incall' railties (4.2.4) lib/rails/engine.rb:518:in call' railties (4.2.4) lib/rails/application.rb:165:incall' rack (1.6.4) lib/rack/lock.rb:17:in call' rack (1.6.4) lib/rack/content_length.rb:15:incall' rack (1.6.4) lib/rack/handler/webrick.rb:88:in service' /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in service' /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in run' /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:in block in start_thread'

How do i fix it?

1

1 Answers

1
votes

It looks like your Rails is version 4.2.

If that is the case, you should not use config.i18n but I18n.
See here:

# in config/initializers/locale.rb

# tell the I18n library where to find your translations
I18n.load_path += Dir[Rails.root.join('lib', 'locale', '*.{rb,yml}')]

# set default locale to something other than :en
I18n.default_locale = :pt