2026-10-18 20:00:31 +02:00
|
|
|
"""What email translation offers (app/translation.py), for the reading pane."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from fastapi import APIRouter
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
from app import translation
|
|
|
|
|
from app.identity.deps import CurrentUser
|
|
|
|
|
|
|
|
|
|
router = APIRouter(prefix="/translation", tags=["mail"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LanguageOut(BaseModel):
|
|
|
|
|
code: str
|
|
|
|
|
name: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TranslationInfoOut(BaseModel):
|
|
|
|
|
available: bool
|
|
|
|
|
languages: list[LanguageOut]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/languages", response_model=TranslationInfoOut)
|
|
|
|
|
async def translation_languages(user: CurrentUser) -> TranslationInfoOut:
|
|
|
|
|
found = await translation.languages()
|
|
|
|
|
return TranslationInfoOut(
|
2026-10-18 22:04:04 +02:00
|
|
|
available=len(found) > 1, # English alone translates nothing
|
2026-10-18 20:00:31 +02:00
|
|
|
languages=[LanguageOut(code=x.code, name=x.name) for x in found],
|
|
|
|
|
)
|