How to configure i18n pt-BR on ruby on rails App, getting an error

I am trying to configure pt-BR on ruby on rails using i18n.

I have added on the file config/application.rb

config.i18n.default_locale = :pt-BR

And on the controller controllers/application_controller.rb


class ApplicationController < ActionController::Base
    before_action :set_locale

    def set_locale
        I18n.locale = params[:lang] || I18n.default_locale
    end
end

When i run rails s i get the error:

: uninitialized constant MyApp::Application::BR (NameError)

If i change the :pt-BR to :pt, for example, it works fine, but not working with pt-BR

Any suggestions to fix that?

>Solution :

you should use quotes around :"pt-BR", instead of only :pt-BR.

try that:

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

source:
https://guiarails.com.br/i18n.html

Leave a Reply