Class: Locallingo::Validators::Outdated
- Inherits:
-
Object
- Object
- Locallingo::Validators::Outdated
- Defined in:
- lib/locallingo/validators/outdated.rb
Overview
Reports target keys whose recorded source hash no longer matches the current source value — i.e. the English text changed after translation.
Instance Method Summary collapse
-
#call(source:, locale_state:, locale:) ⇒ Object
sourceis the flat source hash;locale_stateis the target locale's loaded state (key => { "source_hash" => ... }). -
#initialize(cli_name: "lingo") ⇒ Outdated
constructor
A new instance of Outdated.
-
#outdated_keys(source, locale_state) ⇒ Object
Keys whose stored source_hash differs from the current source hash.
Constructor Details
#initialize(cli_name: "lingo") ⇒ Outdated
Returns a new instance of Outdated.
10 11 12 |
# File 'lib/locallingo/validators/outdated.rb', line 10 def initialize(cli_name: "lingo") @cli_name = cli_name end |
Instance Method Details
#call(source:, locale_state:, locale:) ⇒ Object
source is the flat source hash; locale_state is the target locale's
loaded state (key => { "source_hash" => ... }).
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/locallingo/validators/outdated.rb', line 16 def call(source:, locale_state:, locale:) outdated_keys(source, locale_state).map do |key| { type: :outdated, locale:, key:, suggestion: "Source changed. Run: #{@cli_name} translate --locale #{locale} --force-key #{key}" } end end |
#outdated_keys(source, locale_state) ⇒ Object
Keys whose stored source_hash differs from the current source hash.
28 29 30 31 32 33 |
# File 'lib/locallingo/validators/outdated.rb', line 28 def outdated_keys(source, locale_state) source.filter_map do |key, value| stored = locale_state.dig(key, "source_hash") key if stored && stored != StateStore.hash(value) end end |