Skip to content

Instantly share code, notes, and snippets.

@sunny
Last active October 6, 2020 07:57
Show Gist options
  • Save sunny/5e4fb6ef56941086be398dd01d4628de to your computer and use it in GitHub Desktop.
Save sunny/5e4fb6ef56941086be398dd01d4628de to your computer and use it in GitHub Desktop.
Rails helper so that "?_locale_keys=1" in URL shows locale keys
class ApplicationController < ActionController::Base
include I18nHelper
end
# frozen_string_literal: true
module I18nHelper
# Print out the keys if you add ?_locale_keys=1 in params
def t(key, options = {})
key = scope_key_by_partial(key) if respond_to?(:scope_key_by_partial)
# Make sure params isn't triggered in Mailers by looking for request
if (respond_to?(:request) && request && params[:_locale_keys]) || \
(@mail_params && @mail_params[:_locale_keys])
if options.any?
"#{key} (#{options.map { |k, v| "#{k}: #{v.inspect}" }.join(',')})"
else
key
end
else
I18n.translate(key, options)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment