Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Add aider translation support#1006

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
josix wants to merge3 commits into3.13
base:3.13
Choose a base branch
Loading
fromfeat/aider-translation
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
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
1 change: 1 addition & 0 deletions.gitignore
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,3 +10,4 @@ venv/
ENV/
env.bak/
venv.bak/
.aider*
52 changes: 52 additions & 0 deletions.scripts/intercept.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
"""
A utility script to extract message IDs from PO files.

This script extracts a specific message ID from a PO file based on the file name
and occurrence number. It's useful for retrieving translation strings for
specific occurrences in the Python documentation.

Usage:
python intercept.py path/to/file.po [-n OCCURRENCE_NUMBER]

Arguments:
path: Path to a PO file
-n, --occurrence_number: The occurrence number to match (default: 1)
"""
import argparse
from pathlib import Path

import polib


def get_pofile_from_path(path: Path) -> polib.POFile:
if not path.exists():
raise ValueError(f"The path '{path.absolute()}' does not exist!")

if not (path.is_file() and path.suffix == ".po"):
raise ValueError(f"{path} doesn't seem to be a .po file")

try:
pofile = polib.pofile(path)
except OSError:
raise ValueError(f"{path} doesn't seem to be a .po file")
return pofile


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description="Extract message IDs from PO files"
)
parser.add_argument("path", type=Path,
help="the path of a PO file")
parser.add_argument("-n", '--occurrence_number',
type=int, default=1, help="the occurrence number to match")
args = parser.parse_args()
path = args.path.resolve()
pofile = get_pofile_from_path(path)
occurrence_number = args.occurrence_number

for entry in pofile:
if not any(path.stem in p and int(n) == occurrence_number for p, n in entry.occurrences):
continue
print(entry.msgid)
break
13 changes: 13 additions & 0 deletionsMakefile
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,6 +100,9 @@ $(VENV)/bin/sphinx-lint: $(VENV)/bin/activate
$(VENV)/bin/blurb: $(VENV)/bin/activate
. $(VENV)/bin/activate; python3 -m pip install blurb

$(VENV)/bin/aider: $(VENV)/bin/activate
. $(VENV)/bin/activate; python3 -m pip install aider-chat


.PHONY: upgrade_venv
upgrade_venv: $(VENV)/bin/activate ## Upgrade the venv that compiles the doc
Expand DownExpand Up@@ -156,6 +159,16 @@ rm_cpython: ## Remove cloned cpython repo
lint: $(VENV)/bin/sphinx-lint ## Run sphinx-lint
$(VENV)/bin/sphinx-lint --enable default-role

.PHONY: translate
translate: $(VENV)/bin/aider ## Run translation with aider. Usage: make translate FILE=path/to/file.po LINE=number
@if [ -z "$(FILE)" ] || [ -z "$(LINE)" ]; then \
echo "\x1B[1;31mError: Both FILE and LINE arguments are required.\x1B[0m"; \
echo "Usage: make translate FILE=path/to/file.po LINE=number"; \
exit 1; \
fi
$(eval MESSAGE=$(shell python3 .scripts/intercept.py $(FILE) -n $(LINE)))
aider --no-auto-commits --message 'Translate the following Python documentation into Tranditional Chinese for $(FILE):$(LINE) with message $(MESSAGE). Ensure that the translation is accurate and uses appropriate technical terminology. The output must be in Traditional Chinese. Pay careful attention to context, idiomatic expressions, and any specialized vocabulary related to Python programming. Maintain the structure and format of the original documentation as much as possible to ensure clarity and usability for readers.' $(FILE)

# This allows us to accept extra arguments (by doing nothing when we get a job that doesn't match, rather than throwing an error)
%:
@:

[8]ページ先頭

©2009-2025 Movatter.jp