interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / po / AGENTS.md

888 lines · 33687 bytes Raw Blame History Rendered
1# Instructions for AI Agents
2
3This file gives specific instructions for AI agents that perform
4housekeeping tasks for Git l10n. Use of AI is optional; many successful
5l10n teams work well without it.
6
7The section "Housekeeping tasks for localization workflows" documents the
8most commonly used housekeeping tasks:
9
101. Generating or updating po/git.pot
112. Updating po/XX.po
123. Translating po/XX.po
134. Reviewing translation quality
14
15
16## Background knowledge for localization workflows
17
18Essential background for the workflows below; understand these concepts before
19performing any housekeeping tasks in this document.
20
21### Language code and notation (XX, ll, ll\_CC)
22
23**XX** is a placeholder for the language code: either `ll` (ISO 639) or
24`ll_CC` (e.g. `de`, `zh_CN`). It appears in the PO file header metadata
25(e.g. `"Language: zh_CN\n"`) and is typically used to name the PO file:
26`po/XX.po`.
27
28
29### Header Entry
30
31The **header entry** is the first entry in every `po/XX.po`. It has an empty
32`msgid`; translation metadata (project, language, plural rules, encoding, etc.)
33is stored in `msgstr`, as in this example:
34
35```po
36msgid ""
37msgstr ""
38"Project-Id-Version: Git\n"
39"Language: zh_CN\n"
40"MIME-Version: 1.0\n"
41"Content-Type: text/plain; charset=UTF-8\n"
42"Content-Transfer-Encoding: 8bit\n"
43"Plural-Forms: nplurals=2; plural=(n != 1);\n"
44```
45
46**CRITICAL**: Do not edit the header's `msgstr` while translating. It holds
47metadata only and must be left unchanged.
48
49
50### Glossary Section
51
52PO files may have a glossary in comments before the header entry (first
53`msgid ""`), giving terminology guidelines (e.g.):
54
55```po
56# Git glossary for Chinese translators
57#
58# English | Chinese
59# ---------------------------------+--------------------------------------
60# 3-way merge | 三路合并
61# ...
62```
63
64**IMPORTANT**: Read and use the glossary when translating or reviewing. It is
65in `#` comments only. Leave that comment block unchanged.
66
67
68### PO entry structure (single-line and multi-line)
69
70PO entries are `msgid` / `msgstr` pairs. Plural messages add `msgid_plural` and
71`msgstr[n]`. The `msgid` is the immutable source; `msgstr` is the target
72translation. Each side may be a single quoted string or a multi-line block.
73In the multi-line form the header line is often `msgid ""` / `msgstr ""`, with
74the real text split across following quoted lines (concatenated by Gettext).
75
76**Single-line entries**:
77
78```po
79msgid "commit message"
80msgstr "提交说明"
81```
82
83**Multi-line entries**:
84
85```po
86msgid ""
87"Line 1\n"
88"Line 2"
89msgstr ""
90"行 1\n"
91"行 2"
92```
93
94**CRITICAL**: Do **not** use `grep '^msgstr ""'` to find untranslated entries;
95multi-line `msgstr` blocks use the same opening line, so grep gives false
96positives. Use `git-po-helper msg-select` with `--untranslated` / `--fuzzy`
97(see Task 3), or `msgattrib` (e.g. `--untranslated`, `--only-fuzzy`,
98`--obsolete`).
99
100
101### Translating fuzzy entries
102
103Fuzzy entries need re-translation because the source text changed. The format
104differs by file type:
105
106- **PO file**: A `#, fuzzy` tag in the entry comments marks the entry as fuzzy.
107- **JSON file**: The entry has `"fuzzy": true`.
108
109**Translation principles**: Re-translate the `msgstr` (and, for plural entries,
110`msgstr[n]`) into the target language. Do **not** modify `msgid` or
111`msgid_plural`. After translation, **clear the fuzzy mark**: in PO, remove the
112`#, fuzzy` tag from comments; in JSON, omit or set `fuzzy` to `false`.
113
114
115### Preserving Special Characters
116
117Preserve escape sequences (`\n`, `\"`, `\\`, `\t`), placeholders (`%s`, `%d`,
118etc.), and quotes exactly as in `msgid`. Only reorder placeholders with
119positional syntax when needed (see Placeholder Reordering below).
120
121
122### Preserving Quotation Marks
123
124Some languages use language-specific UTF-8 quotation marks (curly/smart
125quotes) rather than ASCII straight quotes. **Always preserve these
126characters exactly as they appear in the source.** Do **not** convert them
127to ASCII straight quotes.
128
129**Protected quotation marks** (non-exhaustive list):
130
131| Character | Unicode | Name | Languages |
132|-----------|---------|------|-----------|
133| „ | U+201E | DOUBLE LOW-9 QUOTATION MARK | Bulgarian, German, etc. |
134| " | U+201C | LEFT DOUBLE QUOTATION MARK | Bulgarian, etc. |
135| " | U+201D | RIGHT DOUBLE QUOTATION MARK | English, German, etc. |
136| ' | U+2018 | LEFT SINGLE QUOTATION MARK | English, etc. |
137| ' | U+2019 | RIGHT SINGLE QUOTATION MARK | English, etc. |
138| « | U+00AB | LEFT-POINTING DOUBLE ANGLE QUOTATION MARK | French, Russian, etc. |
139| » | U+00BB | RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK | French, Russian, etc. |
140| ‹ | U+2039 | SINGLE LEFT-POINTING ANGLE QUOTATION MARK | French, etc. |
141| › | U+203A | SINGLE RIGHT-POINTING ANGLE QUOTATION MARK | French, etc. |
142
143**Why this matters in PO files**: In PO file format, the ASCII straight
144double quote `"` (U+0022) is the **string delimiter**. If a translation
145contains a curly quote that is incorrectly converted to `"` (U+0022),
146the PO parser will interpret it as the end of the string, causing:
147
1481. **String truncation**: The `msgstr` value is cut short at the
149 spurious quote character.
1502. **Syntax errors**: `msgfmt --check` fails with parse errors at
151 the line where the string was prematurely terminated.
1523. **Data loss**: Content after the accidental quote delimiter is
153 misinterpreted or lost.
154
155**Rules**:
156
157- **Never** replace language-specific quotation marks with ASCII
158 straight quotes `"` (U+0022) or `'` (U+0027).
159- Apply this rule when translating PO files, PO multi-line strings,
160 and GETTEXT JSON `msgstr` array values.
161- Apply this rule when generating suggested translations
162 (`suggest_msgstr`) during review.
163- If the source `msgid` uses ASCII straight quotes, preserve them
164 as-is in the translation unless the target language convention
165 requires different quotation marks.
166
167
168### Placeholder Reordering
169
170When reordering placeholders relative to `msgid`, use positional syntax (`%n$`)
171where *n* is the 1-based argument index, so each argument still binds to the
172right value. Preserve width and precision modifiers, and place `%n$` before
173them (see examples below).
174
175**Example 1** (placeholder reordering with precision):
176
177```po
178msgid "missing environment variable '%s' for configuration '%.*s'"
179msgstr "配置 '%3$.*2$s' 缺少环境变量 '%1$s'"
180```
181
182`%s` → argument 1 → `%1$s`. `%.*s` needs precision (arg 2) and string (arg 3) →
183`%3$.*2$s`.
184
185**Example 2** (multi-line, four `%s` reordered):
186
187```po
188msgid ""
189"Path updated: %s renamed to %s in %s, inside a directory that was renamed in "
190"%s; moving it to %s."
191msgstr ""
192"路径已更新:%1$s 在 %3$s 中被重命名为 %2$s,而其所在目录又在 %4$s 中被重命"
193"名,因此将其移动到 %5$s。"
194```
195
196Original order 1,2,3,4,5; in translation 1,3,2,4,5. Each line must be a
197complete quoted string.
198
199**Example 3** (no placeholder reordering):
200
201```po
202msgid "MIDX %s must be an ancestor of %s"
203msgstr "MIDX %s 必须是 %s 的祖先"
204```
205
206Argument order is still 1,2 in translation, so `%n$` is not needed.
207If no placeholder reordering occurs, you **must not** introduce `%n$`
208syntax; keep the original non-positional placeholders (`%s`, `%d`, etc.).
209
210
211### Validating PO File Format
212
213Check the PO file using the command below:
214
215```shell
216msgfmt --check -o /dev/null po/XX.po
217```
218
219Common validation errors include:
220- Unclosed quotes
221- Missing escape sequences
222- Invalid placeholder syntax
223- Malformed multi-line entries
224- Incorrect line breaks in multi-line strings
225
226On failure, `msgfmt` prints the line number; fix the PO at that line.
227
228
229### Using git-po-helper
230
231[git-po-helper](https://github.com/git-l10n/git-po-helper) supports Git l10n with
232**quality checking** (git-l10n PR conventions) and **AI-assisted translation**
233(subcommands for automated workflows). Task 3 (translating) and Task 4
234(reviewing) **require** `git-po-helper` **>= 0.9.1**. Task 1 and Task 2 use
235`make` / gettext tooling instead.
236
237**Version check**: Before Task 3 or Task 4, run:
238
239```shell
240git-po-helper version --ge 0.9.1
241```
242
243If the command is missing or the exit status is non-zero, print the error (use
244the command's own output when available) and **refuse** the task; do not
245continue.
246
247
248#### Splitting large PO files
249
250When a PO file is too large for translation or review, use `git-po-helper
251msg-select` to split it by entry index.
252
253- **Entry 0** is the header (included by default; use `--no-header` to omit).
254- **Entries 1, 2, 3, …** are content entries.
255- **Range format**: `--range "1-50"` (entries 1 through 50), `--range "-50"`
256 (first 50 entries), `--range "51-"` (from entry 51 to end). Shortcuts:
257 `--head N` (first N), `--tail N` (last N), `--since N` (from N to end).
258- **Output format**: PO by default; use `--json` for GETTEXT JSON. See the
259 "GETTEXT JSON format" section (under git-po-helper) for details.
260- **State filter**: Use `--translated`, `--untranslated`, `--fuzzy` to filter
261 by state (OR relationship). Use `--no-obsolete` to exclude obsolete entries;
262 `--with-obsolete` to include (default). Use `--only-same` or `--only-obsolete`
263 for a single state. Range applies to the filtered list.
264
265```shell
266# First 50 entries (header + entries 1–50)
267git-po-helper msg-select --range "-50" po/in.po -o po/out.po
268
269# Entries 51–100
270git-po-helper msg-select --range "51-100" po/in.po -o po/out.po
271
272# Entries 101 to end
273git-po-helper msg-select --range "101-" po/in.po -o po/out.po
274
275# Entries 1–50 without header (content only)
276git-po-helper msg-select --range "1-50" --no-header po/in.po -o po/frag.po
277
278# Output as JSON; select untranslated and fuzzy entries, exclude obsolete
279git-po-helper msg-select --json --untranslated --fuzzy --no-obsolete po/in.po >po/filtered.json
280```
281
282
283#### Comparing PO files for translation and review
284
285`git-po-helper compare` shows PO changes with full entry context (unlike
286`git diff`). Redirect output to a file: it is empty when there are no new or
287changed entries; otherwise it contains a valid PO header.
288
289```shell
290# Get full context of local changes (HEAD vs working tree)
291git-po-helper compare po/XX.po -o po/out.po
292
293# Get full context of changes in a specific commit (parent vs commit)
294git-po-helper compare --json --commit <commit> po/XX.po -o po/out.json
295
296# Get full context of changes since a commit (commit vs working tree)
297git-po-helper compare --json --since <commit> po/XX.po -o po/out.json
298
299# Get full context between two commits
300git-po-helper compare -r <commit1>..<commit2> po/XX.po -o po/out.po
301
302# Get full context of two worktree files
303git-po-helper compare po/old.po po/new.po -o po/out.po
304
305# Check msgid consistency (detect tampering); no output means target matches source
306git-po-helper compare --msgid po/old.po po/new.po >po/out.po
307```
308
309**Options summary**
310
311| Option | Meaning |
312|---------------------|------------------------------------------------|
313| (none) | Compare HEAD with working tree (local changes) |
314| `--commit <commit>` | Compare parent of commit with the commit |
315| `--since <commit>` | Compare commit with working tree |
316| `-r x..y` | Compare revision x with revision y |
317| `-r x..` | Compare revision x with working tree |
318| `-r x` | Compare parent of x with x |
319
320
321#### Concatenating multiple PO/JSON files
322
323`git-po-helper msg-cat` merges PO, POT, or gettext JSON inputs into one stream.
324Duplicate `msgid` values keep the first occurrence in file order. Write with
325`-o <file>` or stdout (`-o -` or omit); `--json` selects JSON output, else PO.
326
327```shell
328# Convert JSON to PO (e.g. after translation)
329git-po-helper msg-cat --unset-fuzzy -o po/out.po po/in.json
330
331# Merge multiple PO files
332git-po-helper msg-cat -o po/out.po po/in-1.po po/in-2.json
333```
334
335
336#### GETTEXT JSON format
337
338The **GETTEXT JSON** format is an internal format defined by `git-po-helper`
339for convenient batch processing of translation and related tasks by AI models.
340`git-po-helper msg-select`, `git-po-helper msg-cat`, and `git-po-helper compare`
341read and write this format.
342
343**Top-level structure**:
344
345```json
346{
347 "header_comment": "string",
348 "header_meta": "string",
349 "entries": [ /* array of entry objects */ ]
350}
351```
352
353| Field | Description |
354|------------------|--------------------------------------------------------------------------------|
355| `header_comment` | Lines above the first `msgid ""` (comments, glossary), directly concatenated. |
356| `header_meta` | Encoded `msgstr` of the header entry (Project-Id-Version, Plural-Forms, etc.). |
357| `entries` | List of PO entries. Order matches source. |
358
359**Entry object** (each element of `entries`):
360
361| Field | Type | Description |
362|-----------------|----------|--------------------------------------------------------------|
363| `msgid` | string | Singular message ID. PO escapes encoded (e.g. `\n` → `\\n`). |
364| `msgstr` | []string | Translation forms as a **JSON array only**. Details below. |
365| `msgid_plural` | string | Plural form of msgid. Omit for non-plural. |
366| `comments` | []string | Comment lines (`#`, `#.`, `#:`, `#,`, etc.). |
367| `fuzzy` | bool | True if entry has fuzzy flag. |
368| `obsolete` | bool | True for `#~` obsolete entries. Omit if false. |
369
370**`msgstr` array (required shape)**:
371
372- **Always** a JSON array of strings, never a single string. One element = singular
373 (PO `msgstr` / `msgstr[0]`); multiple elements = plural forms in order
374 (`msgstr[0]`, `msgstr[1]`, …).
375- Omit the key or use an empty array when the entry is untranslated.
376
377**Example (single-line entry)**:
378
379```json
380{
381 "header_comment": "# Glossary:\\n# term1\\tTranslation 1\\n#\\n",
382 "header_meta": "Project-Id-Version: git\\nContent-Type: text/plain; charset=UTF-8\\n",
383 "entries": [
384 {
385 "msgid": "Hello",
386 "msgstr": ["你好"],
387 "comments": ["#. Comment for translator\\n", "#: src/file.c:10\\n"],
388 "fuzzy": false
389 }
390 ]
391}
392```
393
394**Example (plural entry)**:
395
396```json
397{
398 "msgid": "One file",
399 "msgid_plural": "%d files",
400 "msgstr": ["一个文件", "%d 个文件"],
401 "comments": ["#, c-format\\n"]
402}
403```
404
405**Example (fuzzy entry before translation)**:
406
407```json
408{
409 "msgid": "Old message",
410 "msgstr": ["旧翻译。"],
411 "comments": ["#, fuzzy\\n"],
412 "fuzzy": true
413}
414```
415
416**Translation notes for GETTEXT JSON files**:
417
418- **Preserve structure**: Keep `header_comment`, `header_meta`, `msgid`,
419 `msgid_plural` unchanged.
420- **Fuzzy entries**: Entries extracted from fuzzy PO entries have `"fuzzy": true`.
421 After translating, **remove the `fuzzy` field** or set it to `false` in the
422 output JSON. The merge step uses `--unset-fuzzy`, which can also remove the
423 `fuzzy` field.
424- **Placeholders**: Preserve `%s`, `%d`, etc. exactly; use `%n$` when
425 reordering (see "Placeholder Reordering" above).
426
427
428### Quality checklist
429
430- **Accuracy**: Faithful to original meaning; no omissions or distortions.
431- **Fuzzy entries**: Re-translate fully and clear the fuzzy flag (see
432 "Translating fuzzy entries" above).
433- **Terminology**: Consistent with glossary (see "Glossary Section" above) or
434 domain standards.
435- **Grammar and fluency**: Correct and natural in the target language.
436- **Placeholders**: Preserve variables (`%s`, `{name}`, `$1`) exactly; use
437 positional parameters when reordering (see "Placeholder Reordering" above).
438- **Special characters**: Preserve escape sequences (`\n`, `\"`, `\\`, `\t`),
439 placeholders exactly as in `msgid`. Preserve language-specific quotation
440 marks (curly/smart quotes like „, ", ", ', ') — do not convert them to
441 ASCII straight quotes. See "Preserving Special Characters" and
442 "Preserving Quotation Marks" above.
443- **Plurals and gender**: Correct forms and agreement.
444- **Context fit**: Suitable for UI space, tone, and use (e.g. error vs. tooltip).
445- **Cultural appropriateness**: No offensive or ambiguous content.
446- **Consistency**: Match prior translations of the same source.
447- **Technical integrity**: Do not translate code, paths, commands, brands, or
448 proper nouns.
449- **Readability**: Clear, concise, and user-friendly.
450
451
452## Housekeeping tasks for localization workflows
453
454For common housekeeping tasks, follow the steps in the matching subsection
455below.
456
457
458### Task 1: Generating or updating po/git.pot
459
460When asked to generate or update `po/git.pot` (or the like):
461
4621. **Directly execute** the command `make po/git.pot` without checking
463 if the file exists beforehand.
464
4652. **Do not verify** the generated file after execution. Simply run the
466 command and consider the task complete.
467
468
469### Task 2: Updating po/XX.po
470
471When asked to update `po/XX.po` (or the like):
472
4731. **Directly execute** the command `make po-update PO_FILE=po/XX.po`
474 without reading or checking the file content beforehand.
475
4762. **Do not verify, translate, or review** the updated file after execution.
477 Simply run the command and consider the task complete.
478
479
480### Task 3: Translating po/XX.po
481
482To translate `po/XX.po`, use the steps below. **Require** `git-po-helper` (see
483"Using git-po-helper" for the version check); without a passing check, refuse
484the task. Batches are GETTEXT JSON for translation.
485
486**Workflow loop**: Steps 1→2→3→4→5→6→7 form a loop. After step 6 succeeds,
487**always** go to step 7, which returns to step 1. The **only** exit to step 8
488is when step 2 finds `po/l10n-pending.json` empty. Do not skip step 7 or jump to
489step 8 after step 6.
490
4911. **Extract entries to translate**: **Directly execute** the script below—it is
492 authoritative; do not reimplement. It generates `po/l10n-pending.json` with
493 messages that need translation.
494
495 ```shell
496 l10n_extract_pending () {
497 test $# -ge 1 || { echo "Usage: l10n_extract_pending <po-file>" >&2; return 1; }
498 PO_FILE="$1"
499 PENDING="po/l10n-pending.json"
500 rm -f "$PENDING"
501
502 git-po-helper msg-select --json --untranslated --fuzzy --no-obsolete -o "$PENDING" "$PO_FILE"
503 ENTRY_COUNT=$(git-po-helper stat -c "$PENDING" 2>/dev/null || true)
504 ENTRY_COUNT=${ENTRY_COUNT:-0}
505 if test "$ENTRY_COUNT" -gt 0
506 then
507 git-po-helper stat "$PENDING" || true
508 echo "Pending file is not empty; there are still entries to translate."
509 else
510 echo "No entries need translation."
511 return 1
512 fi
513 }
514 # Run the extraction. Example: l10n_extract_pending po/zh_CN.po
515 l10n_extract_pending po/XX.po
516 ```
517
5182. **Check generated file**: If `po/l10n-pending.json` has no content entries
519 (or does not exist), translation is complete; go to step 8. Otherwise proceed
520 to step 3.
521
5223. **Prepare one batch for translation**: Batching keeps each run small so the
523 model can complete translation within limited context. **BEFORE translating**,
524 **directly execute** the script below—it is authoritative; do not reimplement.
525 It writes `po/l10n-todo.json`; then go to step 4.
526
527 ```shell
528 l10n_one_batch () {
529 test $# -ge 1 || { echo "Usage: l10n_one_batch <po-file> [min_batch_size]" >&2; return 1; }
530 PO_FILE="$1"
531 min_batch_size=${2:-100}
532 PENDING="po/l10n-pending.json"
533 TODO_JSON="po/l10n-todo.json"
534 DONE_JSON="po/l10n-done.json"
535 DONE_PO_TMP="po/l10n-done.po.tmp"
536 rm -f "$TODO_JSON" "$DONE_JSON" "$DONE_PO_TMP"
537
538 ENTRY_COUNT=$(git-po-helper stat -c "$PENDING" 2>/dev/null || true)
539 ENTRY_COUNT=${ENTRY_COUNT:-0}
540 if test "$ENTRY_COUNT" -gt $min_batch_size
541 then
542 if test "$ENTRY_COUNT" -gt $((min_batch_size * 8))
543 then
544 NUM=$((min_batch_size * 2))
545 elif test "$ENTRY_COUNT" -gt $((min_batch_size * 4))
546 then
547 NUM=$((min_batch_size + min_batch_size / 2))
548 else
549 NUM=$min_batch_size
550 fi
551 git-po-helper msg-select --json --head "$NUM" -o "$TODO_JSON" "$PENDING"
552 echo "Processing batch of $NUM entries (out of $ENTRY_COUNT remaining)"
553 else
554 git-po-helper msg-select --json -o "$TODO_JSON" "$PENDING"
555 echo "Processing all $ENTRY_COUNT entries at once"
556 fi
557 }
558 # Prepare one batch; shrink 2nd arg when batches exceed agent capacity.
559 l10n_one_batch po/XX.po 100
560 ```
561
5624. **Translate JSON batch** (`po/l10n-todo.json` → `po/l10n-done.json`):
563
564 - **Task**: Translate `po/l10n-todo.json` (input, GETTEXT JSON) into
565 `po/l10n-done.json` (output, GETTEXT JSON). See the "GETTEXT JSON format"
566 section above for format details and translation rules.
567 - **Reference glossary**: Read the glossary from the batch file's
568 `header_comment` (see "Glossary Section" above) and use it for
569 consistent terminology.
570 - **When translating**: Follow the "Quality checklist" above for correctness
571 and quality. Handle escape sequences (`\n`, `\"`, `\\`, `\t`), placeholders,
572 and quotes correctly as in `msgid`. For JSON, correctly escape and unescape
573 these sequences when reading and writing. Modify `msgstr` and `msgstr[n]`
574 (for plural entries); clear the fuzzy flag (omit or set `fuzzy` to `false`).
575 Do **not** modify `msgid` or `msgid_plural`.
576
5775. **Validate `po/l10n-done.po.tmp`**:
578
579 Run the validation script below. If it fails, fix per the errors and notes,
580 re-run until it succeeds.
581
582 ```shell
583 l10n_validate_done () {
584 DONE_PO_TMP="po/l10n-done.po.tmp"
585 DONE_JSON="po/l10n-done.json"
586 PENDING="po/l10n-pending.json"
587
588 if test -f "$DONE_JSON" && { ! test -f "$DONE_PO_TMP" || test "$DONE_JSON" -nt "$DONE_PO_TMP"; }
589 then
590 git-po-helper msg-cat --unset-fuzzy -o "$DONE_PO_TMP" "$DONE_JSON" || {
591 echo "ERROR [JSON to PO conversion]: Fix $DONE_JSON and re-run." >&2
592 return 1
593 }
594 fi
595
596 # Check 1: msgid should not be modified
597 MSGID_OUT=$(git-po-helper compare -q --msgid --assert-no-changes \
598 "$PENDING" "$DONE_PO_TMP" 2>&1)
599 MSGID_RC=$?
600 if test $MSGID_RC -ne 0 || test -n "$MSGID_OUT"
601 then
602 echo "ERROR [msgid modified]: The following entries appeared after" >&2
603 echo "translation because msgid was altered. Fix in $DONE_PO_TMP." >&2
604 echo "$MSGID_OUT" >&2
605 return 1
606 fi
607
608 # Check 2: PO format (see "Validating PO File Format" for error handling)
609 MSGFMT_OUT=$(msgfmt --check -o /dev/null "$DONE_PO_TMP" 2>&1)
610 MSGFMT_RC=$?
611 if test $MSGFMT_RC -ne 0
612 then
613 echo "ERROR [PO format]: Fix errors in $DONE_PO_TMP." >&2
614 echo "$MSGFMT_OUT" >&2
615 return 1
616 fi
617
618 echo "Validation passed."
619 }
620 l10n_validate_done
621 ```
622
623 If the script fails, fix **directly in `po/l10n-done.po.tmp`**. Re-run
624 `l10n_validate_done` until it succeeds. Editing `po/l10n-done.json` is not
625 recommended because it adds an extra JSON-to-PO conversion step. Use the
626 error message to decide:
627
628 - **`[msgid modified]`**: The listed entries have altered `msgid`; restore
629 them to match `po/l10n-pending.json`.
630 - **`[PO format]`**: `msgfmt` reports line numbers; fix the errors in place.
631 See "Validating PO File Format" for common issues.
632
633
6346. **Merge translation results into `po/XX.po`**: Run the script below. If it
635 fails, fix the file the error names: **`[JSON to PO conversion]`** →
636 `po/l10n-done.json`; **`[msgcat merge]`** → `po/l10n-done.po.tmp`. Re-run until
637 it succeeds.
638
639 ```shell
640 l10n_merge_batch () {
641 test $# -ge 1 || { echo "Usage: l10n_merge_batch <po-file>" >&2; return 1; }
642 PO_FILE="$1"
643 DONE_PO_TMP="po/l10n-done.po.tmp"
644 DONE_JSON="po/l10n-done.json"
645 MERGED="po/l10n-done.merged"
646 TODO_JSON="po/l10n-todo.json"
647 if test -f "$DONE_JSON" && { ! test -f "$DONE_PO_TMP" || test "$DONE_JSON" -nt "$DONE_PO_TMP"; }
648 then
649 git-po-helper msg-cat --unset-fuzzy -o "$DONE_PO_TMP" "$DONE_JSON" || {
650 echo "ERROR [JSON to PO conversion]: Fix $DONE_JSON and re-run." >&2
651 return 1
652 }
653 fi
654 msgcat --use-first "$DONE_PO_TMP" "$PO_FILE" >"$MERGED" || {
655 echo "ERROR [msgcat merge]: Fix errors in $DONE_PO_TMP and re-run." >&2
656 return 1
657 }
658 mv "$MERGED" "$PO_FILE"
659 rm -f "$TODO_JSON" "$DONE_JSON" "$DONE_PO_TMP"
660 }
661 # Run the merge. Example: l10n_merge_batch po/zh_CN.po
662 l10n_merge_batch po/XX.po
663 ```
664
6657. **Loop**: **MUST** return to step 1 (Extract entries) and repeat the cycle.
666 Do **not** skip this step or go to step 8. Step 8 (below) runs **only**
667 when step 2 finds no more entries and redirects there.
668
6698. **Only after loop exits**: Run the command below to validate the PO file and
670 display the report. The process ends here.
671
672 ```shell
673 msgfmt --check --stat -o /dev/null po/XX.po
674 ```
675
676
677### Task 4: Review translation quality
678
679Review may target the full `po/XX.po`, a specific commit, or changes since a
680commit. When asked to review, follow the steps below.
681
682**Workflow**: Follow steps in order. Do **NOT** use `git show`, `git diff`,
683`git format-patch`, or similar to get changes—they break PO context; use **only**
684`git-po-helper compare` for extraction. **Require** `git-po-helper` (see
685"Using git-po-helper" for the version check); without a passing check, refuse
686the task. Steps 3→4→5→6→7 loop: after step 6, **always** go to step 7 (back to
687step 3). The **only** ways to step 8 are when step 4 finds `po/review-todo.json`
688missing or empty (no batch left to review), or when step 1 finds
689`po/review-result.json` already present.
690
6911. **Check for existing review (resume support)**: Evaluate the following in order:
692
693 - If `po/review-input.json` does **not** exist, proceed to step 2 (Extract
694 entries) for a fresh start.
695 - Else If `po/review-result.json` exists, go to step 8 (only after loop exits).
696 - Else If `po/review-done.json` exists, go to step 6 (Rename result).
697 - Else if `po/review-todo.json` exists, go to step 5 (Review the current
698 batch).
699 - Else go to step 3 (Prepare one batch).
700
7012. **Extract entries**: Run `git-po-helper compare --json` with the desired range
702 and write the output to `po/review-input.json` (use `-o`). See "Comparing PO
703 files for translation and review" under git-po-helper for options.
704
7053. **Prepare one batch**: Batching keeps each run small so the model can
706 complete review within limited context. **Directly execute** the script
707 below—it is authoritative; do not reimplement.
708
709 ```shell
710 review_one_batch () {
711 min_batch_size=${1:-100}
712 INPUT_JSON="po/review-input.json"
713 PENDING="po/review-pending.json"
714 TODO="po/review-todo.json"
715 DONE="po/review-done.json"
716 BATCH_FILE="po/review-batch.txt"
717
718 if test ! -f "$INPUT_JSON"
719 then
720 rm -f "$TODO"
721 echo >&2 "cannot find $INPUT_JSON, nothing for review"
722 return 1
723 fi
724 if test ! -f "$PENDING" || test "$INPUT_JSON" -nt "$PENDING"
725 then
726 # zsh aborts on unmatched globs; allow empty expansion here.
727 if test -n "$ZSH_VERSION"
728 then
729 setopt local_options null_glob
730 fi
731 rm -f po/review-result*.json
732 rm -f "$BATCH_FILE" "$TODO" "$DONE"
733 cp "$INPUT_JSON" "$PENDING"
734 fi
735
736 ENTRY_COUNT=$(git-po-helper stat -c "$PENDING" 2>/dev/null || true)
737 ENTRY_COUNT=${ENTRY_COUNT:-0}
738 if test "$ENTRY_COUNT" -eq 0
739 then
740 rm -f "$TODO"
741 echo >&2 "No entries left for review"
742 return 1
743 fi
744
745 if test "$ENTRY_COUNT" -gt $min_batch_size
746 then
747 if test "$ENTRY_COUNT" -gt $((min_batch_size * 8))
748 then
749 NUM=$((min_batch_size * 2))
750 elif test "$ENTRY_COUNT" -gt $((min_batch_size * 4))
751 then
752 NUM=$((min_batch_size + min_batch_size / 2))
753 else
754 NUM=$min_batch_size
755 fi
756 else
757 NUM=$ENTRY_COUNT
758 fi
759
760 BATCH=$(cat "$BATCH_FILE" 2>/dev/null || true)
761 BATCH=${BATCH:-0}
762 BATCH=$((BATCH + 1))
763 echo "$BATCH" >"$BATCH_FILE"
764
765 git-po-helper msg-select --json --head "$NUM" -o "$TODO" "$PENDING"
766 git-po-helper msg-select --json --since "$((NUM + 1))" -o "${PENDING}.tmp" "$PENDING"
767 mv "${PENDING}.tmp" "$PENDING"
768 echo "Processing batch $BATCH ($NUM entries out of $ENTRY_COUNT)"
769 }
770 # The parameter controls batch size; reduce if the batch file is too large.
771 review_one_batch 100
772 ```
773
7744. **Check todo file**: If `po/review-todo.json` does not exist or is empty,
775 review is complete; go to step 8 (only after loop exits). Otherwise proceed to
776 step 5.
777
7785. **Review the current batch**: Review translations in `po/review-todo.json`
779 and write findings to `po/review-done.json` as follows:
780 - Use "Background knowledge for localization workflows" for PO/JSON structure,
781 placeholders, and terminology.
782 - If `header_comment` includes a glossary, follow it for consistency.
783 - Do **not** review the header (`header_comment`, `header_meta`).
784 - For every other entry, check the entry's `msgstr` **array** (translation
785 forms) against `msgid` / `msgid_plural` using the "Quality checklist" above.
786 - Write JSON per "Review result JSON format" below; use `{"issues": []}` when
787 there are no issues. **Always** write `po/review-done.json`—it marks the
788 batch complete.
789
7906. **Rename result**: Rename `po/review-done.json` to `po/review-result-<N>.json`,
791 where N is the value in `po/review-batch.txt` (the batch just completed).
792 Run the script below:
793
794 ```shell
795 review_rename_result () {
796 TODO="po/review-todo.json"
797 DONE="po/review-done.json"
798 BATCH_FILE="po/review-batch.txt"
799 if test -f "$DONE"
800 then
801 N=$(cat "$BATCH_FILE" 2>/dev/null) || { echo "ERROR: $BATCH_FILE not found." >&2; return 1; }
802 mv "$DONE" "po/review-result-$N.json"
803 echo "Renamed to po/review-result-$N.json"
804 fi
805 rm -f "$TODO"
806 }
807 review_rename_result
808 ```
809
8107. **Loop**: **MUST** return to step 3 (Prepare one batch) and repeat the cycle.
811 Do **not** skip this step or go to step 8. Step 8 is reached **only** when
812 step 4 finds `po/review-todo.json` missing or empty.
813
8148. **Only after loop exits**: **Directly execute** the command below. It merges
815 results, applies suggestions, and displays the report. The process ends here.
816
817 ```shell
818 git-po-helper agent-run review --report po
819 ```
820
821 **Do not** run cleanup or delete intermediate files. Keep them for inspection
822 or resumption.
823
824**Review result JSON format**:
825
826The **Review result JSON** format defines the structure for translation
827review reports. For each entry with translation issues, create an issue
828object as follows:
829
830- Copy the original entry's `msgid`, optional `msgid_plural`, and optional
831 `msgstr` array (original translation forms) into the issue object. Use the
832 same shape as GETTEXT JSON: `msgstr` is **always a JSON array** when present
833 (one element singular, multiple for plural).
834- Write a summary of all issues found for this entry in `description`.
835- Set `score` according to the severity of issues found for this entry,
836 from 0 to 3 (0 = critical; 1 = major; 2 = minor; 3 = perfect, no issues).
837 **Lower score means more severe issues.**
838- Place the suggested translation in **`suggest_msgstr`** as a **JSON array**:
839 one string for singular, multiple strings for plural forms in order. This is
840 required for `git-po-helper` to apply suggestions.
841- Include only entries with issues (score less than 3). When no issues are
842 found in the batch, write `{"issues": []}`.
843
844Example review result (with issues):
845
846```json
847{
848 "issues": [
849 {
850 "msgid": "commit",
851 "msgstr": ["委托"],
852 "score": 0,
853 "description": "Terminology error: 'commit' should be translated as '提交'",
854 "suggest_msgstr": ["提交"]
855 },
856 {
857 "msgid": "repository",
858 "msgid_plural": "repositories",
859 "msgstr": ["版本库", "版本库"],
860 "score": 2,
861 "description": "Consistency issue: suggest using '仓库' consistently",
862 "suggest_msgstr": ["仓库", "仓库"]
863 }
864 ]
865}
866```
867
868Field descriptions for each issue object (element of the `issues` array):
869
870- `msgid` (and optional `msgid_plural` for plural entries): Original source text.
871- `msgstr` (optional): JSON array of original translation forms (same meaning as
872 in GETTEXT JSON entries).
873- `suggest_msgstr`: JSON array of suggested translation forms; **must be an
874 array** (e.g. `["提交"]` for singular). Plural entries use multiple elements
875 in order.
876- `score`: 0–3 (0 = critical; 1 = major; 2 = minor; 3 = perfect, no issues).
877- `description`: Brief summary of the issue.
878
879
880## Human translators remain in control
881
882Git translation is human-driven; language team leaders and contributors are
883responsible for maintaining translation quality and consistency.
884
885AI-generated output should always be treated as drafts that must be reviewed
886and approved by someone who understands both the technical context and the
887target language. The best results come from combining AI efficiency with human
888judgment, cultural insight, and community engagement.