Skip to content

Instantly share code, notes, and snippets.

View alec-c4's full-sized avatar
🪓
I do make sacrifices to Odin

Alexey Poimtsev alec-c4

🪓
I do make sacrifices to Odin
View GitHub Profile
@alec-c4
alec-c4 / gist:138659
Created July 1, 2009 07:53
locale filter
###### application_controller.rb
before_filter :set_locale
def set_locale
locale = params[:locale] || cookies[:locale] || TLD_LOCALES[request.host.split('.').last] || request.headers['HTTP_ACCEPT_LANGUAGE'].split(',').map { |l| l.split(';').first }
locale = DEFAULT_LOCALE unless (SUPPORTED_LOCALES).include?(locale.to_s)
I18n.locale = locale.to_s
cookies[:locale] = locale unless (cookies[:locale] && cookies[:locale] == locale)