Reputation: 45
How can I create a language toggle with the Mobility gem? Coming from Globalize I was using:
<% if I18n.locale == I18n.default_locale %>
<% Globalize.with_locale(:fr) do %>
<%= link_to "Français", url_for(slug: @page.slug, locale: 'fr') %>
<% end %>
<% else %>
<% Globalize.with_locale('en-ca') do %>
<%= link_to "English", url_for(slug: @page.slug, locale: 'en-ca') %>
<% end %>
<% end %>
But this isn't working with Mobility.
Upvotes: 0
Views: 213
Reputation: 45
Figured it out, for anyone else that has the same issue:
For French
<%= link_to "Français", I18n.with_locale(:fr){page_path(@page, locale: 'fr')}
For English
<%= link_to "English", I18n.with_locale('en-ca'){page_path(@page, locale: 'en-ca')} %>
Answer was found here: https://github.com/norman/friendly_id-globalize/issues/7
Upvotes: 1