Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ae02be9

Browse files
🔨 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>
1 parent d67f092 commit ae02be9

2 files changed

Lines changed: 86 additions & 57 deletions

File tree

‎docs/es/llm-prompt.md‎

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,6 @@ Use the informal grammar (use "tú" instead of "usted").
44

55
For instructions or titles in imperative, keep them in imperative, for example "Edit it" to "Edítalo".
66

7-
There are special blocks of notes, tips and others that look like:
8-
9-
/// note
10-
11-
To translate it, keep the same line and add the translation after a vertical bar:
12-
13-
/// note | Nota
14-
15-
Some examples:
16-
17-
Source:
18-
19-
/// tip
20-
21-
Result:
22-
23-
/// tip | Consejo
24-
25-
Source:
26-
27-
/// details | Preview
28-
29-
Result:
30-
31-
/// details | Vista previa
32-
33-
Source:
34-
35-
/// warning
36-
37-
Result:
38-
39-
/// warning | Advertencia
40-
41-
Source:
42-
43-
/// info
44-
45-
Result:
46-
47-
/// info | Información
48-
49-
Source:
50-
51-
/// note | Technical Details
52-
53-
Result:
54-
55-
/// note | Detalles Técnicos
56-
577
---
588

599
For the next terms, use the following translations:

‎scripts/translate.py‎

Lines changed: 86 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import typer
66
import yaml
77
from pydantic_ai import Agent
8+
from rich import print
89

910
non_translated_sections = (
1011
"reference/",
@@ -28,8 +29,38 @@
2829
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.
2930
3031
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.
32+
33+
There are special blocks of notes, tips and others that look like:
34+
35+
/// note
36+
37+
To translate it, keep the same line and add the translation after a vertical bar.
38+
39+
For example, if you were translating to Spanish, you would write:
40+
41+
/// note | Nota
42+
43+
Some examples in Spanish:
44+
45+
Source:
46+
47+
/// tip
48+
49+
Result:
50+
51+
/// tip | Consejo
52+
53+
Source:
54+
55+
/// details | Preview
56+
57+
Result:
58+
59+
/// details | Vista previa
3160
"""
3261

62+
app = typer.Typer()
63+
3364

3465
@lru_cache
3566
def get_langs() -> dict[str, str]:
@@ -46,6 +77,17 @@ def generate_lang_path(*, lang: str, path: Path) -> Path:
4677
return out_path
4778

4879

80+
def generate_en_path(*, lang: str, path: Path) -> Path:
81+
en_docs_path = Path("docs/en/docs")
82+
assert not str(path).startswith(str(en_docs_path)), (
83+
f"Path must not be inside {en_docs_path}"
84+
)
85+
lang_docs_path = Path(f"docs/{lang}/docs")
86+
out_path = Path(str(path).replace(str(lang_docs_path), str(en_docs_path)))
87+
return out_path
88+
89+
90+
@app.command()
4991
def translate_page(*, lang: str, path: Path) -> None:
5092
langs = get_langs()
5193
language = langs[lang]
@@ -68,8 +110,8 @@ def translate_page(*, lang: str, path: Path) -> None:
68110
agent = Agent("openai:gpt-4o")
69111

70112
prompt_segments = [
71-
lang_prompt_content,
72113
general_prompt,
114+
lang_prompt_content,
73115
]
74116
if old_translation:
75117
prompt_segments.extend(
@@ -119,6 +161,7 @@ def iter_paths_to_translate() -> Iterable[Path]:
119161
yield path
120162

121163

164+
@app.command()
122165
def translate_all(lang: str) -> None:
123166
paths_to_process: list[Path] = []
124167
for path in iter_paths_to_translate():
@@ -151,12 +194,48 @@ def translate_all(lang: str) -> None:
151194
print(f"Done translating: {p}")
152195

153196

154-
def main(*, lang: str, path: Path = None) -> None:
155-
if path:
156-
translate_page(lang=lang, path=path)
157-
else:
158-
translate_all(lang=lang)
197+
@app.command()
198+
def list_removable(lang: str) -> list[Path]:
199+
removable_paths: list[Path] = []
200+
lang_paths = Path(f"docs/{lang}").rglob("*.md")
201+
for path in lang_paths:
202+
en_path = generate_en_path(lang=lang, path=path)
203+
if not en_path.exists():
204+
removable_paths.append(path)
205+
print(removable_paths)
206+
return removable_paths
207+
208+
209+
@app.command()
210+
def list_all_removable() -> list[Path]:
211+
all_removable_paths: list[Path] = []
212+
langs = get_langs()
213+
for lang in langs:
214+
if lang == "en":
215+
continue
216+
removable_paths = list_removable(lang)
217+
all_removable_paths.extend(removable_paths)
218+
print(all_removable_paths)
219+
return all_removable_paths
220+
221+
222+
@app.command()
223+
def remove_removable(lang: str) -> None:
224+
removable_paths = list_removable(lang)
225+
for path in removable_paths:
226+
path.unlink()
227+
print(f"Removed: {path}")
228+
print("Done removing all removable paths")
229+
230+
231+
@app.command()
232+
def remove_all_removable() -> None:
233+
all_removable = list_all_removable()
234+
for removable_path in all_removable:
235+
removable_path.unlink()
236+
print(f"Removed: {removable_path}")
237+
print("Done removing all removable paths")
159238

160239

161240
if __name__ == "__main__":
162-
typer.run(main)
241+
app()

0 commit comments

Comments
 (0)