Skip to content

Instantly share code, notes, and snippets.

@msievers
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msievers/d11281da3d4a5db9d969 to your computer and use it in GitHub Desktop.
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
#
# 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
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