Class: Locallingo::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/locallingo/reporter.rb

Overview

Renders status/violation/quality output for the CLI (text + JSON) and computes strict exit codes. Extracted from the original bin/translate printers so the CLI stays thin.

Constant Summary collapse

SEVERITY_ICONS =
{ error: "šŸ”“", warning: "🟔", info: "šŸ”µ" }.freeze
TYPE_ICONS =
{
  missing: "āŒ", outdated: "šŸ”„", duplicate_value: "šŸ”", manual_edit: "āœļø"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(config:, format: :text, io: $stdout, cli_name: "lingo") ⇒ Reporter

Returns a new instance of Reporter.



15
16
17
18
19
20
# File 'lib/locallingo/reporter.rb', line 15

def initialize(config:, format: :text, io: $stdout, cli_name: "lingo")
  @config = config
  @format = format
  @io = io
  @cli_name = cli_name
end

Instance Method Details

#exit_code(violations, strict:, strict_all:) ⇒ Object

Exit code for a strict tier, per the configured strict_types.



66
67
68
69
70
71
72
# File 'lib/locallingo/reporter.rb', line 66

def exit_code(violations, strict:, strict_all:)
  return 0 unless strict || strict_all

  tier = strict_all ? :strict_all : :strict
  error_types = @config.strict_types(tier)
  violations.any? { |v| error_types.include?(v[:type]) } ? 1 : 0
end

#quality(suggestions, locale:) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/locallingo/reporter.rb', line 51

def quality(suggestions, locale:)
  return json(suggestions) if json?

  if suggestions.empty?
    puts "\nāœ… No quality issues found!"
    return
  end

  puts "\nšŸ“ Translation Quality Suggestions"
  puts "=" * 60
  print_quality_by_severity(suggestions)
  print_quality_summary(suggestions, locale)
end

#status(status) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/locallingo/reporter.rb', line 22

def status(status)
  return json(status) if json?

  puts "\nšŸ“Š Translation Status"
  puts "=" * 60
  status.each { |locale, info| print_locale_status(locale, info) }
  puts ""
end

#violations(violations, strict: false, strict_all: false) ⇒ Object

Prints violations and returns the strict exit code.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/locallingo/reporter.rb', line 32

def violations(violations, strict: false, strict_all: false)
  if json?
    json(violations)
    return exit_code(violations, strict:, strict_all:)
  end

  if violations.empty?
    puts "\nāœ… All translations valid!"
    return 0
  end

  puts "\nāŒ Translation Issues Found"
  puts "=" * 60
  violations.group_by { |v| v[:type] }.each { |type, items| print_violation_group(type, items) }
  puts "\nTotal: #{violations.size} issues"

  exit_code(violations, strict:, strict_all:)
end