Class: Locallingo::Validators::ManualEdits
- Inherits:
-
Object
- Object
- Locallingo::Validators::ManualEdits
- Defined in:
- lib/locallingo/validators/manual_edits.rb
Overview
Detects target values that were hand-edited after Locallingo wrote them.
When enabled, the Manager records a target_hash alongside source_hash
for each translated key. If the current target value's hash differs from
the recorded target_hash (and the key is not already flagged manual),
it was edited by a human — surface it so the operator can protect it with
accept-edits before the next translate run overwrites it.
Instance Method Summary collapse
-
#call(target:, locale_state:, locale:) ⇒ Object
targetis the flat target hash;locale_stateits loaded state. -
#initialize(cli_name: "lingo") ⇒ ManualEdits
constructor
A new instance of ManualEdits.
Constructor Details
#initialize(cli_name: "lingo") ⇒ ManualEdits
Returns a new instance of ManualEdits.
15 16 17 |
# File 'lib/locallingo/validators/manual_edits.rb', line 15 def initialize(cli_name: "lingo") @cli_name = cli_name end |
Instance Method Details
#call(target:, locale_state:, locale:) ⇒ Object
target is the flat target hash; locale_state its loaded state.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/locallingo/validators/manual_edits.rb', line 20 def call(target:, locale_state:, locale:) target.filter_map do |key, value| entry = locale_state[key] next unless entry.is_a?(Hash) next if entry["manual"] stored = entry["target_hash"] next unless stored && stored != StateStore.hash(value) { type: :manual_edit, locale:, key:, suggestion: "Value was hand-edited. Protect it: #{@cli_name} accept-edits --locale #{locale}" } end end |