Created
September 12, 2012 15:15
-
-
Save j15e/3707291 to your computer and use it in GitHub Desktop.
Spree language switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
# app/views/spree/shared/_lang_choice.html.erb | |
# Deface + I18n.with_locale do not play well together, implementing it manually | |
saved_locale = I18n.locale | |
I18n.locale = I18n.locale == :fr ? :en : :fr | |
%> | |
<li class="lang-swich"><%= lang_switch_url %></li> | |
<% I18n.locale = saved_locale %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/helpers/spree/base_help_decorator.rb | |
Spree::BaseHelper.module_eval do | |
def lang_switch_url | |
url = if params[:controller] == 'spree/products' && params[:action] == 'show' | |
{ :id => @product.permalink } | |
elsif params[:controller] == 'spree/taxons' && params[:action] == 'show' | |
{ :id => @taxon.permalink } | |
else | |
{ } | |
end | |
link_to I18n.t("layout.#{I18n.locale}"), url | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing! Successfully integrated on a Spree 1.2.0 project.
Used the Deface DSL in place of Deface::Override: