Class: I18n::Migrations::MigrationFactory::Translations

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n/migrations/migration_factory.rb

Overview

This is a facade over our translations data = all keys -> all translations in this locale notes = some keys -> notes about the translation in this locale

Instance Method Summary collapse

Constructor Details

#initialize(data:, notes:) ⇒ Translations

Returns a new instance of Translations.



47
48
49
# File 'lib/i18n/migrations/migration_factory.rb', line 47

def initialize(data:, notes:)
  @data, @notes = data, notes
end

Instance Method Details

#delete_term(key) ⇒ Object



64
65
66
67
# File 'lib/i18n/migrations/migration_factory.rb', line 64

def delete_term(key)
  @data.delete(key)
  @notes.delete(key)
end

#get_term(key) ⇒ Object



51
52
53
# File 'lib/i18n/migrations/migration_factory.rb', line 51

def get_term(key)
  @data[key]
end

#move_term(from, to) ⇒ Object



69
70
71
72
# File 'lib/i18n/migrations/migration_factory.rb', line 69

def move_term(from, to)
  @data[to] = @data.delete(from)
  @notes[to] = @notes.delete(from)
end

#set_term(key, value:, notes: nil) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/i18n/migrations/migration_factory.rb', line 55

def set_term(key, value:, notes: nil)
  @data[key] = value
  if notes.present?
    @notes[key] = notes
  else
    @notes.delete(key)
  end
end