Open vincentcordel opened 9 years ago
Hey,
I am having the same issue. Have you found a work around?
I found a workaround. Not sure if it's the most efficient but it works.
First create a partial on your layout:
<%= yield :change_lang %>
Then include the partial for each view page (model is story)
<% content_for :change_lang do %>
<ul class="languages">
<li><%= link_to t('menu.languages.text_fr'), url_for(id: @story.slug_fr, locale: 'fr') %></li>
<li><%= link_to t('menu.languages.text_en'), url_for(id: @story.slug_en, locale: 'en') %></li>
</ul>
<% end %>
Hope this helps,
As explained in the readme, if a slug in a specific locale is empty, shouldn't it fallback to the default locale and still find the record ?
If I have a similar use of @story.slug_en, and that the record have not been saved yet in its english locale version, it does returns nil so far and breaks with an error (@story.slug_en would be nil)
Is there is something to add in the conf ? With plain id's (not using the slugs), it all works like charm; able to create a record with the default locale, then navigate to the others one to fill it all
thanks if any tips
Hi, i had same problem and i resolved in this way
- link = I18n.with_locale(:it){page_path(@page, locale: 'it')}
= link_to 'Italiano', link
- link = I18n.with_locale(:en){page_path(@page, locale: 'en')}
= link_to 'English', link
I've a generic answer. please let me know if it works for you.
in your application_helper.rb
if you have a namespace you can set up in :shop, if not just url_for(obj)
def languages(obj=nil)
content_for(:switch_locale) do
I18n.available_locales.each do |locale|
I18n.with_locale(locale) do
concat(
if obj
content_tag(:li, (link_to locale, url_for([:shop, obj]) ))
else
content_tag(:li, (link_to locale, url_for(locale: locale.to_s) ))
end
)
end
end
end
end
in your views
- languages @category
or simply
-languages
in application.html.(erb/haml.slim) or wherever you want to render the translations.
=yield(:switch_locale)
Hi there,
I've been scratching my head for the last few hours, looking for an answer but I can't find it anywhere.
My gem file:
Here's the situation:
So I assume friendly_id and globalize are properly configured.
However my problem is that I can't make a language switcher work using:
The route becomes en/pages/slug-fr (i.e. the language changes but not the slug).
I have activated config.use :finders in the initializer.
My page model:
So what do I need to do to have the proper path on my language switcher? Ideally, I'd like this to work with any models, not just the Page model.
Thanks!