Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't switch languages anymore #47

Open
toadle opened this issue Oct 22, 2013 · 0 comments
Open

Can't switch languages anymore #47

toadle opened this issue Oct 22, 2013 · 0 comments

Comments

@toadle
Copy link

toadle commented Oct 22, 2013

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:

  • Checking params[:locale] - it always hold the path's locale, even if ?locale= is given.
  • Removing before_filter :set_locale_from_url. Doesn't help.

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

Thx for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant