-
Notifications
You must be signed in to change notification settings - Fork 143
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
Use of an *optional* locale scope leads to missing locale in URLs #208
Comments
Hi! Thanks for being part of the Route Translator Community I didn't get the use case, could you please clarify what you are trying to achieve? |
The goal is to use this gem, but together with an optional "locale scope" like in the 1st example. But when I do this, Rails will generate links that don't contain the locale any longer, i.e. With this gem, it seems I can only use a mandatory "locale scope" like in the 2nd example, in order to have Rails generate links that do contain the locale correctly, i.e.: |
Sorry, could you please provide an example of the routes that you want to generate? |
In this first case below (without this gem), Rails will show
But in this second case below (with this gem), Rails will show
(And I would like to have all URLs like the first example, like |
(And I would like to have all URLs like the first example, like /en/books, but WITH this gem.) Thanks for the many clarifications 🙏 You are looking for the Let me know if that helps |
Unfortunately, when I follow your instruction while keeping the above mentioned routes configuration...
... then the command
... where the correct format would be:
|
Hi @john-999 , please do not use the |
Ok, so if I understand correctly, then the format (note the parenthesis around
... is not possible with this gem. If this is correct, would you consider it worth implementing this option? |
Thanks for your patience, I need to understand the use case and why this feature is needed. What you are trying to achieve? What you achieve instead? Look in example at this issue: #205 You can see expected behavior and wanted behavior, I have to understand that
If you want all localized routes have its own locale, including the default one, then the option to use is Example: Rails.application.routes.draw do
localized do
resources :products, only: %i[index show]
end
end Output:
If you want # config/initializers/route_translator.rb
RouteTranslator.config do |config|
config.force_locale = true
end Output:
|
The idea would be to have routes where the Route 1 == Route 2 (identical routes):
Route 3 == Route 4 (identical routes):
I was expecting to achieve this result by the following (but as stated above, it does not seem to work that way):
(But maybe this behavior is too much of an edge/perfectionist case...) |
@john-999 ok, I've got it :) You are looking for
Hope it helps Closing here |
No, sorry, you want both |
Does # config/initializers/route_translator.rb
RouteTranslator.config do |config|
config.hide_locale = true
end # config/routes.rb
Rails.application.routes.draw do
localized do
resources :products, only: %i[index show new]
end
scope(':locale') do
localized do
resources :products, only: %i[index show new]
end
end
end
work for your use case? In any case, this is something that I would not like to officially support |
Yes, thank you for your help - that result was indeed the idea. But I do of course understand if this goes beyond the idea of this gem. |
When I use an optional locale scope - meaning with parenthesis like below - with this gem, then all URLs resulting from routes instructions inside "localized do" will not include the locale any longer:
...will not result in
/en/books
but only in/books
.The locale is included correctly in the URL only if the local scope is not optional (not in parenthesis):
This means a deviation from Rails' default behavior.
The text was updated successfully, but these errors were encountered: