You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
alu0100921038
changed the title
Translations not working on pruduction environment
Translations not working on production environment
Apr 6, 2020
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.
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.
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.
The text was updated successfully, but these errors were encountered: