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
Rails config for raise on missing translations #13832
Rails config for raise on missing translations #13832
Conversation
@@ -153,6 +153,10 @@ class Base | |||
# Specify default_formats that can be rendered. | |||
cattr_accessor :default_formats | |||
|
|||
# Specify whether raise error for missing translations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about something like:
Specify whether an error should be raised for missing translations
Hello @kassio, thanks for your contribution. This looks like a quite tiny patch that could be pretty useful! However, I'm not a merger so let's wait for some feedback before addressing the comments. Also, what do you think about changing the changelog entry to something like:
|
@robin850 thank's for the comments, I did the changes. |
@@ -38,7 +38,8 @@ def translate(key, options = {}) | |||
|
|||
# If the user has specified rescue_format then pass it all through, otherwise use | |||
# raise and do the work ourselves | |||
if options.key?(:raise) || options.key?(:rescue_format) | |||
options[:raise] ||= ActionView::Base.raise_on_missing_translations | |||
if options[:raise] || options.key?(:rescue_format) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this logic can be improved to something like:
options[:raise] ||= ActionView::Base.raise_on_missing_translations
if options.key?(:rescue_format)
raise_error = options[:rescue_format]
else
raise_error = options[:raise]
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT:
options[:raise] ||= ActionView::Base.raise_on_missing_translations
raise_error = options[:raise] || options.key?(:rescue_format)
unless raise_error
options[:raise] = true
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems good
Add a config to setup whether raise exception for missing translation or not.
…tions Rails config for raise on missing translations
Thanks @kassio! Can we back port this to 4.0.x and 3.2.x since it was a regression? |
I consider this is a new feature so I'd not backport. But if we would backport we would only do to 4.0 |
In which version of Rails is this commit merged? In Rails 4.0.2 I have the error:
|
@fguillen it's been merged to master only. |
What about disregarding missing translations for default language? #13429 |
Sorry @firedev but I don't know what you mean :/ |
Well, it is all described in the ticket, since rails 4.0.2 there seem to be no way to work around missing translations. |
@firedev I'm using your workaround:
I know you can't intercept the exception but at least I have an exception :) |
I just want |
I see. Looks like you are trying hard: http://stackoverflow.com/questions/12558716/disable-translation-missing-for-english-only-in-rails luck with this! |
And by the way I tried to add
To |
I'm not completely sure what is going on, but I too have issues with a custom exception handler for I18n. We are using an exception handler that stores missing translations in a separate file. Before Rails 4.1, we needed to override the Rails helper to always use Unfortunately, our previous setup only works when supplying the Before Rails 4.1: After upgrading to 4.1: |
Just to reiterate, before 4.0.2 was out I intercepted missing translations for english and I didn't have to bother about |
Sorry, I am just a bit frustrated. Don't see Also I have tried different error handlers with |
I've created #17676 that fixes this regression. @edwinv note that |
Previously, when the `:raise` options was set to `false`, it would get overwritten to `true`, preventing custom exception handlers to be used.
…ler_regression Fix I18n regression introduced by #13832
…ler_regression Fix I18n regression introduced by #13832
…ler_regression Fix I18n regression introduced by #13832
Add a config to setup whether raise exception for missing translation or
not.
Fixes #13196