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

Translate routes #38

Closed
vyper opened this issue Apr 4, 2015 · 7 comments
Closed

Translate routes #38

vyper opened this issue Apr 4, 2015 · 7 comments

Comments

@vyper
Copy link
Member

vyper commented Apr 4, 2015

Manually?

# in english
resources :events, only: :show

# in portuguese
resources :eventos, only: :show, controller: :events

Output...

event  GET    /events/:id(.:format)                    events#show
evento GET    /eventos/:id(.:format)                   events#show

Or use gem?

@vyper vyper mentioned this issue Apr 4, 2015
4 tasks
@diegopolido
Copy link

@vyper
Copy link
Member Author

vyper commented Apr 10, 2015

The route_translator worked... I saw others, but I don't found better option.

config/router.rb

# from
resources :events, only: :show

# to
localized do
  resources :events, only: :show
end

rake routes

           event_en GET    /en/events/:id(.:format)                 events#show {:locale=>"en"}
        event_pt_br GET    /eventos/:id(.:format)                   events#show {:locale=>"pt-BR"}

But the routes events/:name don't work after the gem applied, we'll have to change all routes in oldest posts. I think it's... justo!

@vyper
Copy link
Member Author

vyper commented Apr 10, 2015

But... I remembered... exists posts using /events/:name! We can't change this routes, we need to keep the routes. ):

@lcguida
Copy link
Contributor

lcguida commented Apr 23, 2015

Why localize the routes? I18n let's you put the localization in the url:

# config/routes.rb
scope "/:locale" do
  resources :events
end

This way it's possible to access the localized page by: <url>/pt-br/events

@vyper
Copy link
Member Author

vyper commented Apr 23, 2015

@lcguida improvement for a better seo...

@vyper vyper mentioned this issue Apr 25, 2015
@tiagolupepic
Copy link
Member

Maybe use an initializer to hide locales

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

@tiagolupepic
Copy link
Member

And.. to fix routes in tests.

RouteTranslator.config do |config|
  config.hide_locale = true
  config.generate_unlocalized_routes = true if Rails.env.test?
end

@vyper vyper closed this as completed in 913f942 Apr 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants