language fixes
This commit is contained in:
parent
fc17f51752
commit
0f5d695960
1 changed files with 73 additions and 61 deletions
|
|
@ -58,12 +58,15 @@ _TRANSLATE_RATE_LIMIT_MAX_RETRIES = 3
|
|||
|
||||
_PROTECTED_CODES = frozenset({"xx"})
|
||||
|
||||
# In-memory set of language codes currently being updated (sync / create).
|
||||
_UPDATING_CODES: Set[str] = set()
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# ISO 639-1 label map (used when creating a language without explicit label)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_ISO_LABELS: Dict[str, str] = {
|
||||
"de": "Deutsch", "en": "English", "fr": "Français", "it": "Italiano",
|
||||
"de": "Deutsch", "gsw": "Schweizerdeutsch", "en": "English", "fr": "Français", "it": "Italiano",
|
||||
"es": "Español", "pt": "Português", "nl": "Nederlands", "pl": "Polski",
|
||||
"cs": "Čeština", "sk": "Slovenčina", "sv": "Svenska", "no": "Norsk",
|
||||
"da": "Dansk", "fi": "Suomi", "hu": "Magyar", "ro": "Română",
|
||||
|
|
@ -487,15 +490,17 @@ async def list_language_codes():
|
|||
entries = _rowEntries(r)
|
||||
uiCount = sum(1 for e in entries if e.get("context", "ui") == "ui")
|
||||
gatewayCount = len(entries) - uiCount
|
||||
code = r["id"]
|
||||
out.append(
|
||||
{
|
||||
"code": r["id"],
|
||||
"code": code,
|
||||
"label": r.get("label"),
|
||||
"status": r.get("status"),
|
||||
"isDefault": bool(r.get("isDefault")),
|
||||
"entriesCount": len(entries),
|
||||
"uiCount": uiCount,
|
||||
"gatewayCount": gatewayCount,
|
||||
"updating": code in _UPDATING_CODES,
|
||||
}
|
||||
)
|
||||
return sorted(out, key=lambda x: (not x.get("isDefault"), x["code"]))
|
||||
|
|
@ -520,9 +525,9 @@ class CreateLanguageBody(BaseModel):
|
|||
|
||||
def _validate_iso2_code(code: str) -> str:
|
||||
c = code.strip().lower()
|
||||
if not re.fullmatch(r"[a-z]{2}", c):
|
||||
if not re.fullmatch(r"[a-z]{2,3}", c):
|
||||
raise HTTPException(
|
||||
status_code=400, detail=routeApiMsg("Nur ISO-639-1 Zwei-Buchstaben-Codes erlaubt.")
|
||||
status_code=400, detail=routeApiMsg("Nur ISO-639 Sprachcodes (2–3 Buchstaben) erlaubt.")
|
||||
)
|
||||
return c
|
||||
|
||||
|
|
@ -536,6 +541,7 @@ def _run_create_language_job(userId: str, code: str, label: str, currentUser: Us
|
|||
|
||||
|
||||
async def _run_create_language_job_async(userId: str, code: str, label: str, currentUser: User, mandateId: str) -> None:
|
||||
_UPDATING_CODES.add(code)
|
||||
try:
|
||||
db = _publicMgmtDb()
|
||||
rows = db.getRecordset(UiLanguageSet, recordFilter={"id": code})
|
||||
|
|
@ -590,6 +596,8 @@ async def _run_create_language_job_async(userId: str, code: str, label: str, cur
|
|||
title="Sprachset fehlgeschlagen",
|
||||
message=f"Fehler bei «{code}»: {e}",
|
||||
)
|
||||
finally:
|
||||
_UPDATING_CODES.discard(code)
|
||||
|
||||
|
||||
@router.post("/sets")
|
||||
|
|
@ -678,6 +686,8 @@ async def _syncLanguageWithXx(db, code: str, userId: Optional[str], adminUser: O
|
|||
"""
|
||||
if code == "xx":
|
||||
raise HTTPException(status_code=400, detail=routeApiMsg("Das xx-Set wird über 'UI-Keys einlesen' aktualisiert."))
|
||||
_UPDATING_CODES.add(code)
|
||||
try:
|
||||
rows = db.getRecordset(UiLanguageSet, recordFilter={"id": code})
|
||||
if not rows:
|
||||
raise HTTPException(status_code=404, detail=routeApiMsg("Sprachset nicht gefunden"))
|
||||
|
|
@ -743,6 +753,8 @@ async def _syncLanguageWithXx(db, code: str, userId: Optional[str], adminUser: O
|
|||
"translated": translatedCount,
|
||||
"entriesCount": len(newEntries),
|
||||
}
|
||||
finally:
|
||||
_UPDATING_CODES.discard(code)
|
||||
|
||||
|
||||
@router.put("/sets/sync-xx")
|
||||
|
|
|
|||
Loading…
Reference in a new issue