A platform for community discussion. Free, open, simple.
FEATURE: Add estimated completion time to AI translation backfill (#35474)
Rafael dos Santos Silva6b7a08664438
diff --git a/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_translations_controller.rb b/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_translations_controller.rbindex f637a9dec25..3ecc3de0452 100644--- a/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_translations_controller.rb+++ b/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_translations_controller.rb@@ -40,6 +40,7 @@ module DiscourseAiSiteSetting.ai_translation_backfill_max_age_days > 0,backfill_enabled: DiscourseAi::Translation.backfill_enabled?,translation_enabled: SiteSetting.ai_translation_enabled,+ hourly_rate: SiteSetting.ai_translation_backfill_hourly_rate,}endenddiff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-translations.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-translations.gjsindex fe07cbe5da0..7d46218653e 100644--- a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-translations.gjs+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-translations.gjs@@ -38,6 +38,7 @@ export default class AiTranslations extends Component {: [];@tracked isSavingLocales = false;@tracked isTogglingTranslation = false;+ @tracked hourlyRate = this.args.model?.hourly_rate || 0;get localesChanged() {const current = [...this.selectedLocales].sort().join("|");@@ -180,6 +181,7 @@ export default class AiTranslations extends Component {this.total = response.total;this.done = response.posts_with_detected_locale;this.enabled = response.enabled;+ this.hourlyRate = response.hourly_rate || 0;}} else {this.enabled = false;@@ -211,6 +213,38 @@ export default class AiTranslations extends Component {: "discourse_ai.translations.stats.incomplete_language_detection_description";}+ get estimatedCompletionTime() {+ if (!this.args.model?.backfill_enabled || this.hourlyRate === 0) {+ return null;+ }++ const totalRemaining = this.data?.reduce(+ (sum, { total, done }) => sum + (total - done),+ 0+ );++ if (!totalRemaining || totalRemaining === 0) {+ return null;+ }++ const hoursRemaining = totalRemaining / this.hourlyRate;++ if (hoursRemaining < 1) {+ const minutes = Math.ceil(hoursRemaining * 60);+ return i18n("discourse_ai.translations.stats.eta_minutes", {+ count: minutes,+ });+ } else if (hoursRemaining < 24) {+ const hours = Math.ceil(hoursRemaining);+ return i18n("discourse_ai.translations.stats.eta_hours", {+ count: hours,+ });+ } else {+ const days = Math.ceil(hoursRemaining / 24);+ return i18n("discourse_ai.translations.stats.eta_days", { count: days });+ }+ }+get chartColors() {const styles = getComputedStyle(document.querySelector(".ai-translations"));return {@@ -441,6 +475,10 @@ export default class AiTranslations extends Component {<div class="ai-translations__stat-item"><span class="ai-translations__stat-label">{{this.descriptionTooltip}}+ {{#if this.estimatedCompletionTime}}+ ({{i18n "discourse_ai.translations.stats.eta_label"}}:+ {{this.estimatedCompletionTime}})+ {{/if}}{{#unless @model.backfill_enabled}}{{i18n "discourse_ai.translations.stats.backfill_disabled"}}{{/unless}}diff --git a/plugins/discourse-ai/config/locales/client.en.yml b/plugins/discourse-ai/config/locales/client.en.ymlindex 8297ac3fa44..582b33e5e95 100644--- a/plugins/discourse-ai/config/locales/client.en.yml+++ b/plugins/discourse-ai/config/locales/client.en.yml@@ -344,6 +344,16 @@ en:description_tooltip:one: 'There is %{count} post ready to translate.'other: 'There are %{count} posts ready to translate.'+ eta_label: "Estimated completion time"+ eta_minutes:+ one: "%{count} minute"+ other: "%{count} minutes"+ eta_hours:+ one: "%{count} hour"+ other: "%{count} hours"+ eta_days:+ one: "%{count} day"+ other: "%{count} days"progress_chart:title: "Translation Progress"data_label: "%{percentage}%"diff --git a/plugins/discourse-ai/spec/requests/admin/ai_translations_controller_spec.rb b/plugins/discourse-ai/spec/requests/admin/ai_translations_controller_spec.rbindex f8750714dd3..7331fc6390a 100644--- a/plugins/discourse-ai/spec/requests/admin/ai_translations_controller_spec.rb+++ b/plugins/discourse-ai/spec/requests/admin/ai_translations_controller_spec.rb@@ -21,6 +21,7 @@ describe DiscourseAi::Admin::AiTranslationsController doit "returns translation progress data" doSiteSetting.ai_translation_backfill_max_age_days = 30SiteSetting.ai_translation_backfill_limit_to_public_content = false+ SiteSetting.ai_translation_backfill_hourly_rate = 100english_posts = Fabricate.times(14, :post, locale: "en")french_post = Fabricate(:post, locale: "fr")@@ -46,6 +47,7 @@ describe DiscourseAi::Admin::AiTranslationsController doexpect(json["enabled"]).to be_in([true, false])expect(json["total"]).to eq(19)expect(json["posts_with_detected_locale"]).to eq(15)+ expect(json["hourly_rate"]).to eq(100)# Check structure of first locale datalocale_data = json["translation_progress"].first