upsert.rb 584 B

123456789101112131415161718192021222324
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::Translation::Upsert < Service::Base
  3. attr_reader :locale, :source, :target
  4. def initialize(locale:, source:, target:)
  5. super()
  6. @locale = locale
  7. @source = source
  8. @target = target
  9. end
  10. def execute
  11. translation = Translation.find_source(locale, source)
  12. if translation
  13. translation.update!(target: target)
  14. return translation
  15. end
  16. Translation.create!(locale: locale, source: source, target: target, is_synchronized_from_codebase: false)
  17. end
  18. end