0

URL을 특정 언어 (예 : en, pt 등)로 유지하려고 시도하지만이를 설정 한 후 'en-US'가 아닌 'en'. (즉, localhost : 3000/ko/apps 대신 localhost : 3000/ko-us/apps). 내 후퇴가 기본이라고 생각 했으므로이 설정을 어디에서 변경할 수 있는지 잘 모릅니다.en 로케일에 "-US"를 추가합니다.

나는 내 길을 접두어 한 다음

scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do 

    root :to => "home#index" 

    get 'omniauth/:provider' => 'omniauth#localized', as: :localized_omniauth 

    devise_for :users, skip: :omniauth_callbacks, :controllers => { :registrations => "registrations", :sessions => "sessions", :passwords => "passwords" } 

    resources :submissions..... 

ApplicationController.rb

def default_url_options(options = {}) 
    {locale: I18n.locale} 
end 

def set_locale 
    I18n.locale = params[:locale] || 
        request.env['rack.locale'] || 
        I18n.default_locale 
end 

Application.rb 당신은 I18n.locale 설정이 누락

config.i18n.default_locale = :en 
config.i18n.available_locales = [:en, :pt] 
config.i18n.fallbacks = true 

답변

0

:

,210
def default_url_options(options={}) 
    { locale: I18n.locale } 
end 

검색 및 사용자의 입력 데이터에 따라, 현재 요청에 대한 로케일 설정 : 내가로 교체해야하는 경우 나는 현재 확인을 set_locale 방법을 가지고 있지만하지 않기 때문에

before_filter :set_locale 

def set_locale 
    if defined?(params) && params[:locale] 
    I18n.locale = params[:locale] 
    elsif current_user && current_user.language_id.present? 
    I18n.locale = current_user.language.code 
    end 
    I18n.locale ||= I18n.default_locale 
end 
+0

내 대답을 편집 한 내용을 당신은 넣거나 추가하십시오. – user3828551

+0

정의되지 않은 로컬 변수 또는 메서드 'extract_locale_from_accept_language_header "가 나타납니다. 그런 다음"valid_languages ​​"에 대해 동일한 오류가 발생합니다. – user3828551

+0

'set_locale' 메서드가 약간 변경되었습니다. 첫 번째 조건이 일치하지 않아 이상해야합니다. 'I18n.available_locales'을 돌려주는 것은 무엇입니까? – blelump