Internationalization spreee commerce添加第二语言
我需要在我的spree项目中添加对西班牙语的支持。 尝试了各种方法,URL的方式是为我(不是想要的),globalizer3并没有真正做到我想要的。其他一些扩展不起作用,一些会破坏网站,等等 所以我补充说Internationalization spreee commerce添加第二语言,internationalization,e-commerce,locale,spree,Internationalization,E Commerce,Locale,Spree,我需要在我的spree项目中添加对西班牙语的支持。 尝试了各种方法,URL的方式是为我(不是想要的),globalizer3并没有真正做到我想要的。其他一些扩展不起作用,一些会破坏网站,等等 所以我补充说 gem 'spree_i18n', :git => 'git://github.com/spree/spree_i18n.git' gem 'globalize3' 对我的gemfile,而globalizer很可能会被抓伤(不做我想做的) 我在“spree_用户”中添加了一个“def
gem 'spree_i18n', :git => 'git://github.com/spree/spree_i18n.git'
gem 'globalize3'
对我的gemfile,而globalizer很可能会被抓伤(不做我想做的)
我在“spree_用户”中添加了一个“def_lang”列来存储区域设置,该区域设置由用户注册时的下拉框设置。可用的有“en”和“es”
我在过去14个小时里发现的一段代码和重复建议如下:
将以下代码添加到应用程序_controller.rb(或根据其他人的说法添加到base_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
网站已经被翻译了
为什么不起作用?
如何让它工作?
还有什么我可以用来让第二语言在每个用户的基础上工作的吗
请帮我解决这个问题。
params[:def_lang]
仅适用于注册请求,不适用于后续请求。您可能希望使用current_user&¤t_user.locale
而不是检查params[:def_lang]
before_filter :set_locale
protected #<-this is not in all tips
def set_locale
I18n.locale = params[:def_lang] || I18n.default_locale
end
config.i18n.default_locale = :es