Permalink
Browse files

Rails config for raise on missing translations

Add a config to setup whether raise exception for missing translation or
not.

Conflicts:
	actionview/CHANGELOG.md
  • Loading branch information...
1 parent 29ac566 commit 2d3a3ff176c129882bb1a6a430c5ffeea57c129b @kassio kassio committed with lukaszx0 Jan 26, 2014
View
@@ -1,3 +1,10 @@
+* Added `config.action_view.raise_on_missing_translations` to define whether an
+ error should be raised for missing translations.
+
+ Fixes #13196
+
+ *Kassio Borges*
+
* ActionController::Parameters#require now accepts `false` values.
Fixes #15685.
@@ -149,6 +149,10 @@ class Base
# Specify default_formats that can be rendered.
cattr_accessor :default_formats
+ # Specify whether an error should be raised for missing translations
+ cattr_accessor :raise_on_missing_translations
+ @@raise_on_missing_translations = false
+
class_attribute :_routes
class_attribute :logger
@@ -38,10 +38,10 @@ 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)
- raise_error = options[:raise] || options[:rescue_format]
- else
- raise_error = false
+ options[:raise] ||= ActionView::Base.raise_on_missing_translations
+
+ raise_error = options[:raise] || options.key?(:rescue_format)
+ unless raise_error
options[:raise] = true
end
@@ -53,6 +53,16 @@ def test_returns_missing_translation_message_using_nil_as_rescue_format
assert_equal false, translate(:"translations.missing", :rescue_format => nil).html_safe?
end
+ def test_raises_missing_translation_message_with_raise_config_option
+ ActionView::Base.raise_on_missing_translations = true
+
+ assert_raise(I18n::MissingTranslationData) do
+ translate("translations.missing")
+ end
+ ensure
+ ActionView::Base.raise_on_missing_translations = false
+ end
+
def test_raises_missing_translation_message_with_raise_option
assert_raise(I18n::MissingTranslationData) do
translate(:"translations.missing", :raise => true)
@@ -360,6 +360,8 @@ The schema dumper adds one additional configuration option:
The default setting is `true`, which uses the partial at `/admin/posts/_post.erb`. Setting the value to `false` would render `/posts/_post.erb`, which is the same behavior as rendering from a non-namespaced controller such as `PostsController`.
+* `config.action_view.raise_on_missing_translations` determines whether an error should be raised for missing translations
+
### Configuring Action Mailer
There are a number of settings available on `config.action_mailer`:
@@ -30,4 +30,7 @@
# number of complex assets.
config.assets.debug = true
<%- end -%>
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
end
@@ -33,4 +33,7 @@
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
+
+ # Raises error for missing translations
+ # config.action_view.raise_on_missing_translations = true
end

0 comments on commit 2d3a3ff

Please sign in to comment.