Created
June 3, 2017 03:49
-
-
Save ghiculescu/43ce40145a70beeb6e9bb26fe51ea8a1 to your computer and use it in GitHub Desktop.
Monkey patch ActionView's TranslationHelper to add a custom prefix for keys accessed via lazy lookup (http://guides.rubyonrails.org/i18n.html#looking-up-translations). Use this if you don't want a top level i18n key for each controller in your app - instead all keys sit under a "views" parent (and presumably you'd have other top level keys for o…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/translation_helper.rb | |
module ActionView | |
# = Action View Translation Helpers | |
module Helpers | |
module TranslationHelper | |
private | |
def scope_key_by_partial_with_views_prefix(key) | |
if key.is_a?(String) && key.first == "." | |
key = scope_key_by_partial_without_views_prefix(key) | |
"views.#{key}" | |
else | |
scope_key_by_partial_without_views_prefix(key) | |
end | |
end | |
alias_method_chain :scope_key_by_partial, :views_prefix | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment