Last active
August 29, 2015 14:07
-
-
Save msievers/d11281da3d4a5db9d969 to your computer and use it in GitHub Desktop.
Monkey patch I18n.translate so it recognizes references encoded as ~> some.other.key
This file contains 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/i18n_translate_with_references.rb | |
# | |
module I18n | |
class << self | |
alias_method :original_translate, :translate | |
def translate(*args) | |
regexp = /\A~>(.*)\Z/ # e.g. ~> some.other.key | |
if (original_translation = original_translate(*args))[regexp] | |
referenced_key = original_translation.match(regexp)[1].strip | |
translate(*args.slice(1..-1).unshift(referenced_key)) | |
else | |
original_translation | |
end | |
end | |
end | |
end |
This file contains 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
de: | |
users: | |
watch_lists: | |
join: | |
join_shared_watch_list: ~> users.watch_lists.index.join_shared_watch_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment