module ViewComponent::Translatable

def translate(key = nil, **options)

def translate(key = nil, **options)
  return super unless i18n_backend
  return key.map { |k| translate(k, **options) } if key.is_a?(Array)
  locale = options.delete(:locale) || ::I18n.locale
  scope = options.delete(:scope)
  scope = scope.join(".") if scope.is_a? Array
  key = key&.to_s unless key.is_a?(String)
  key = "#{scope}.#{key}" if scope
  key = "#{i18n_scope}#{key}" if key.start_with?(".")
  if HTML_SAFE_TRANSLATION_KEY.match?(key)
    html_escape_translation_options!(options)
  end
  if key.start_with?(i18n_scope + ".")
    translated =
      catch(:exception) do
        i18n_backend.translate(locale, key, options)
      end
    # Fallback to the global translations
    if translated.is_a? ::I18n::MissingTranslation
      return super(key, locale: locale, **options)
    end
    if HTML_SAFE_TRANSLATION_KEY.match?(key)
      translated = html_safe_translation(translated)
    end
    translated
  else
    super(key, locale: locale, **options)
  end
end