-
-
Save dlupu/612f143c9360ebca3b5a13f1e035cd7f 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 | |
translate_with_default_scope(key, conf.site, options) | |
end | |
end | |
private | |
def translate_with_default_scope(key, scope, options = {}) | |
default_lookup = proc { I18n.translate(key, options) } | |
I18n.translate(key, options.merge(scope: scope, default: default_lookup)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment