0
      VirtualPS/2 VMware VMMouse
  /   ˆ{‹„„-i[D<†ªoZƒ›Ù«Ã577_‘I|¥‰ÓMdœv ©ƒ†ü+=ÃÂ A    ‹      Õ–AoÚ0Çïýž»‘— Ý&šxêH¥¡Q@”iš¦œØ!‰Ù†Œ}ú+›@l‡uåòâ8ûýÞ?–íðE<îÏ>OîÐûÙýM>¾ú· >uú ñ,n>t=? ¸a„sk«@]×^Ýñ”žÃl
¹-‹.«Ej=f&Wá¦�\¡0ç”¹'
­°'Éø7¤2ji�`¼½o S¥Ã%ËDÁ=ÆKååÆK•ª\¦RÓ2¦Ø«]ºµÆW�æTCÐéuÚ`–‰ëµ¼!«¥õ!¥MD!¬à&„†À1Á*L[oXƒÿÊåÒo¢ÉoÓÔ$´9ZÑBÌe„­ª0	E9GF§‘*i )¨\xs‘aDá/ƒþø«Ó�Í7£IHQ®yá·ýht3ŽbLF´ä!Ðãš{§¹ÅdH�E¥b"œ�?4âñýô„q£‰¹Iµ¨¬PòQ
®ÄÃRSU˜ŠºZ¯]¹>T5vÎšþbÆävz7šÅƒic	ÛLñH÷$“	Õ\ZÍS«ôzWóR&¦ºÙ¿¢]uZÌs‹	B-tTù–,åBªZºâ?êM&.þFÔöÛ¯ZAÐêø(xÝë¾Aè„Ðíž�¯0á«Ï2L²ì,x»å(èöºíç¾àkL\¸@Ïî§âç¾vÞõkÿ¹ —&ÅÄ…D×¼ÀÄ…\0FºãÂºnjG^ÿ{ð?<Åaw¿	a{ë
¡¹!þ ›VÿÊ„
    E   ˆl–Ãa¾”ªi?u8 ¸Û71hß�þC+�¬ã�f1�¡n3üÿÆƒxÅ_�uÐb&=LyZËcõÅÄ i    # Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

module HasTranslations # rubocop:disable Metrics/ModuleLength
  extend ActiveSupport::Concern

  included do
    has_many :translations, class_name: translation_class_name,
                            inverse_of: name.demodulize.underscore,
                            dependent:  :destroy

    validate :validate_translations

    accepts_nested_attributes_for :translations

    # returns objects having a translation in the given KnowledgeBase::Locale.
    # Filters via a subquery (no joins), so it stays composable with .or.
    scope :translated_to, lambda { |kb_locale|
      where(id: translation_class.where(kb_locale: kb_locale).select(reflect_on_association(:translations).foreign_key))
    }

    # Translated to the given *system* locale â€” what `localed` filters by, composable with `.or`.
    #
    # Not `translated_to`'s `id IN (subquery)`: the help site asks this of one row at a time (the
    #   knowledge base, a category lookup, the breadcrumb, the adjacent-answer walk), and PostgreSQL
    #   answers that form by first hashing every translation of the locale â€” about 7 ms for one of
    #   10,000 categories, against 0.1 ms for a probe of the (kb_locale_id, owner id) index. The
    #   locale ids are literal (KnowledgeBase::Locale.translation_preference_ids) so that index
    #   serves the whole probe, and `OFFSET 0` keeps the planner from rewriting the EXISTS back into
    #   the hashed form, which it did on a listing of thirty.
    scope :translated_to_system_locale, lambda { |system_locale_or_id|
      where(translated_to_system_locale_sql(system_locale_or_id))
    }

    # returns objects with single translation according to given locale.
    # If no locale is given, defaults to Knowledge Base's primary locale
    scope :localed, lambda { |system_locale_or_id|
      output = eager_load(:translations).joins(translations: { kb_locale: :knowledge_base })

      if system_locale_or_id.present?
        output.where('knowledge_base_locales.system_locale_id' => system_locale_or_id)
      else
        output.where('knowledge_base_locales.system_locale_id' => -1)
      end
    }

    # Loads each record with the single translation it is *shown* under â€” the given locale's, then
    #   the primary one, then any â€” so `#translation` on it is that one, as it is after `localed`,
    #   which unlike this drops the records not translated to the locale.
    scope :with_preferred_translation, lambda { |system_locale_or_id|
      eager_load(:translations)
        .where("#{translation_class.table_name}.id = (#{preferred_translation_sql(:id, system_locale_or_id)})")
    }
  end

  def translation
    translations.first
  end

  def translation_to(kb_locale_or_id)
    translations.find_by(kb_locale_id: kb_locale_or_id)
  end

  def translation_preferred(kb_locale_or_id)
    translation_to(kb_locale_or_id) || translation_primary || translations.first
  end

  def translation_primary
    translations.joins(:kb_locale).find_by(knowledge_base_locales: { primary: true })
  end

  class_methods do # rubocop:disable Metrics/BlockLength
    def translation_class_name
      "#{name}::Translation"
    end

    def translation_class
      translation_class_name.constantize
    end

    # The check of .t