简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM