Browse Source

🔨 Update translations script to remove old (removed) files (#13928)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
pull/13930/head
Sebastián Ramírez 7 days ago
committed by GitHub
parent
commit
ae02be90b6
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 50
      docs/es/llm-prompt.md
  2. 93
      scripts/translate.py

50
docs/es/llm-prompt.md

@ -4,56 +4,6 @@ Use the informal grammar (use "tú" instead of "usted").
For instructions or titles in imperative, keep them in imperative, for example "Edit it" to "Edítalo".
There are special blocks of notes, tips and others that look like:
/// note
To translate it, keep the same line and add the translation after a vertical bar:
/// note | Nota
Some examples:
Source:
/// tip
Result:
/// tip | Consejo
Source:
/// details | Preview
Result:
/// details | Vista previa
Source:
/// warning
Result:
/// warning | Advertencia
Source:
/// info
Result:
/// info | Información
Source:
/// note | Technical Details
Result:
/// note | Detalles Técnicos
---
For the next terms, use the following translations:

93
scripts/translate.py

@ -5,6 +5,7 @@ from typing import Iterable
import typer
import yaml
from pydantic_ai import Agent
from rich import print
non_translated_sections = (
"reference/",
@ -28,8 +29,38 @@ The content is written in markdown, write the translation in markdown as well. D
When there's an example of code, the console or a terminal, normally surrounded by triple backticks and a keyword like "console" or "bash" (e.g. ```console), do not translate the content, keep the original in English.
The original content will be surrounded by triple percentage signs (%) and you should translate it to the target language. Do not include the triple percentage signs in the translation.
There are special blocks of notes, tips and others that look like:
/// note
To translate it, keep the same line and add the translation after a vertical bar.
For example, if you were translating to Spanish, you would write:
/// note | Nota
Some examples in Spanish:
Source:
/// tip
Result:
/// tip | Consejo
Source:
/// details | Preview
Result:
/// details | Vista previa
"""
app = typer.Typer()
@lru_cache
def get_langs() -> dict[str, str]:
@ -46,6 +77,17 @@ def generate_lang_path(*, lang: str, path: Path) -> Path:
return out_path
def generate_en_path(*, lang: str, path: Path) -> Path:
en_docs_path = Path("docs/en/docs")
assert not str(path).startswith(str(en_docs_path)), (
f"Path must not be inside {en_docs_path}"
)
lang_docs_path = Path(f"docs/{lang}/docs")
out_path = Path(str(path).replace(str(lang_docs_path), str(en_docs_path)))
return out_path
@app.command()
def translate_page(*, lang: str, path: Path) -> None:
langs = get_langs()
language = langs[lang]
@ -68,8 +110,8 @@ def translate_page(*, lang: str, path: Path) -> None:
agent = Agent("openai:gpt-4o")
prompt_segments = [
lang_prompt_content,
general_prompt,
lang_prompt_content,
]
if old_translation:
prompt_segments.extend(
@ -119,6 +161,7 @@ def iter_paths_to_translate() -> Iterable[Path]:
yield path
@app.command()
def translate_all(lang: str) -> None:
paths_to_process: list[Path] = []
for path in iter_paths_to_translate():
@ -151,12 +194,48 @@ def translate_all(lang: str) -> None:
print(f"Done translating: {p}")
def main(*, lang: str, path: Path = None) -> None:
if path:
translate_page(lang=lang, path=path)
else:
translate_all(lang=lang)
@app.command()
def list_removable(lang: str) -> list[Path]:
removable_paths: list[Path] = []
lang_paths = Path(f"docs/{lang}").rglob("*.md")
for path in lang_paths:
en_path = generate_en_path(lang=lang, path=path)
if not en_path.exists():
removable_paths.append(path)
print(removable_paths)
return removable_paths
@app.command()
def list_all_removable() -> list[Path]:
all_removable_paths: list[Path] = []
langs = get_langs()
for lang in langs:
if lang == "en":
continue
removable_paths = list_removable(lang)
all_removable_paths.extend(removable_paths)
print(all_removable_paths)
return all_removable_paths
@app.command()
def remove_removable(lang: str) -> None:
removable_paths = list_removable(lang)
for path in removable_paths:
path.unlink()
print(f"Removed: {path}")
print("Done removing all removable paths")
@app.command()
def remove_all_removable() -> None:
all_removable = list_all_removable()
for removable_path in all_removable:
removable_path.unlink()
print(f"Removed: {removable_path}")
print("Done removing all removable paths")
if __name__ == "__main__":
typer.run(main)
app()

Loading…
Cancel
Save