2012-08-08 22 views
0

我需要在我的狂歡項目中添加對西班牙語的支持。 嘗試了各種方法,URL的方式對我來說(不想),globalizer3不真正做我想要的。一些其他的擴展不工作,有些殺網站等Spreee-commerce增加第二種語言

,所以我增加了

gem 'spree_i18n', :git => 'git://github.com/spree/spree_i18n.git' 
gem 'globalize3' 

我的Gemfile,而全球化者預訂購最有可能被劃傷(沒有做我想要什麼)。

我已將「def_lang」列添加到「spree_users」來存儲區域設置,該區域由用戶註冊時的下拉框設置。可用的是「en」和「es」。

的代碼段和重複建議我發現在過去14個小時這樣的:

(根據他人或base_controller.rb)

before_filter :set_locale 

protected 
def set_locale 
I18n.locale = params[:locale] || I18n.default_locale 
end 
下面的代碼添加到application_controller.rb

哪我我的情況應該是

before_filter :set_locale 

protected #<-this is not in all tips 
    def set_locale 
    I18n.locale = params[:def_lang] || I18n.default_locale 
end 

使它短,它不工作。 西班牙作品中的語言支持,可以通過在「application.rb中」設置

config.i18n.default_locale = :es 

被證明和現場翻譯。

爲什麼不起作用? 如何使它工作? 還有什麼我可以用來獲得第二語言在每個用戶的基礎上工作?

請幫我解決這個問題。

回答

0

params[:def_lang]只適用於註冊請求,不適用於後續請求。你可能想要得到這個使用current_user && current_user.locale,而不是檢查params[:def_lang]