Rails persisted locale
internationalization, ruby-on-rails, ruby-on-rails-3
Solution
I've faced these issues and ended up using this strategy:
- locale in URL (allows page caching and direct linking in specific language)
- store locale in user cookie
If locale is not present in URL, try (in order):
- retrieve from cookie
- guess from geolocation
- guess from browser header accept language
- fallback to app default
Hope that helps; let me know if you'd like any points elaborated on.
Problem
I'm about to start adding I18n support for a Rails app I'm currently working on. In the past I have set the locale value from the URL. I just was wondering how bad practice it'd be to persist the locale? So instead of something like this: ``` 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 looks like FB persists the locale, what are the trade-offs of this schema? how might this affect SEO stuff? Thanks!