fix(translate): deduplicate bulk replace buttons with distinct labels
- Rename page-level button to 'Массовая замена по всем запускам' (bulk_replace_all key in i18n) to distinguish from run-level button - Remove duplicate Bulk Replace button from records table header in TranslationRunResult (kept only in result header) - Fix i18n path for bulk_replace_all (was incorrectly in run namespace)
This commit is contained in:
@@ -94,13 +94,22 @@ class BatchProcessingService:
|
||||
return {**result, "batch_id": bid}
|
||||
# #endregion process_batch
|
||||
|
||||
# #region _create_batch [C:2] [TYPE Function] [SEMANTICS translate,batch,create]
|
||||
# @ingroup Translate
|
||||
# @BRIEF Create a TranslationBatch DB record and flush to get its ID.
|
||||
def _create_batch(self, run_id, batch_index, batch_rows):
|
||||
b = TranslationBatch(id=str(uuid.uuid4()), run_id=run_id, batch_index=batch_index,
|
||||
status="RUNNING", total_records=len(batch_rows), started_at=datetime.now(UTC))
|
||||
self.db.add(b)
|
||||
self.db.flush()
|
||||
return b
|
||||
# #endregion _create_batch
|
||||
|
||||
# #region _check_cache [C:3] [TYPE Function] [SEMANTICS translate,cache,hash,lookup]
|
||||
# @ingroup Translate
|
||||
# @BRIEF Check translation cache for each batch row, attach _cached_lang_values.
|
||||
# @POST Rows with cache hits have _cached_lang_values dict set.
|
||||
# @SIDE_EFFECT Modifies batch_rows in-place. Emits aggregated log.
|
||||
def _check_cache(self, job, batch_rows, dict_snapshot_hash, config_hash):
|
||||
cache_hits = 0
|
||||
for row in batch_rows:
|
||||
@@ -121,8 +130,11 @@ class BatchProcessingService:
|
||||
"Translation cache hits",
|
||||
{"batch_rows": len(batch_rows), "cache_hits": cache_hits},
|
||||
)
|
||||
# #endregion _check_cache
|
||||
|
||||
# ★ Local language detection — replaces LLM-based detection
|
||||
# #region _detect_languages [C:2] [TYPE Function] [SEMANTICS translate,language,detect,lingua]
|
||||
# @ingroup Translate
|
||||
# @BRIEF Run local language detection on all batch rows (no LLM).
|
||||
def _detect_languages(self, batch_rows: list[dict], target_languages: list[str]) -> None:
|
||||
"""Run local language detection on all batch rows (no LLM).
|
||||
|
||||
@@ -133,7 +145,17 @@ class BatchProcessingService:
|
||||
results = batch_detect(texts, target_languages)
|
||||
for row, lang in zip(batch_rows, results):
|
||||
row["_detected_lang"] = lang
|
||||
# #endregion _detect_languages
|
||||
|
||||
# #region _classify [C:4] [TYPE Function] [SEMANTICS translate,classify,cache,same-lang]
|
||||
# @ingroup Translate
|
||||
# @BRIEF Classify batch rows into pre_rows (no LLM needed) and llm_rows.
|
||||
# @POST Returns (llm_rows, pre_rows). Cached rows go to pre_rows only when
|
||||
# all non-source target languages are present in cache.
|
||||
# @RATIONALE Non-source tls filtering: tls may include the source language
|
||||
# (e.g. ["ru","en","fr","zh"]) but cache only has translations
|
||||
# (en/fr/zh). We exclude detected source language from the
|
||||
# cache-completeness check via non_source_tls.
|
||||
def _classify(self, batch_rows, preview_edits_cache, tls):
|
||||
llm_rows, pre_rows = [], []
|
||||
tls_lower = [str(t).lower() for t in tls]
|
||||
@@ -156,9 +178,15 @@ class BatchProcessingService:
|
||||
pre_rows.append(row)
|
||||
continue
|
||||
cl = row.get("_cached_lang_values")
|
||||
if cl and all(lc in cl for lc in tls):
|
||||
pre_rows.append(row)
|
||||
continue
|
||||
if cl:
|
||||
# Exclude source language from cache-completeness check:
|
||||
# tls may include the source language (e.g. ["ru","en","fr","zh"])
|
||||
# but cache only contains translations (en/fr/zh), not the source.
|
||||
dl = row.get("_detected_lang") or ""
|
||||
non_source_tls = [lc for lc in tls if str(lc).lower() != str(dl).lower()]
|
||||
if non_source_tls and all(lc in cl for lc in non_source_tls):
|
||||
pre_rows.append(row)
|
||||
continue
|
||||
if preview_edits_cache:
|
||||
sd = row.get("source_data") or {}
|
||||
if sd:
|
||||
@@ -175,7 +203,11 @@ class BatchProcessingService:
|
||||
{"tls": tls, "pre": len(pre_rows), "llm": len(llm_rows),
|
||||
"total": len(pre_rows) + len(llm_rows)})
|
||||
return llm_rows, pre_rows
|
||||
# #endregion _classify
|
||||
|
||||
# #region _persist_pre [C:3] [TYPE Function] [SEMANTICS translate,persist,record,language]
|
||||
# @ingroup Translate
|
||||
# @BRIEF Persist pre-classified rows as TranslationRecord + TranslationLanguage.
|
||||
def _persist_pre(self, pre_rows, bid, run_id, tls):
|
||||
count = 0
|
||||
for row in pre_rows:
|
||||
@@ -213,7 +245,11 @@ class BatchProcessingService:
|
||||
))
|
||||
count += 1
|
||||
return count
|
||||
# #endregion _persist_pre
|
||||
|
||||
# #region _process_llm [C:4] [TYPE Function] [SEMANTICS translate,llm,call,batch]
|
||||
# @ingroup Translate
|
||||
# @BRIEF Process LLM translation for a batch: estimate budget, call LLM, return results.
|
||||
async def _process_llm(self, job, run_id, rows_for_llm, dict_matches, bid, tls):
|
||||
# Resolve provider token config (DB values take priority over PROVIDER_DEFAULTS)
|
||||
token_config = {"model": None, "context_window": None, "max_output_tokens": None}
|
||||
@@ -260,9 +296,13 @@ class BatchProcessingService:
|
||||
},
|
||||
)
|
||||
return result
|
||||
# #endregion _process_llm
|
||||
|
||||
# -- Batch insert (delegation) --
|
||||
# #region insert_batch_to_target [C:4] [TYPE Function] [SEMANTICS translate,batch,insert,target]
|
||||
# @ingroup Translate
|
||||
# @BRIEF Insert batch records into the target table via SQL Lab or direct DB.
|
||||
async def insert_batch_to_target(self, job: TranslationJob, batch_id: str, run_id: str) -> None:
|
||||
await insert_batch_to_target(self.db, self.config_manager, job, batch_id, run_id)
|
||||
# #endregion insert_batch_to_target
|
||||
# #endregion BatchProcessingService
|
||||
# #endregion BatchProcessingService
|
||||
|
||||
Reference in New Issue
Block a user