Class: Jekyll::L10n::DebugLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-l10n/utils/debug_logger.rb

Overview

Logs detailed translation debug information.

DebugLogger provides detailed logging of translation attempts for debugging normalization and matching issues. It logs when translations are found, when translations are missing, character-level differences, and similarity analysis for debugging.

Key responsibilities:

  • Log translation match details

  • Log missing translations with similar key analysis

  • Log character-level differences for debugging

  • Provide context around matching failures

  • Support verbose translation debugging

Defined Under Namespace

Classes: TranslationData

Class Method Summary collapse

Class Method Details

.log_alert_details(text, normalized_text, translations) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/jekyll-l10n/utils/debug_logger.rb', line 62

def self.log_alert_details(text, normalized_text, translations)
  return unless text.include?('Alert component is an inline message box')

  matching_keys = translations.keys.select { |key| key.include?('Alert component is') }
  return unless matching_keys.any?

  key_from_hash = matching_keys[0]
  log_alert_comparison(text, normalized_text, key_from_hash)
end

.log_first_difference(normalized_text, key_from_hash) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/jekyll-l10n/utils/debug_logger.rb', line 72

def self.log_first_difference(normalized_text, key_from_hash)
  (0...normalized_text.length).each do |i|
    next unless normalized_text[i] != key_from_hash[i]

    log_difference_at_position(normalized_text, key_from_hash, i)
    log_context_strings(normalized_text, key_from_hash, i)
    break
  end

  log_normalization_match
end

.log_found_translation(text, translated) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/jekyll-l10n/utils/debug_logger.rb', line 84

def self.log_found_translation(text, translated)
  return unless translated && translated.length > Jekyll::L10n::Constants::LOG_THRESHOLD_SHORT

  truncate_length = Jekyll::L10n::Constants::LOG_TRUNCATE_LONG
  log_message(
    "[HtmlTranslator] ✓ TRANSLATION FOUND: #{text[0..truncate_length]}... => " \
    "#{translated[0..truncate_length]}..."
  )
end

.log_missing_translation(text, normalized_text, translations) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/jekyll-l10n/utils/debug_logger.rb', line 50

def self.log_missing_translation(text, normalized_text, translations)
  return unless translations[normalized_text].nil?
  return unless text.length > Jekyll::L10n::Constants::LOG_THRESHOLD_SHORT

  similar_keys = translations.keys.select do |key|
    key.start_with?(text[0..Jekyll::L10n::Constants::LOG_TRUNCATE_SHORT])
  end
  return unless similar_keys.any?

  log_no_translation_found(text, normalized_text, similar_keys)
end

.log_translation_details(translator, translation_data) ⇒ void

This method returns an undefined value.

Log detailed translation information.

Logs the text being translated, how it was normalized, whether a translation was found, and provides debugging information if no translation matched. Only logs if translator has debug_logging enabled.

Parameters:



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/jekyll-l10n/utils/debug_logger.rb', line 37

def self.log_translation_details(translator, translation_data)
  return unless translator.debug_logging

  threshold = Jekyll::L10n::Constants::LOG_THRESHOLD_SHORT
  return if translation_data.translated.nil? && translation_data.text.length <= threshold

  log_missing_translation(translation_data.text, translation_data.normalized_text,
                          translation_data.translations)
  log_alert_details(translation_data.text, translation_data.normalized_text,
                    translation_data.translations)
  log_found_translation(translation_data.text, translation_data.translated)
end