Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translations not working on production environment #525

Open
alu0100921038 opened this issue Apr 6, 2020 · 1 comment
Open

Translations not working on production environment #525

alu0100921038 opened this issue Apr 6, 2020 · 1 comment

Comments

@alu0100921038
Copy link

I'm making the translations of a project im working on. I have some init.rb which are giving me problems.

So, in my database,the users have a column named "preferred_locale", which saves the language chosen by the user. Later, in the application_controller, i have this method, which assigns the locale to the user so this is persistent even if you restart the session.

def switch_locale(&action)
    if current_user
      I18n.locale = current_user.try(:preferred_locale) || I18n.default_locale
      I18n.with_locale(I18n.locale, &action)
    else
      I18n.with_locale(I18n.locale, &action)
    end
  end

Coming back to the init.rb files, the translations of these files are working, since the locale is correctly assigned, if i print I18n.locale it shows "es" (spanish). the problem is that when i run the project in production mode, if i print I18n.locale, this is returning "en" (the default locale). I'm so lost in how to fix this problem, the only thing that i need is that these init.rb (they are inside the modules folders) work the same way as development but i'm stuck with this. Any ideas?

I was looking at the folder called environments, which have the files development.rb and production.rb but i dont know what i can change here in order to make it work.

I've read something about putting in the production config file something like config.application.eager_load! but i dont exactly understand what this is doing.

@alu0100921038 alu0100921038 changed the title Translations not working on pruduction environment Translations not working on production environment Apr 6, 2020
@bonol
Copy link

bonol commented Jun 8, 2021

I reckon this one is more 'StackOverflow type of question.

Back to your question, why do you need to configure init.rb? If you follow through Rails official documentation, only locale.rb is required to configure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants