Skip to content

Instantly share code, notes, and snippets.

@mort
Last active October 19, 2021 10:57
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 mort/54f40b6e9762d60daee416ab8ba63add to your computer and use it in GitHub Desktop.
Save mort/54f40b6e9762d60daee416ab8ba63add to your computer and use it in GitHub Desktop.
// A silly trick for when you need to display several text lines (marketing pages, error pages and such) and it feels cumbersome to have to edit both the locales file and the view for that
// This should be a helper
- begin
// Set a reasonable max value
- (1..9).each do |n|
// raise: true to avoid the default handling for missing keys ("translation missing...") and raise the exception normally
p = I18n.t("your_locale_key_#{n}", raise: true)
- rescue I18n::MissingTranslationData
- break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment