Rails is saved in the locale

I'm going to start adding I18n support for the Rails application I'm currently working on. In the past, I set the locale value from the url. I was just wondering how bad the practice of preserving the language is?

So instead:

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

Do something like

 before_filter :set_locale def set_locale I18n.locale = current_user.try(:locale) || I18n.default_locale end 

It seems that FB preserves the locale, what are the tradeoffs of this scheme? how can this affect SEO stuff?

Thanks!

+6
source share
1 answer

I ran into these problems and ended up using this strategy:

  • locale in URL (allows you to cache pages and direct links in a specific language)
  • save locale in user cookie

If the locale is not in the url, try (in order):

  • extract from cookie
  • Guess geolocation
  • guess from the browser header accept the language
  • Default application cessation

Hope this helps; let me know if you want any points to be developed.

+8
source

Source: https://habr.com/ru/post/915700/


All Articles