Search code examples
ruby-on-railsrubylocale

set locale automatically in ruby on rails


how to set locale automatically on ruby on rails? For instance, if the web pages is opened up in Spain then the locale=es, similarly if it is in united kingdom then the locale=en and alike?

Please help me out.


Solution

  • try using gem geocoder and i18n_data gem and have a before_filter to a method which does

    def checklocale
      I18n.locale =  I18nData.country_code(request.location.country) 
    end