How do I link the same page in another language with the i18n gem for Refinery CMS?
-
19-06-2021 - |
Domanda
I'm converting a site into the Rails based Refinery CMS, I've setup the i18n refinery cms gem and I've created multi-lingual versions of my pages. I'd like to create a locale switcher on the page, so that a user can click on a flag and switch between the various languages for the particular page that they are on.
How can I get the available languages for a page, and their respective links?
Soluzione
# In a controller
::I18n.locale = params[:locale]
<!-- In a view with a dropdown -->
<ul id="menu1" class="dropdown-menu" role="menu" aria-labelledby="drop4">
<% Refinery::I18n.frontend_locales.each do |frontend_locale| %>
<li>
<%= link_to Refinery::I18n.locales[frontend_locale], refinery.url_for(:locale => frontend_locale) %>
</li>
<% end %>
</ul>
Altri suggerimenti
<ul id="laguages">
<%
@page.translations.each do |t|
%>
<li>
<%= link_to "#{@page.translations.find_by_locale(t.locale).title} (#{Refinery::I18n.locales[t.locale]} #{image_tag("/assets/refinery/icons/flags/#{t.locale}.png")})".html_safe, refinery.url_for(:locale => t.locale) %>
</li>
<%
end
%>
</ul>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow