feat(translation): Post translation columns + settings + migration (#143 step 1)
Post gains post_title_translated / description_translated / translated_source_lang / translation_engine_version / translated_at — filled by the translate sweep so viewing is instant. ImportSettings gains translation_enabled (OFF by default), interpreter_base_url (EMPTY — no default host; the operator points it at their own Interpreter proxy behind a reverse proxy) and translation_target_lang (en), exposed + validated via /settings/import. Migration 0083. Settings defaults + patch + validation test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CDgx8bQS5YrGRK76v8HUnM
This commit is contained in:
@@ -32,6 +32,9 @@ _EDITABLE_FIELDS = (
|
||||
"extdl_mediafire_enabled",
|
||||
"extdl_dropbox_enabled",
|
||||
"extdl_pixeldrain_enabled",
|
||||
"translation_enabled",
|
||||
"interpreter_base_url",
|
||||
"translation_target_lang",
|
||||
)
|
||||
|
||||
# Per-host external-download toggles — all plain booleans, validated uniformly.
|
||||
@@ -69,6 +72,9 @@ async def get_import_settings():
|
||||
"extdl_mediafire_enabled": row.extdl_mediafire_enabled,
|
||||
"extdl_dropbox_enabled": row.extdl_dropbox_enabled,
|
||||
"extdl_pixeldrain_enabled": row.extdl_pixeldrain_enabled,
|
||||
"translation_enabled": row.translation_enabled,
|
||||
"interpreter_base_url": row.interpreter_base_url,
|
||||
"translation_target_lang": row.translation_target_lang,
|
||||
})
|
||||
|
||||
|
||||
@@ -128,6 +134,15 @@ async def update_import_settings():
|
||||
for tog in _EXTDL_TOGGLE_FIELDS:
|
||||
if tog in body and not isinstance(body[tog], bool):
|
||||
return jsonify({"error": f"{tog} must be a boolean"}), 400
|
||||
# Translation (#143): base URL may be empty (feature off until set — no
|
||||
# default host; the operator points it at their own Interpreter proxy).
|
||||
if "translation_enabled" in body and not isinstance(
|
||||
body["translation_enabled"], bool
|
||||
):
|
||||
return jsonify({"error": "translation_enabled must be a boolean"}), 400
|
||||
for key in ("interpreter_base_url", "translation_target_lang"):
|
||||
if key in body and not isinstance(body[key], str):
|
||||
return jsonify({"error": f"{key} must be a string"}), 400
|
||||
if "series_suggest_threshold" in body:
|
||||
v = body["series_suggest_threshold"]
|
||||
if not isinstance(v, (int, float)) or isinstance(v, bool) or v < 0 or v > 1:
|
||||
|
||||
@@ -92,6 +92,21 @@ class ImportSettings(Base):
|
||||
Boolean, nullable=False, default=True, server_default="true",
|
||||
)
|
||||
|
||||
# -- Post-text translation via the Interpreter LAN service (milestone 143).
|
||||
# Off by default with NO default host — it needs a reachable Interpreter
|
||||
# service (the operator's, behind a reverse proxy), which not every install
|
||||
# has; the operator sets the URL and flips it on. Empty base_url OR disabled
|
||||
# → the translate sweep no-ops.
|
||||
translation_enabled: Mapped[bool] = mapped_column(
|
||||
Boolean, nullable=False, default=False, server_default="false",
|
||||
)
|
||||
interpreter_base_url: Mapped[str] = mapped_column(
|
||||
Text, nullable=False, default="", server_default="",
|
||||
)
|
||||
translation_target_lang: Mapped[str] = mapped_column(
|
||||
Text, nullable=False, default="en", server_default="en",
|
||||
)
|
||||
|
||||
@classmethod
|
||||
async def load(cls, session) -> ImportSettings:
|
||||
"""The singleton settings row (id=1), via an async session."""
|
||||
|
||||
@@ -47,6 +47,24 @@ class Post(Base):
|
||||
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
attachment_count: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
|
||||
# -- Post-text translation (milestone 143). Filled by the translate_posts
|
||||
# sweep via the Interpreter LAN service so viewing is instant.
|
||||
# translated_source_lang is the DETECTED original language; "en" (or a
|
||||
# passthrough) means nothing to translate and the *_translated columns stay
|
||||
# NULL. engine_version keys the Interpreter cache — re-runs are ~1ms and a
|
||||
# model upgrade re-translates instead of serving stale.
|
||||
post_title_translated: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
description_translated: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
translated_source_lang: Mapped[str | None] = mapped_column(
|
||||
String(8), nullable=True
|
||||
)
|
||||
translation_engine_version: Mapped[str | None] = mapped_column(
|
||||
String(128), nullable=True
|
||||
)
|
||||
translated_at: Mapped[datetime | None] = mapped_column(
|
||||
DateTime(timezone=True), nullable=True
|
||||
)
|
||||
|
||||
downloaded_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), nullable=False, server_default=func.now()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user