A platform for community discussion. Free, open, simple.
UX: remove total and update backfill message for AI translations (#35479)
Krise2c701a849d8
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 3ecc3de0452..103f389cf63 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@@ -41,6 +41,7 @@ module DiscourseAibackfill_enabled: DiscourseAi::Translation.backfill_enabled?,translation_enabled: SiteSetting.ai_translation_enabled,hourly_rate: SiteSetting.ai_translation_backfill_hourly_rate,+ backfill_max_age_days: SiteSetting.ai_translation_backfill_max_age_days,}endenddiff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-translations.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-translations.gjsindex 7d46218653e..ed8062412ab 100644--- a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-translations.gjs+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-translations.gjs@@ -4,6 +4,7 @@ import { hash } from "@ember/helper";import { on } from "@ember/modifier";import { action } from "@ember/object";import { service } from "@ember/service";+import { htmlSafe } from "@ember/template";import DButton from "discourse/components/d-button";import DPageSubheader from "discourse/components/d-page-subheader";import DToggleSwitch from "discourse/components/d-toggle-switch";@@ -213,36 +214,64 @@ 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;- }+ get backfillStatusMessage() {+ if (+ this.args.model?.backfill_enabled &&+ this.args.model?.backfill_max_age_days &&+ this.hourlyRate > 0+ ) {+ const totalRemaining = this.data?.reduce(+ (sum, { total, done }) => sum + (total - done),+ 0+ );- const totalRemaining = this.data?.reduce(- (sum, { total, done }) => sum + (total - done),- 0- );+ if (totalRemaining && totalRemaining > 0) {+ const hoursRemaining = totalRemaining / this.hourlyRate;- if (!totalRemaining || totalRemaining === 0) {- return null;- }+ const cutoffDate = new Date();+ cutoffDate.setDate(+ cutoffDate.getDate() - this.args.model.backfill_max_age_days+ );- const hoursRemaining = totalRemaining / this.hourlyRate;+ const formattedDate = cutoffDate.toLocaleDateString(undefined, {+ year: "numeric",+ month: "long",+ day: "numeric",+ });- 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 });+ let timeKey;+ if (hoursRemaining < 1) {+ const minutes = Math.ceil(hoursRemaining * 60);+ timeKey = i18n("discourse_ai.translations.stats.eta_minutes", {+ count: minutes,+ });+ } else if (hoursRemaining < 24) {+ const hours = Math.ceil(hoursRemaining);+ timeKey = i18n("discourse_ai.translations.stats.eta_hours", {+ count: hours,+ });+ } else {+ const days = Math.ceil(hoursRemaining / 24);+ timeKey = i18n("discourse_ai.translations.stats.eta_days", {+ count: days,+ });+ }++ return htmlSafe(+ i18n("discourse_ai.translations.stats.backfill_message", {+ date: formattedDate,+ eta: timeKey,+ settingsUrl: this.settingsUrl,+ })+ );+ }+ }++ if (!this.args.model?.backfill_enabled) {+ return i18n("discourse_ai.translations.stats.backfill_disabled");}++ return null;}get chartColors() {@@ -472,18 +501,13 @@ export default class AiTranslations extends Component {</:header><:content><div class="ai-translations__stats-container">- <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}}- </span>- </div>+ {{#if this.backfillStatusMessage}}+ <div class="ai-translations__stat-item">+ <span class="ai-translations__stat-label">+ {{this.backfillStatusMessage}}+ </span>+ </div>+ {{/if}}</div><div class="ai-translations__chart-container"><Chartdiff --git a/plugins/discourse-ai/config/locales/client.en.yml b/plugins/discourse-ai/config/locales/client.en.ymlindex 582b33e5e95..4cbfa80de07 100644--- a/plugins/discourse-ai/config/locales/client.en.yml+++ b/plugins/discourse-ai/config/locales/client.en.yml@@ -341,10 +341,7 @@ en:complete_language_detection_description: "All %{total} eligible posts have their language detected."incomplete_language_detection_description: "%{done} of %{total} eligible posts have their language detected."backfill_disabled: "Backfilling is disabled, only new posts will be translated."- description_tooltip:- one: 'There is %{count} post ready to translate.'- other: 'There are %{count} posts ready to translate.'- eta_label: "Estimated completion time"+ backfill_message: "<a href='%{settingsUrl}'>Backfill settings</a> are configured to translate all posts after %{date} — this is estimated to take %{eta}."eta_minutes:one: "%{count} minute"other: "%{count} minutes"