Compare commits

..

2 Commits

Author SHA1 Message Date
github-actions[bot]
174a3e0976 🎨 Auto format 2026-01-21 09:44:13 +00:00
Yurii Motov
2a0d5ee2af Integrate check_translation function to translate_page - retry up to 3 times if translation check failed 2026-01-21 10:21:36 +01:00
11 changed files with 55 additions and 63 deletions

1
.github/labeler.yml vendored
View File

@@ -31,7 +31,6 @@ internal:
- .pre-commit-config.yaml
- pdm_build.py
- requirements*.txt
- uv.lock
- docs/en/data/sponsors.yml
- docs/en/overrides/main.html
- all-globs-to-all-files:

View File

@@ -189,7 +189,7 @@ Siehe Abschnitt `### Links` im allgemeinen Prompt in `scripts/translate.py`.
////
## HTML-„abbr“-Elemente { #html-abbr-elements }
## HTML „abbr“-Elemente { #html-abbr-elements }
//// tab | Test

View File

@@ -56,19 +56,19 @@ from app.routers import items
Die gleiche Dateistruktur mit Kommentaren:
```bash
```
.
├── app # "app" ist ein Python-Package
│   ├── __init__.py # diese Datei macht "app" zu einem "Python-Package"
│   ├── main.py # "main"-Modul, z. B. import app.main
│   ├── dependencies.py # "dependencies"-Modul, z. B. import app.dependencies
│   └── routers # "routers" ist ein "Python-Subpackage"
│   │ ├── __init__.py # macht "routers" zu einem "Python-Subpackage"
│   │ ├── items.py # "items"-Submodul, z. B. import app.routers.items
│   │ └── users.py # "users"-Submodul, z. B. import app.routers.users
│   └── internal # "internal" ist ein "Python-Subpackage"
│   ├── __init__.py # macht "internal" zu einem "Python-Subpackage"
│   └── admin.py # "admin"-Submodul, z. B. import app.internal.admin
├── app # app ist ein Python-Package
│   ├── __init__.py # diese Datei macht app zu einem Python-Package
│   ├── main.py # main-Modul, z. B. import app.main
│   ├── dependencies.py # dependencies-Modul, z. B. import app.dependencies
│   └── routers # routers ist ein Python-Subpackage
│   │ ├── __init__.py # macht routers zu einem Python-Subpackage
│   │ ├── items.py # items-Submodul, z. B. import app.routers.items
│   │ └── users.py # users-Submodul, z. B. import app.routers.users
│   └── internal # internal ist ein Python-Subpackage
│   ├── __init__.py # macht internal zu einem Python-Subpackage
│   └── admin.py # admin-Submodul, z. B. import app.internal.admin
```
## `APIRouter` { #apirouter }
@@ -479,7 +479,7 @@ $ fastapi dev app/main.py
</div>
Und öffnen Sie die Dokumentation unter <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
und öffnen Sie die Dokumentation unter <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
Sie sehen die automatische API-Dokumentation, einschließlich der Pfade aller Submodule, mit den richtigen Pfaden (und Präfixen) und den richtigen Tags:

View File

@@ -60,7 +60,8 @@ FastAPI also includes these JavaScript-only `presets` settings:
```JavaScript
presets: [
SwaggerUIBundle.presets.apis
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.SwaggerUIStandalonePreset
]
```

View File

@@ -18,8 +18,6 @@ hide:
### Translations
* 🌐 Update translations for de (update-outdated). PR [#14690](https://github.com/fastapi/fastapi/pull/14690) by [@tiangolo](https://github.com/tiangolo).
* 🌐 Update LLM prompt for Russian translations. PR [#14733](https://github.com/fastapi/fastapi/pull/14733) by [@YuriiMotov](https://github.com/YuriiMotov).
* 🌐 Update translations for ru (update-outdated). PR [#14693](https://github.com/fastapi/fastapi/pull/14693) by [@tiangolo](https://github.com/tiangolo).
* 🌐 Update translations for pt (update-outdated). PR [#14724](https://github.com/fastapi/fastapi/pull/14724) by [@tiangolo](https://github.com/tiangolo).
* 🌐 Update Korean LLM prompt. PR [#14740](https://github.com/fastapi/fastapi/pull/14740) by [@hard-coders](https://github.com/hard-coders).
@@ -36,7 +34,6 @@ hide:
### Internal
* 🔧 Ensure that an edit to `uv.lock` gets the `internal` label. PR [#14759](https://github.com/fastapi/fastapi/pull/14759) by [@svlandeg](https://github.com/svlandeg).
* 🔧 Update sponsors: remove Requestly. PR [#14735](https://github.com/fastapi/fastapi/pull/14735) by [@tiangolo](https://github.com/tiangolo).
* 🔧 Update sponsors, LambdaTest changes to TestMu AI. PR [#14734](https://github.com/fastapi/fastapi/pull/14734) by [@tiangolo](https://github.com/tiangolo).
* ⬆ Bump actions/cache from 4 to 5. PR [#14511](https://github.com/fastapi/fastapi/pull/14511) by [@dependabot[bot]](https://github.com/apps/dependabot).

View File

@@ -90,12 +90,5 @@ For the following technical terms, use these specific translations to ensure con
* serve (meaning providing access to something): «отдавать» (or `предоставлять доступ к`)
* recap (noun): резюме
* utility function: вспомогательная функция
* fast to code: позволяет быстро писать код
* Tutorial - User Guide: Учебник - Руководство пользователя
* submodule: подмодуль
* subpackage: подпакет
* router: роутер
* building, deploying, accessing (when describing features of FastAPI Cloud): созданиe образа, развертывание и доступ
* type checker tool: инструмент проверки типов
Do not add whitespace in `т.д.`, `т.п.`.

View File

@@ -54,14 +54,6 @@ def get_swagger_ui_html(
"""
),
] = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-bundle.js",
swagger_extra_js_urls: Annotated[
Optional[list[str]],
Doc(
"""
The URLs of additional JavaScript files to include.
"""
),
] = None,
swagger_css_url: Annotated[
str,
Doc(
@@ -106,14 +98,6 @@ def get_swagger_ui_html(
"""
),
] = None,
swagger_extra_presets: Annotated[
Optional[list[str]],
Doc(
"""
Extra presets to add to Swagger UI.
"""
),
] = None,
) -> HTMLResponse:
"""
Generate and return the HTML that loads Swagger UI for the interactive
@@ -130,13 +114,6 @@ def get_swagger_ui_html(
if swagger_ui_parameters:
current_swagger_ui_parameters.update(swagger_ui_parameters)
js_urls = [swagger_js_url]
if swagger_extra_js_urls:
js_urls.extend(swagger_extra_js_urls)
scripts_str = "\n ".join(
f'<script src="{js_url}"></script>' for js_url in js_urls
)
html = f"""
<!DOCTYPE html>
<html>
@@ -148,7 +125,7 @@ def get_swagger_ui_html(
<body>
<div id="swagger-ui">
</div>
{scripts_str}
<script src="{swagger_js_url}"></script>
<!-- `SwaggerUIBundle` is now available on the page -->
<script>
const ui = SwaggerUIBundle({{
@@ -161,18 +138,12 @@ def get_swagger_ui_html(
if oauth2_redirect_url:
html += f"oauth2RedirectUrl: window.location.origin + '{oauth2_redirect_url}',"
presets = ["SwaggerUIBundle.presets.apis"]
if swagger_extra_presets:
presets.extend(swagger_extra_presets)
presets_str = ",\n ".join(presets)
html += f"""
html += """
presets: [
{presets_str},
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.SwaggerUIStandalonePreset
],
"""
html += " })"
})"""
if init_oauth:
html += f"""

View File

@@ -10,6 +10,7 @@ from typing import Annotated
import git
import typer
import yaml
from doc_parsing_utils import check_translation
from github import Github
from pydantic_ai import Agent
from rich import print
@@ -119,9 +120,30 @@ def translate_page(
]
)
prompt = "\n\n".join(prompt_segments)
print(f"Running agent for {out_path}")
result = agent.run_sync(prompt)
out_content = f"{result.output.strip()}\n"
MAX_ATTEMPTS = 3
for attempt_no in range(1, MAX_ATTEMPTS + 1):
print(f"Running agent for {out_path} (attempt {attempt_no}/{MAX_ATTEMPTS})")
result = agent.run_sync(prompt)
out_content = f"{result.output.strip()}\n"
try:
check_translation(
doc_lines=out_content.splitlines(),
en_doc_lines=original_content.splitlines(),
lang_code=language,
auto_fix=False,
path=str(out_path),
)
break # Exit loop if no errors
except ValueError as e:
print(
f"Translation check failed on attempt {attempt_no}/{MAX_ATTEMPTS}: {e}"
)
continue # Retry if not reached max attempts
else: # Max retry attempts reached
print(f"Translation failed for {out_path} after {MAX_ATTEMPTS} attempts")
raise typer.Exit(code=1)
print(f"Saving translation to {out_path}")
out_path.write_text(out_content, encoding="utf-8", newline="\n")

View File

@@ -18,6 +18,9 @@ def test_swagger_ui():
assert "SwaggerUIBundle.presets.apis," in response.text, (
"default configs should be preserved"
)
assert "SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text, (
"default configs should be preserved"
)
assert '"layout": "BaseLayout",' in response.text, (
"default configs should be preserved"
)

View File

@@ -21,6 +21,9 @@ def test_swagger_ui():
assert "SwaggerUIBundle.presets.apis," in response.text, (
"default configs should be preserved"
)
assert "SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text, (
"default configs should be preserved"
)
assert '"layout": "BaseLayout",' in response.text, (
"default configs should be preserved"
)

View File

@@ -24,6 +24,9 @@ def test_swagger_ui():
assert "SwaggerUIBundle.presets.apis," in response.text, (
"default configs should be preserved"
)
assert "SwaggerUIBundle.SwaggerUIStandalonePreset" in response.text, (
"default configs should be preserved"
)
assert '"layout": "BaseLayout",' in response.text, (
"default configs should be preserved"
)