Skip to content

Instantly share code, notes, and snippets.

@ebeigarts
Created March 22, 2017 12:58
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 ebeigarts/c9872fd6db8a4c1e305dd3fa3c1a26f1 to your computer and use it in GitHub Desktop.
Save ebeigarts/c9872fd6db8a4c1e305dd3fa3c1a26f1 to your computer and use it in GitHub Desktop.
require "i18n"
I18n.backend = I18n::Backend::KeyValue.new({})
I18n.backend.store_translations(:en, { test: "Hello %{value}" }, escape: false)
module I18nSafeTranslations
def translate(*args)
super
rescue I18n::MissingInterpolationArgument => e
# Raven.capture_exception(e) # send to Sentry
""
end
end
I18n.singleton_class.prepend I18nSafeTranslations
puts I18n.translate("test", value: "John")
puts I18n.translate("test", val: "John")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment