Skip to content

Commit

Permalink
ruby 3 / rails 7 compability
Browse files Browse the repository at this point in the history
  • Loading branch information
JensRavens committed Dec 28, 2021
1 parent 6709131 commit 9e3467d
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions lib/shimmer/utils/localizable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,30 @@ def check_locale
def url_locale
params[:locale]
end
end
end
end

module I18n
UNTRANSLATED_SCOPES = ["number", "transliterate", "date", "datetime", "errors", "helpers", "support", "time", "faker"].map { |k| "#{k}." }

thread_mattr_accessor :debug

class << self
alias_method :old_translate, :translate
def translate(key, options = {})
key = key.to_s.downcase
untranslated = UNTRANSLATED_SCOPES.any? { |e| key.include? e }
key_name = [options[:scope], key].flatten.compact.join(".")
option_names = options.except(:count, :default, :raise, :scope).map { |k, v| "#{k}=#{v}" }.join(", ")
return "#{key_name} #{option_names}" if I18n.debug && !untranslated

options.reverse_merge!(default: old_translate(key, **options.merge(locale: :de))) if untranslated
old_translate(key, **options)
end
alias_method :t, :translate

def debug?
debug
I18n.class_eval do
thread_mattr_accessor :debug

class << self
alias_method :old_translate, :translate
def translate(key, options = {})
untranslated_scopes = ["number", "transliterate", "date", "datetime", "errors", "helpers", "support", "time", "faker"].map { |k| "#{k}." }
key = key.to_s.downcase
untranslated = untranslated_scopes.any? { |e| key.include? e }
key_name = [options[:scope], key].flatten.compact.join(".")
option_names = options.except(:count, :default, :raise, :scope).map { |k, v| "#{k}=#{v}" }.join(", ")
return "#{key_name} #{option_names}" if I18n.debug && !untranslated

options.reverse_merge!(default: old_translate(key, **options.merge(locale: :de))) if untranslated
old_translate(key, **options)
end
alias_method :t, :translate

def debug?
debug
end
end
end
end
end
end

0 comments on commit 9e3467d

Please sign in to comment.