Skip to content

Instantly share code, notes, and snippets.

@coop
Last active December 24, 2015 23:48
Show Gist options
  • Save coop/6882489 to your computer and use it in GitHub Desktop.
Save coop/6882489 to your computer and use it in GitHub Desktop.
# config/routes.rb
get '/:country/welcome' => 'welcome#show'
# app/controllers/welcome_controller.rb
class WelcomeController < ApplicationController
around_filter :set_preferred_locale
private
def set_preferred_locale
I18n.locale = header_locale || params.fetch(:country, I18n.default_locale)
end
def header_locale
headers['Accept-Language']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment