Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts/set-alias-page.py: Improve sync translations #15389

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e94501a
Update set alias page when file already exists
Zamoca42 Dec 30, 2024
cf7648e
Update Korean translation alias pages
Zamoca42 Dec 30, 2024
b7895f8
Revert "Update Korean translation alias pages"
Zamoca42 Dec 30, 2024
f21edaf
Update original command
Zamoca42 Dec 30, 2024
ecf2dd9
Add Korean translation for alias pages
Zamoca42 Dec 30, 2024
a2394f3
Revert "Add Korean translation for alias pages"
Zamoca42 Dec 30, 2024
6e641be
Improve alias page template processing
Zamoca42 Dec 30, 2024
7138ad6
Add Korean translation for alias pages
Zamoca42 Dec 30, 2024
4ca4c90
Update format of alias pages
Zamoca42 Dec 30, 2024
56a6cfc
Update format of alias pages
Zamoca42 Dec 30, 2024
14d4685
Reformat scripts/set-alias-page.py
Zamoca42 Dec 30, 2024
5ef6671
Merge branch 'main' into update-set-alias-page
Zamoca42 Dec 30, 2024
004a9a5
Remove Korean alias pages
Zamoca42 Dec 31, 2024
34733d9
Reverting Korean alias pages template
Zamoca42 Dec 31, 2024
35f8fc8
Restore regex for alias page parsing
Zamoca42 Dec 31, 2024
1e8d78e
Merge branch 'main' into update-set-alias-page
Zamoca42 Dec 31, 2024
08d0b39
Update parsing alias page command
Zamoca42 Jan 2, 2025
7db9d2e
Merge branch 'main' into update-set-alias-page
Zamoca42 Jan 2, 2025
424087f
Update comment
Zamoca42 Jan 2, 2025
0f06818
Update command arguments to support separate original and documentati…
Zamoca42 Jan 2, 2025
672259c
Add original_command arguments optional
Zamoca42 Jan 2, 2025
f5b9df6
Merge branch 'main' into update-set-alias-page
sebastiaanspeck Jan 2, 2025
cf45691
Add get_locale_alias_pattern and fix flag collision
Zamoca42 Jan 2, 2025
2da1472
Add command parsing test function
Zamoca42 Jan 2, 2025
355fa47
Fix ORIGINAL_CMD argument
Zamoca42 Jan 3, 2025
97846ac
Merge branch 'main' into update-set-alias-page
Zamoca42 Jan 3, 2025
5adeab7
Update scripts/set-alias-page.py
Zamoca42 Jan 3, 2025
ee9665f
Update scripts/set-alias-page.py
Zamoca42 Jan 3, 2025
538d1f4
Update scripts/set-alias-page.py
Zamoca42 Jan 3, 2025
60252c4
Update page only when documentation command changes
Zamoca42 Jan 3, 2025
9f3dc8a
Merge branch 'main' into update-set-alias-page
sebastiaanspeck Jan 3, 2025
93bd8c5
Add wizard to page arg and refactor sync
Zamoca42 Jan 4, 2025
f373f3d
Merge branch 'main' into update-set-alias-page
Zamoca42 Jan 4, 2025
b496d9d
Update script file documents
Zamoca42 Jan 4, 2025
c904cd3
Rename command to page_path for clarity
Zamoca42 Jan 4, 2025
91ae2ca
Refactor to use global Config
Zamoca42 Jan 4, 2025
a0f401c
Add AliasPageContent dataclass for title and commands
Zamoca42 Jan 4, 2025
bffeb7a
Update global state and simplify sync logic
Zamoca42 Jan 4, 2025
2f4391f
Rename functions and variables for clarity
Zamoca42 Jan 4, 2025
b643eb6
Update scripts/set-alias-page.py
Zamoca42 Jan 6, 2025
a123833
Add check_exists flag to get_target_paths()
Zamoca42 Jan 6, 2025
c81ea1f
Update docstring indentation
Zamoca42 Jan 6, 2025
6573a77
Merge branch 'main' into update-set-alias-page
Zamoca42 Jan 6, 2025
28602dc
Update prompt with page status and documentation
Zamoca42 Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contributing-guides/translation-templates/alias-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
```markdown
# example

> Dieser Befehl ist ein Alias von `example`.

Check failure on line 152 in contributing-guides/translation-templates/alias-pages.md

View workflow job for this annotation

GitHub Actions / build

ist ==> is, it, its, it's, sit, list

- Zeige die Dokumentation für den originalen Befehl an:

Expand All @@ -163,9 +163,9 @@
```markdown
# example

> Este comando es un alias de `example`.

Check failure on line 166 in contributing-guides/translation-templates/alias-pages.md

View workflow job for this annotation

GitHub Actions / build

comando ==> commando

- Vea la documentación para el comando original:

Check failure on line 168 in contributing-guides/translation-templates/alias-pages.md

View workflow job for this annotation

GitHub Actions / build

comando ==> commando

`tldr example`
```
Expand Down Expand Up @@ -247,9 +247,9 @@
```markdown
# example

> Questo comando è un alias per `example`.

Check failure on line 250 in contributing-guides/translation-templates/alias-pages.md

View workflow job for this annotation

GitHub Actions / build

comando ==> commando

- Consulta la documentazione del comando originale:

Check failure on line 252 in contributing-guides/translation-templates/alias-pages.md

View workflow job for this annotation

GitHub Actions / build

comando ==> commando

`tldr example`
```
Expand All @@ -275,9 +275,9 @@
```markdown
# example

> 이 명령은 `example` 의 에일리어스 (별칭) 입니다.
> 이 명령어는 `example`의 별칭 입니다.

- 원본 명령의 도큐멘테이션 (설명서) 보기:
- 원본 명령어의 문서 보기:

`tldr example`
```
Expand Down Expand Up @@ -373,9 +373,9 @@
```markdown
# example

> Este comando é um apelido de `example`.

Check failure on line 376 in contributing-guides/translation-templates/alias-pages.md

View workflow job for this annotation

GitHub Actions / build

comando ==> commando

- Veja documentação sobre o comando original:

Check failure on line 378 in contributing-guides/translation-templates/alias-pages.md

View workflow job for this annotation

GitHub Actions / build

comando ==> commando

`tldr example`
```
Expand All @@ -387,9 +387,9 @@
```markdown
# example

> Este comando é um alias de `example`.

Check failure on line 390 in contributing-guides/translation-templates/alias-pages.md

View workflow job for this annotation

GitHub Actions / build

comando ==> commando

- Ver documentação do comando original:

Check failure on line 392 in contributing-guides/translation-templates/alias-pages.md

View workflow job for this annotation

GitHub Actions / build

comando ==> commando

`tldr example`
```
Expand Down Expand Up @@ -499,7 +499,7 @@
```markdown
# example

> Bu komut `example` için bir takma addır.

Check failure on line 502 in contributing-guides/translation-templates/alias-pages.md

View workflow job for this annotation

GitHub Actions / build

Bu ==> By, Be, But, Bug, Bun, Bud, Buy, Bum

- Asıl komutun belgelerini görüntüleyin:

Expand Down
7 changes: 7 additions & 0 deletions pages.ko/common/mapfile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# mapfile

> 이 명령어는 `readarray`의 별칭 입니다.

- 원본 명령어의 문서 보기:

`tldr readarray`
7 changes: 7 additions & 0 deletions pages.ko/common/npm-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# npm list

> 이 명령어는 `npm ls`의 별칭 입니다.

- 원본 명령어의 문서 보기:

`tldr npm ls`
7 changes: 7 additions & 0 deletions pages.ko/linux/dnf5-group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# dnf5 group

> 이 명령어는 `dnf group`의 별칭 입니다.

- 원본 명령어의 문서 보기:

`tldr dnf group`
7 changes: 7 additions & 0 deletions pages.ko/linux/i386.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# i386

> 이 명령어는 `setarch i386`의 별칭 입니다.

- 원본 명령어의 문서 보기:

`tldr setarch`
7 changes: 7 additions & 0 deletions pages.ko/linux/linux32.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# linux32

> 이 명령어는 `setarch linux32`의 별칭 입니다.

- 원본 명령어의 문서 보기:

`tldr setarch`
7 changes: 7 additions & 0 deletions pages.ko/linux/linux64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# linux64

> 이 명령어는 `setarch linux64`의 별칭 입니다.

- 원본 명령어의 문서 보기:

`tldr setarch`
7 changes: 7 additions & 0 deletions pages.ko/linux/pacman-d.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pacman -D

> 이 명령어는 `pacman --database`의 별칭 입니다.

- 원본 명령어의 문서 보기:

`tldr pacman database`
7 changes: 7 additions & 0 deletions pages.ko/linux/pacman-f.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pacman -F

> 이 명령어는 `pacman --files`의 별칭 입니다.

- 원본 명령어의 문서 보기:

`tldr pacman files`
7 changes: 7 additions & 0 deletions pages.ko/linux/pacman-q.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pacman -Q

> 이 명령어는 `pacman --query`의 별칭 입니다.

- 원본 명령어의 문서 보기:

`tldr pacman query`
7 changes: 7 additions & 0 deletions pages.ko/linux/pacman-r.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pacman -R

> 이 명령어는 `pacman --remove`의 별칭 입니다.

- 원본 명령어의 문서 보기:

`tldr pacman remove`
7 changes: 7 additions & 0 deletions pages.ko/linux/pacman-s.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pacman -S

> 이 명령어는 `pacman --sync`의 별칭 입니다.

- 원본 명령어의 문서 보기:

`tldr pacman sync`
7 changes: 7 additions & 0 deletions pages.ko/linux/pacman-t.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pacman -T

> 이 명령어는 `pacman --deptest`의 별칭 입니다.

- 원본 명령어의 문서 보기:

`tldr pacman deptest`
7 changes: 7 additions & 0 deletions pages.ko/linux/pacman-u.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pacman -U

> 이 명령어는 `pacman --upgrade`의 별칭 입니다.

- 원본 명령어의 문서 보기:

`tldr pacman upgrade`
7 changes: 7 additions & 0 deletions pages.ko/linux/uname26.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# uname26

> 이 명령어는 `setarch uname26`의 별칭 입니다.

- 원본 명령어의 문서 보기:

`tldr setarch`
7 changes: 7 additions & 0 deletions pages.ko/linux/x86_64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# x86_64

> 이 명령어는 `setarch x86_64`의 별칭 입니다.

- 원본 명령어의 문서 보기:

`tldr setarch`
44 changes: 35 additions & 9 deletions scripts/set-alias-page.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,32 @@ def get_templates(root: Path):
return templates


def process_alias_and_command(template: str, alias_name: str, command: str) -> str:
"""
Process the template to replace 'example' with alias_name and command,
modifying the first dash to a space for the alias_name if needed.

Parameters:
template (str): The markdown template.
alias_name (str): The alias name to insert into the template.
command (str): The command name to insert into the template.

Returns:
str: The processed markdown template.
"""
# Modify alias_name: change the first dash to a space
if "-" in alias_name:
alias_name = alias_name.replace("-", " ", 1)

# Replace 'example' with the processed alias_name in the template
template = template.replace("example", alias_name, 1)

# Replace the remaining 'example' with the command
template = template.replace("example", command)

return template


def set_alias_page(
path: Path, command: str, dry_run: bool = False, language_to_update: str = ""
) -> str:
Expand All @@ -146,22 +172,22 @@ def set_alias_page(
if locale not in templates or (
language_to_update != "" and locale != language_to_update
):
# return empty status to indicate that no changes were made
return ""

alias_name = path.stem
text = (
templates[locale].replace("example", alias_name, 1).replace("example", command)
)
text = process_alias_and_command(templates[locale], alias_name, command)

# Test if the alias page already exists
line = re.search(r">.*", text).group(0).replace(command, "(.+)")
original_command = get_alias_page(path, line)
original_command = get_alias_command_in_page(path, line)
if original_command == command:
return ""

# Determine status based on whether the translation file already exists
status = get_status(
"added" if original_command == "" else "updated", dry_run, "page"
"added" if not path.exists() else "updated",
dry_run,
"page",
)

if not dry_run: # Only write to the path during a non-dry-run
Expand All @@ -172,7 +198,7 @@ def set_alias_page(
return status


def get_alias_page(path: Path, regex: str) -> str:
def get_alias_command_in_page(path: Path, regex: str) -> str:
"""
Determine whether the given path is an alias page.

Expand Down Expand Up @@ -276,9 +302,9 @@ def main():
if page.name not in IGNORE_FILES
]
for command in commands:
original_command = get_alias_page(
original_command = get_alias_command_in_page(
root / "pages" / command,
r"^> This command is an alias of `(.+)`\.$",
Zamoca42 marked this conversation as resolved.
Show resolved Hide resolved
r"> This command is an alias of(?: \w+)? `([^`]+)`(?:,.*)?",
)
if original_command != "":
target_paths += sync(
Expand Down
Loading