# app/controller/application_controller.rb before_action :set_locale # set local {{{ defset_locale I18n.locale = get_locale end # }}} # locale {{{ defget_locale locale = I18n.default_locale if params[:locale] locale = params[:locale].downcase elsif cookies[:locale] locale = cookies[:locale] elsif locale = get_accept_language locale end # set cookies if cookies[:locale] != locale cookies[:locale] = locale end locale end defget_accept_language begin first_lang = request.env['HTTP_ACCEPT_LANGUAGE'].split(';').first default_lang = first_lang[0,2].downcase if default_lang == 'zh' first_lang[3,2].downcase else default_lang end rescue nil end end # }}}