-
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
disable_fallback not working when I18n.fallbacks is configured #241
Comments
Hi, apologies for the late reply I think that the expected behavior is correct, or I'm getting this report wrong route_translator generates routes for all the available locales. If the application is available in |
@tagliala Well I haven't been much quicker to reply either 😬 If that's the intended behavior on your end then it's not a bug, but maybe it would be nice to have this behavior clearly explained in the README, if you have the time. An amazing feature would be to allow skipping routes that don't have a translated path available for a given locale, to allow supporting (possibly minor) use-cases like this one. In any case, thanks for your reply! |
Hi @dvkch I read this again and I think it is an issue. Will investigate further |
enriclluelles/route_translator#241 Signed-off-by: Geremia Taglialatela <[email protected]>
Hi, I think I've found the issue but I'm not confident to do the changes because I'm not using We have two points to discuss 1. Raise on translation error
The above lines should raise an error, so This new behavior may be considered a breaking change, so I should at least bump up the major version number but I'm afraid of side effects 2. Fallback behaviourRails may itself fallback on the default translation, so we should decide if it is correct to do that or give priority to RouteTranslator's setting. I would set fallback to false if
Also: why is With the following diff, all route translator tests are green and your use case is fixed diff --git a/lib/route_translator/translator/path/segment.rb b/lib/route_translator/translator/path/segment.rb
index c9b5df5..9bb6f68 100644
--- a/lib/route_translator/translator/path/segment.rb
+++ b/lib/route_translator/translator/path/segment.rb
@@ -9,7 +9,7 @@ module RouteTranslator
def fallback_options(str, locale)
if RouteTranslator.config.disable_fallback && locale.to_s != I18n.default_locale.to_s
- { scope: :routes, fallback: true }
+ { scope: :routes, fallback: false }
else
{ scope: :routes, default: str }
end
@@ -25,7 +25,7 @@ module RouteTranslator
opts = { locale: locale, scope: scope }
if I18n.t(str, **opts.merge(exception_handler: handler)).is_a?(I18n::MissingTranslation)
- I18n.t str, **opts.merge(fallback_options(str, locale))
+ I18n.t! str, **opts.merge(fallback_options(str, locale))
else
I18n.t str, **opts
end but I should at least add a failing spec for this use case |
1. Do not enable fallback if disable_fallback option is enabled 2. Raise if the translation is not found, so that `translate_path` may rescue from it Close #241
@tagliala That seams perfect! I don't see any issue either in your decision making or the code itself. Unfortunately I am no longer working on the impacted project and no longer have access to it to run tests. If you wish I can rebuild a similar project myself to test that case, but I think adding the test case in Route Translator suite should be enough to validate this reasoning and prevent regressions |
1. Do not enable fallback if disable_fallback option is enabled 2. Raise if the translation is not found, so that `translate_path` may rescue from it Close #241
I've provided a failing test case and released version 12.0.0 because this is a potential breaking change Thanks for the report |
Amazing, thank you! |
Steps to reproduce*
Create an app with the given configuration and run
rails routes
Expected behavior*
We should generate the following routes :
Actual behavior*
newsletter_subscription_it
is defined as well, with theen
translation of the route.If I comment
config.i18n.fallbacks = ...
then the route gets created too but with the following path/it/translation%20missing:%20it.routes.newsletter_subscription
.System configuration*
Rails version: Rails 6.0.3.4
Ruby version: Ruby 2.6.6
Route Translator version: 10.0.0
I18n configuration*
Route Translator initializier
Source of:
config/initializers/route_translator.rb
Source code of routes.rb*
Source of:
config/routes.rb
Locale
.yml
files*routes.en.yml
routes.it.yml
The text was updated successfully, but these errors were encountered: