로켈이없는 경우 레일스는 기본 로켈로 "en"이 기본 설정됩니다. 따라서 http://localhost:3000/?locale=de을 전달하면 해당 번역이 존재하지 않으므로 역겨워하려면 'en'이 사용됩니다.
여기 봐
http://guides.rubyonrails.org/i18n.html, 특히 "절 2.3 설정 및 로케일을 전달"가
#config/initializers/available_locales.rb
# Get loaded locales conveniently
module I18n
class << self
def available_locales; backend.available_locales; end
end
module Backend
class Simple
def available_locales; translations.keys.collect { |l| l.to_s }.sort; end
end
end
end
# You need to "force-initialize" loaded locales
I18n.backend.send(:init_translations)
AVAILABLE_LOCALES = I18n.backend.available_locales
RAILS_DEFAULT_LOGGER.debug "* Loaded locales: #{AVAILABLE_LOCALES.inspect}"
그러면와 ApplicationController에 쉽게 액세스 할 수 있도록 일정하게 포장 할 수 있습니다
class ApplicationController < ActionController::Base
def available_locales; AVAILABLE_LOCALES; end
end
당신은 구현할 수를 그것은 당신의 ApplicationController에서 이것을 좋아합니다 :
before_filter :set_locale
def set_locale
I18n.locale = extract_locale_from_params
end
def extract_locale_from_params
parsed_locale = params[:locale]
(available_locales.include? parsed_locale) ? parsed_locale : nil
end
HTH