Open wafendy opened 7 years ago
which version of Rails?
Rails version Rails 5.1.4
Could you please give a try with 5.1.2?
Ok, I just did, i'm still getting the same behavior.
Just in case if you missed, I did set
RouteTranslator.config { |config| config.hide_locale = true }
at the engine's route so I won't see the language twice in the URL.
By doing this, I'm getting
Routes for App::Engine:
root_de GET / app/pages#landing {:locale=>"de"}
root_en GET / app/pages#landing {:locale=>"en"}
So if I go directly to root path, then it will pick up the first one in the list (I assume).
Sorry, I'm not using this gem with engines, so I don't know what to expect and what the actual behavior is. I thought it could be related to #172, so I've asked your rails version
Also, I don't know how to fix this issue.
Given that we cannot have two paths with two different languages, could you please provide:
?
/cc @rvasquez-flip4new (author of the engine support feature)
I want to use route translator on both the main app and my engine. But i'm getting the following path with my route helpers:
/en/engine/en/index
The language is being displayed twice
What does happen if you remove the localized block inside the engine routes?
If you remove localized block inside the engine routes, then all routes from engine don't have any locale
information and are not translated.
Thanks for the information.
As I mentioned before, I'm not so much into Rails Engines and I don't know how they behave and how route_translator should deal with them.
I would like a summary like this:
routes.rb
# Your routes here
# Your engine routes here
rails routes
Prefix Verb URI Pattern Controller#Action
... ... ...
routes.rb
# Your routes here
route_translator.rb
initialzier# Your initializer here
# Your engine routes here
rails routes
Prefix Verb URI Pattern Controller#Action
... ... ...
rails routes
Prefix Verb URI Pattern Controller#Action
... ... ...
git repo
https://github.com/wafendy/blorgh
routes.yml
en:
routes:
articles: articles
magazines: magazines
id:
routes:
articles: artikel
magazines: majalah
routes.rb
Rails.application.routes.draw do
localized do
resources :articles, only: [:index]
mount Blorgh::Engine => "/blorgh"
end
end
Engine routes
Blorgh::Engine.routes.draw do
resources :magazines, only: [:index]
end
Result of rails routes
Prefix Verb URI Pattern Controller#Action
articles_id GET /id/artikel(.:format) articles#index {:locale=>"id"}
articles_en GET /en/articles(.:format) articles#index {:locale=>"en"}
blorgh_id /id/blorgh Blorgh::Engine {:locale=>"id"}
blorgh_en /en/blorgh Blorgh::Engine {:locale=>"en"}
Routes for Blorgh::Engine:
magazines GET /magazines(.:format) blorgh/magazines#index
Would it be possible to automagically include route translator at Engine level when Rails Engine is mounted inside localized block?
Actual Result:
http://localhost:3000/id/blorgh/magazines
Expected Result:
http://localhost:3000/id/blorgh/majalah
routes.rb
Rails.application.routes.draw do
localized do
resources :articles, only: [:index]
mount Blorgh::Engine => "/blorgh"
end
end
route_translator.rb initialzier
RouteTranslator.config do |config|
config.force_locale = true
end
Engine routes
Blorgh::Engine.routes.draw do
localized do
resources :magazines, only: [:index]
end
end
Result of rails routes
Prefix Verb URI Pattern Controller#Action
articles_id GET /id/artikel(.:format) articles#index {:locale=>"id"}
articles_en GET /en/articles(.:format) articles#index {:locale=>"en"}
blorgh_id /id/blorgh Blorgh::Engine {:locale=>"id"}
blorgh_en /en/blorgh Blorgh::Engine {:locale=>"en"}
Routes for Blorgh::Engine:
magazines_id GET /id/majalah(.:format) blorgh/magazines#index {:locale=>"id"}
magazines_en GET /en/magazines(.:format) blorgh/magazines#index {:locale=>"en"}
So, as far as I understand, if you use route_translator inside your engine and your engine is itself inside a localized block, then:
Prefix Verb URI Pattern Controller#Action
articles_id GET /id/artikel(.:format) articles#index {:locale=>"id"}
articles_en GET /en/articles(.:format) articles#index {:locale=>"en"}
blorgh_id /id/blorgh Blorgh::Engine {:locale=>"id"}
blorgh_en /en/blorgh Blorgh::Engine {:locale=>"en"}
Routes for Blorgh::Engine:
magazines_id GET /id/majalah(.:format) blorgh/magazines#index {:locale=>"id"}
magazines_en GET /en/magazines(.:format) blorgh/magazines#index {:locale=>"en"}
Prefix Verb URI Pattern Controller#Action
articles_id GET /id/artikel(.:format) articles#index {:locale=>"id"}
articles_en GET /en/articles(.:format) articles#index {:locale=>"en"}
blorgh_id /id/blorgh Blorgh::Engine {:locale=>"id"}
blorgh_en /en/blorgh Blorgh::Engine {:locale=>"en"}
Routes for Blorgh::Engine:
magazines_id GET /majalah(.:format) blorgh/magazines#index {:locale=>"id"}
magazines_en GET /magazines(.:format) blorgh/magazines#index {:locale=>"en"}
Am I right?
Yup, that's correct.
Hi,
I'm using
route_translator
v5.5.0 gem and running the following issue. I hope someone can clarify why it's behaving this way.Since I set my default_locale, I would expect it returns
en
, but it returnsde
as locale instead. Any idea how to do proper spec in this scenario?