mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 10:40:48 +08:00
Related: https://meta.discourse.org/t/feature-request-make-it-possible-to-translate-custom-sidebar-links-and-sections/299871 Custom sidebar sections can be translated manually or with AI.
37 lines
1,009 B
Ruby
Vendored
37 lines
1,009 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class SidebarLocalizationBackfill < ::Jobs::Scheduled
|
|
every 1.hour
|
|
cluster_concurrency 1
|
|
|
|
def execute(args)
|
|
return if !DiscourseAi::Translation.backfill_enabled?
|
|
|
|
short_text_llm =
|
|
find_llm_model_for_agent(SiteSetting.ai_translation_short_text_translator_agent)
|
|
|
|
if short_text_llm && !LlmCreditAllocation.credits_available?(short_text_llm)
|
|
Rails.logger.info(
|
|
"Sidebar localization backfill skipped: insufficient credits. Will resume when credits reset.",
|
|
)
|
|
return
|
|
end
|
|
|
|
limit = SiteSetting.ai_translation_backfill_hourly_rate
|
|
|
|
Jobs.enqueue(:localize_sidebar_sections, limit:)
|
|
end
|
|
|
|
private
|
|
|
|
def find_llm_model_for_agent(agent_id)
|
|
return nil if agent_id.blank?
|
|
|
|
agent_klass = AiAgent.find_by_id_from_cache(agent_id)
|
|
return nil if agent_klass.blank?
|
|
|
|
DiscourseAi::Translation::BaseTranslator.preferred_llm_model(agent_klass)
|
|
end
|
|
end
|
|
end
|