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

Commitc13a0ab

Browse files
josixmattwang44beccalzh
committed
feat: Add aider translation support
Co-Authored-By: Wei-Hsiang (Matt) Wang <mattwang44@gmail.com>Co-Authored-By: Becca <beccalin.8359@gmail.com>
1 parentc4c0d58 commitc13a0ab

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ venv/
1010
ENV/
1111
env.bak/
1212
venv.bak/
13+
.aider*

‎.scripts/intercept.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# /// script
2+
# dependencies = [
3+
# "polib",
4+
# ]
5+
# ///
6+
importargparse
7+
frompathlibimportPath
8+
9+
importpolib
10+
11+
12+
defget_pofile_from_path(path:Path)->polib.POFile:
13+
ifnotpath.exists():
14+
raiseValueError(f"The path '{path.absolute()}' does not exist!")
15+
16+
ifnot (path.is_file()andpath.suffix==".po"):
17+
raiseValueError(f"{path} doesn't seem to be a .po file")
18+
19+
try:
20+
pofile=polib.pofile(path)
21+
exceptOSError:
22+
raiseValueError(f"{path} doesn't seem to be a .po file")
23+
returnpofile
24+
25+
26+
if__name__=='__main__':
27+
parser=argparse.ArgumentParser()
28+
parser.add_argument(
29+
"path",
30+
help="the path of a PO file",
31+
)
32+
parser.add_argument("-n",'--occurrence_number',type=int,default=1)
33+
args=parser.parse_args()
34+
path=Path(args.path).resolve()
35+
pofile=get_pofile_from_path(path)
36+
occurrence_number=args.occurrence_number
37+
38+
forentryinpofile:
39+
ifnotany(path.steminpandint(n)==occurrence_numberforp,ninentry.occurrences):
40+
continue
41+
print(entry.msgid)
42+
break

‎Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ $(VENV)/bin/sphinx-lint: $(VENV)/bin/activate
100100
$(VENV)/bin/blurb:$(VENV)/bin/activate
101101
.$(VENV)/bin/activate; python3 -m pip install blurb
102102

103+
$(VENV)/bin/aider:$(VENV)/bin/activate
104+
.$(VENV)/bin/activate; python3 -m pip install aider-chat
105+
103106

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

162+
.PHONY: translate
163+
translate:$(VENV)/bin/aider## Run translation with aider. Usage: make translate FILE=path/to/file.po LINE=number
164+
@if [-z"$(FILE)" ]|| [-z"$(LINE)" ];then\
165+
echo"\x1B[1;31mError: Both FILE and LINE arguments are required.\x1B[0m";\
166+
echo"Usage: make translate FILE=path/to/file.po LINE=number";\
167+
exit 1;\
168+
fi
169+
$(eval MESSAGE=$(shell python3 .scripts/intercept.py$(FILE) -n$(LINE)))
170+
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)
171+
159172
# This allows us to accept extra arguments (by doing nothing when we get a job that doesn't match, rather than throwing an error)
160173
%:
161174
@:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp