I am currently dealing with I18n and am facing a problem.
The locale.rb:
I18n.load_path += Dir[Rails.root.join('config', 'locale', '*.{rb,yml}')]
I18n.available_locales = [:de, :en, :es]
I18n.default_locale = :en
For changing the locale i have a little partial which works fine:
<% I18n.available_locales.each do |lang| %>
<a href="<%= url_for(:locale => lang)%>" class=" text-gray-300 e">
<%= lang %>
</a>
<% end %>
In my routes i have the following:
...
root to: redirect("/#{I18n.default_locale}"), as: :redirected_root
scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do
root "home#index"
... more code
Here is a Screenshot:
The redirect to the current locale also works fine. When i load my page, the locale will set to :de When i click on another language, the locale will change successfully.
Now to the problems:
When i click on checklists
the locale will removed and the URL changes to http://localhost:3000/checklists
.
When clicking another locale for more than one time the URL change to http://localhost:3000/de/es/checklisten
, it has two locales.
Why is that so?
I couldn’t find a solution via google.
Does anyone has an idea for fixing that issue?
Thanks,
Piet