Skip to content

Commit 4517374

Browse files
committed
doc(l10n): add AI agent instructions to review translations
Add a new "Reviewing po/XX.po" section to po/AGENTS.md that provides comprehensive guidance for AI agents to review translation files. The review workflow leverages git-po-helper subcommands: - git-po-helper compare: Extract new or changed entries between two PO file versions into a valid PO file for review. Supports multiple modes: * Compare HEAD with working tree (local changes) * Compare parent of commit with the commit (--commit) * Compare commit with working tree (--since) * Compare two arbitrary revisions (-r) - git-po-helper msg-select: Split large review files into smaller batches by entry index range for manageable review sessions. Supports range formats like "-50" (first 50), "51-100", "101-" (from 101 to end). The review procedure covers: 1. Extracting entries using git-po-helper compare 2. Handling large files with batch processing via git-po-helper msg-select 3. Step-by-step review against glossary and PO format rules 4. Outputting review reports in JSON format with issues and suggestions This enables AI agents to conduct structured translation reviews for: - Full file reviews - Changes in a specific commit - Changes since a specific commit Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
1 parent a600ccb commit 4517374

File tree

1 file changed

+206
-1
lines changed

1 file changed

+206
-1
lines changed

po/AGENTS.md

Lines changed: 206 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ most commonly used housekeeping tasks:
1010
1. Generating or updating po/git.pot
1111
2. Updating po/XX.po
1212
3. Translating po/XX.po
13+
4. Review translation quality
1314

1415

1516
## Background knowledge for localization workflows
@@ -186,6 +187,64 @@ When `msgfmt` reports an error, it provides the line number where the error
186187
was detected. Use this information to locate and fix the issue.
187188

188189

190+
#### Extracting full context for review
191+
192+
**This subsection is part of "Task 4: review translation quality".** Do not
193+
run it in isolation. Follow the full review flow strictly according to the
194+
steps in Task 4.
195+
196+
Plain `git diff` or `git show` can fragment and lose PO context, or mistakenly
197+
treat the whole file as the review scope, which does not match the intended
198+
review. **You MUST** use `git-po-helper compare` to generate the source file
199+
for translation review (redirect output to a file):
200+
201+
```shell
202+
# Review local changes (HEAD vs working tree)
203+
git-po-helper compare po/XX.po -o po/review.po
204+
205+
# Review changes in a specific commit (parent vs commit)
206+
git-po-helper compare --commit <commit> po/XX.po -o po/review.po
207+
208+
# Review changes since a commit (commit vs working tree)
209+
git-po-helper compare --since <commit> po/XX.po -o po/review.po
210+
211+
# Review between two commits
212+
git-po-helper compare -r <commit1>..<commit2> po/XX.po -o po/review.po
213+
214+
# Compare two worktree files
215+
git-po-helper compare po/XX-old.po po/XX-new.po -o po/review.po
216+
```
217+
218+
**Options summary**
219+
220+
| Option | Meaning |
221+
|---------------------|------------------------------------------------|
222+
| (none) | Compare HEAD with working tree (local changes) |
223+
| `--commit <commit>` | Compare parent of commit with the commit |
224+
| `--since <commit>` | Compare commit with working tree |
225+
| `-r x..y` | Compare revision x with revision y |
226+
| `-r x..` | Compare revision x with working tree |
227+
| `-r x` | Compare parent of x with x |
228+
229+
Output is empty when there are no new or changed entries; otherwise it
230+
includes a valid PO header.
231+
232+
233+
#### Splitting large PO file for review
234+
235+
When the review file is too large, use `git-po-helper msg-select` to split by
236+
entry index: 0 = header (default; use `--no-header` to omit), 1,2,3,... =
237+
content entries. Ranges: `--range "1-50"`, `--range "-50"` (first 50),
238+
`--range "51-"` (from 51 to end).
239+
240+
```shell
241+
git-po-helper msg-select --range "-50" po/review.po -o po/review-batch1.po
242+
git-po-helper msg-select --range "51-100" po/review.po -o po/review-batch2.po
243+
git-po-helper msg-select --range "101-" po/review.po -o po/review-batch3.po
244+
git-po-helper msg-select --range "1-50" --no-header po/review.po -o po/review-fragment.po
245+
```
246+
247+
189248
### Quality checklist
190249

191250
- **Accuracy**: Faithful to original meaning; no omissions or distortions.
@@ -520,6 +579,146 @@ For the full schema reference, see the "GETTEXT JSON File Format (Reference)"
520579
section in the msg-select JSON design document.
521580

522581

582+
### Task 4: Review translation quality
583+
584+
Review can target the full `po/XX.po`, a specific commit, or changes since a
585+
commit. When asked to review, follow the steps below. **Note**: Review uses
586+
`git-po-helper compare`; if `git-po-helper` is not available, this task
587+
cannot be performed.
588+
589+
1. **Check for existing review**: Run in order:
590+
591+
- If `po/review.po` does **not** exist, go to step 2 regardless of any other
592+
files (e.g. batch or JSON files).
593+
- If both `po/review.po` and `po/review.json` exist, go directly to the
594+
final step (Merge and summary) and display the report. Do **not** check
595+
for batch or other temporary files; no further review steps are needed.
596+
- If `po/review.po` exists but `po/review.json` does **not** exist, go to
597+
step 4 (Check batch files and select current batch) to continue the
598+
previous unfinished review.
599+
600+
2. **Extract entries**: Run `git-po-helper compare` with the desired range and
601+
redirect output to `po/review.po`. Do not use `git show` or `git diff`—they
602+
can fragment or lose PO context, or treat the whole file as the review scope
603+
(see "Extracting full context for review" above).
604+
605+
3. **Prepare review batches**: Run the script below to clean up any leftover
606+
files from previous reviews and split `po/review.po` into one or multiple
607+
`po/review-batch-<N>.po` files (dynamic batch sizing). Run as a single
608+
script (define the function, then call it):
609+
610+
```shell
611+
review_split_batches () {
612+
min_batch_size=${1:-50}
613+
rm -f po/review-batch-*.po
614+
rm -f po/review-batch-*.json
615+
rm -f po/review.json
616+
617+
ENTRY_COUNT=$(grep -c '^msgid ' po/review.po 2>/dev/null || true)
618+
ENTRY_COUNT=$((ENTRY_COUNT > 0 ? ENTRY_COUNT - 1 : 0))
619+
620+
if test "$ENTRY_COUNT" -gt $((min_batch_size * 2))
621+
then
622+
if test "$ENTRY_COUNT" -gt $((min_batch_size * 8))
623+
then
624+
NUM=$((min_batch_size * 2))
625+
elif test "$ENTRY_COUNT" -gt $((min_batch_size * 4))
626+
then
627+
NUM=$((min_batch_size + min_batch_size / 2))
628+
else
629+
NUM=$min_batch_size
630+
fi
631+
BATCH_COUNT=$(( (ENTRY_COUNT + NUM - 1) / NUM ))
632+
for i in $(seq 1 "$BATCH_COUNT")
633+
do
634+
START=$(((i - 1) * NUM + 1))
635+
END=$((i * NUM))
636+
if test "$END" -gt "$ENTRY_COUNT"
637+
then
638+
END=$ENTRY_COUNT
639+
fi
640+
if test "$i" -eq 1
641+
then
642+
git-po-helper msg-select --range "-$NUM" po/review.po -o "po/review-batch-$i.po"
643+
elif test "$END" -ge "$ENTRY_COUNT"
644+
then
645+
git-po-helper msg-select --range "$START-" po/review.po -o "po/review-batch-$i.po"
646+
else
647+
git-po-helper msg-select --range "$START-$END" po/review.po -o "po/review-batch-$i.po"
648+
fi
649+
done
650+
else
651+
cp po/review.po po/review-batch-1.po
652+
fi
653+
}
654+
review_split_batches 50
655+
```
656+
657+
4. **Check batch files and select current batch**: If no `po/review-batch-*.po`
658+
exist, proceed to step 9. Otherwise take the **first** remaining file
659+
(smallest <N>) as the current batch; in steps 5–8 "current batch file"
660+
means `po/review-batch-<N>.po`. Enables resume after an unexpected stop.
661+
662+
5. **Read context**: Use "Background knowledge for localization workflows"
663+
for PO format, placeholder rules, and terminology. If the current batch
664+
file has a glossary section, add it to your context.
665+
666+
6. **Review entries**:
667+
- Do not review or modify the header entry (empty `msgid`, metadata in
668+
`msgstr`).
669+
- For all other entries in the current batch file, check against "Quality
670+
checklist" above.
671+
- Apply corrections to `po/review.po` (not the batch file); the human
672+
translator decides whether to apply them to `po/XX.po`.
673+
- **Do NOT** remove `po/review.po` or `po/*.json`.
674+
675+
7. **Generate review report**:
676+
- Save the report for the current batch to `po/review-batch-<N>.json`.
677+
- Use the review JSON format below.
678+
- Only include entries with issues you found, perfect entries with score 3
679+
should not be included.
680+
- Optionally provide inline suggestions or a human-readable report.
681+
682+
8. **Repeat or finish**: After saving the JSON, delete
683+
`po/review-batch-<N>.po`. If no `po/review-batch-*.po` remain, proceed to
684+
step 9; otherwise repeat from step 4.
685+
686+
9. **Merge and summary**: Run `git-po-helper agent-run report` to merge all
687+
`po/review-batch-*.json` into `po/review.json` and display the result. Show
688+
the command output to the user. Do **not** open or read any JSON files; the
689+
user will refer to them as needed.
690+
691+
```shell
692+
git-po-helper agent-run report
693+
```
694+
695+
**Review JSON format.** Use the following structure:
696+
697+
```json
698+
{
699+
"issues": [
700+
{
701+
"msgid": "commit",
702+
"msgstr": "承诺",
703+
"score": 0,
704+
"description": "术语错误:'commit'应译为'提交'",
705+
"suggestion": "提交"
706+
},
707+
{
708+
"msgid": "repository",
709+
"msgstr": "仓库",
710+
"score": 2,
711+
"description": "一致性问题:其他地方使用'版本库'",
712+
"suggestion": "版本库"
713+
}
714+
]
715+
}
716+
```
717+
718+
- `issues`: Array of issues. Each issue: `msgid`, `msgstr`, `score`, `description`, `suggestion`.
719+
- `score`: 0 = critical (must fix before release), 1 = major (should fix), 2 = minor (improve later), 3 = perfect.
720+
721+
523722
## Human translators remain in control
524723

525724
Git translation is human-driven; language team leaders and contributors are
@@ -532,7 +731,13 @@ responsible for:
532731
- Building and maintaining language glossaries
533732
- Reviewing and approving all changes before submission
534733

535-
AI tools, if used, only accelerate routine tasks.
734+
AI tools, if used, only accelerate routine tasks:
735+
736+
- First-draft translations for new or updated messages
737+
- Finding untranslated or fuzzy entries
738+
- Checking consistency with glossary and existing translations
739+
- Detecting technical errors (placeholders, formatting)
740+
- Reviewing against quality criteria
536741

537742
AI-generated output should always be treated as rough drafts requiring human
538743
review, editing, and approval by someone who understands both the technical

0 commit comments

Comments
 (0)