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

host_locales doesn't seem to be working #104

Closed
flaviomestre opened this issue Jun 25, 2015 · 5 comments
Closed

host_locales doesn't seem to be working #104

flaviomestre opened this issue Jun 25, 2015 · 5 comments

Comments

@flaviomestre
Copy link

I'm trying to use route_translator with subdomains (en|pt|es.ityou.dev). I can make it work with a subfolder (ityou.dev/pt/) but subdomain won't work. I have the following:

# route_translator.rb
RouteTranslator.config.host_locales = {
    'en.ityou.*'     => :en,
    'pt.ityou.*'     => :pt,
    'es.ityou.*'     => :es
}
# routes.rb
localized do
    root 'static#home'
end

Any domain/subdomain I open always sets the locale to english

# open pt.ityou.dev:3000
Started GET "/" for 127.0.0.1 at 2015-06-25 08:51:43 -0500
Processing by StaticController#home as HTML
  Parameters: {"locale"=>"en"}

Am I missing something?

@tagliala
Copy link
Collaborator

you are probably missing this one: #95

Ok, I'm a collaborator, but I don't know how to solve this :)

Closing here, please share your thoughts in #95. If it is not the same issue feel free to comment here

@flaviomestre
Copy link
Author

Hi @tagliala thanks for commenting.

From what I understanding, #95 is about generating the right routes. In my case, I'm having trouble getting the locale correctly assigned from the subdomain.

Did I understand right?

Did you get the subdomain locale detection to work on your side?

@tagliala
Copy link
Collaborator

I think that the issue I'm having is the same issue as yours, because I don't get the exact locale in the root path, and it is probably the cause of the wrong urls:

when I visit http://it.lvh.me:3000 I can't see the Italian translation, because something is messing up with the :locale param

I'm using a custom solution at the moment. Just skipped host_locales and implemented by myself in an around filter

@flaviomestre
Copy link
Author

Can you share how you solved the locale detection from subdomain? I read the issues you posted but couldn't find any that worked for me.

@tagliala
Copy link
Collaborator

Something like this:

route_translator.rb

RouteTranslator.config do |config|
  config.hide_locale = true
end

development.rb

  # Map domains to languages
  DOMAIN_LANGUAGE = {
    'it.lvh.me' => :it,
    'en.lvh.me' => :en,
    'de.lvh.me' => :de
  }

application_controller.rb

  skip_around_action :set_locale_from_url
  around_action :set_site_locale

  def set_site_locale(&block)
    I18n.with_locale DOMAIN_LANGUAGE[request.host], &block
  end

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

2 participants