francesc / rails-translate-routes

MIT License
147 stars 50 forks source link

Can't switch languages anymore #47

Open toadle opened 11 years ago

toadle commented 11 years ago

Hey there guys,

I believe this is something that I'm simply doing wrong: I have an app that uses the following configuration:

ActionDispatch::Routing::Translator.translate_from_file('config/locales/routes.yml', { no_prefixes: true, keep_untranslated_routes: true })

ApplicationController:

  before_filter :set_locale
  before_filter :set_locale_from_url

  def set_locale
    I18n.locale = params[:locale] || ((lang = request.env['HTTP_ACCEPT_LANGUAGE']) && lang[/^[a-z]{2}/])
  end

Now I wanted to have a language-switcher and added this:

    <p>
    <%= link_to_unless I18n.locale == :en, "English", locale: :en %>
    |
    <%= link_to_unless I18n.locale == :de, "Deutsch", locale: :de %>
    </p>

However: The language-switcher will not work. The only thing that currently succesfully switches the language in my app is by willfully accessing a route in the target-language.

What I have already done:

How do I do this correctly with "rails-translate-routes"?

Thx for your help!