Last active
October 6, 2020 07:57
-
-
Save sunny/5e4fb6ef56941086be398dd01d4628de to your computer and use it in GitHub Desktop.
Rails helper so that "?_locale_keys=1" in URL shows locale keys
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
class ApplicationController < ActionController::Base | |
include I18nHelper | |
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
# 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