31 lines
780 B
Python
31 lines
780 B
Python
"""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(
|
||
|
|
available=bool(found),
|
||
|
|
languages=[LanguageOut(code=x.code, name=x.name) for x in found],
|
||
|
|
)
|