at commit b2bc011e

1 # Instructions for AI Agents
2
3 This file gives specific instructions for AI agents that perform
4 housekeeping tasks for Git l10n. Use of AI is optional; many successful
5 l10n teams work well without it.
6
7 The section "Housekeeping tasks for localization workflows" documents the
8 most commonly used housekeeping tasks:
9
10 1. Generating or updating po/git.pot
11 2. Updating po/XX.po
12 3. Translating po/XX.po
13 4. Reviewing translation quality
14
15
16 ## Background knowledge for localization workflows
17
18 Essential background for the workflows below; understand these concepts before
19 performing 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
31 The **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.)
33 is stored in `msgstr`, as in this example:
34
35 ```po
36 msgid ""
37 msgstr ""
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
47 metadata only and must be left unchanged.
48
49
50 ### Glossary Section
51
52 PO 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
65 in `#` comments only. Leave that comment block unchanged.
66
67
68 ### PO entry structure (single-line and multi-line)
69
70 PO entries are `msgid` / `msgstr` pairs. Plural messages add `msgid_plural` and
71 `msgstr[n]`. The `msgid` is the immutable source; `msgstr` is the target
72 translation. Each side may be a single quoted string or a multi-line block.
73 In the multi-line form the header line is often `msgid ""` / `msgstr ""`, with
74 the real text split across following quoted lines (concatenated by Gettext).
75
76 **Single-line entries**:
77
78 ```po
79 msgid "commit message"
80 msgstr "提交说明"
81 ```
82
83 **Multi-line entries**:
84
85 ```po
86 msgid ""
87 "Line 1\n"
88 "Line 2"
89 msgstr ""
90 "行 1\n"
91 "行 2"
92 ```
93
94 **CRITICAL**: Do **not** use `grep '^msgstr ""'` to find untranslated entries;
95 multi-line `msgstr` blocks use the same opening line, so grep gives false
96 positives. 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
103 Fuzzy entries need re-translation because the source text changed. The format
104 differs 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
117 Preserve escape sequences (`\n`, `\"`, `\\`, `\t`), placeholders (`%s`, `%d`,
118 etc.), and quotes exactly as in `msgid`. Only reorder placeholders with
119 positional syntax when needed (see Placeholder Reordering below).
120
121
122 ### Preserving Quotation Marks
123
124 Some languages use language-specific UTF-8 quotation marks (curly/smart
125 quotes) rather than ASCII straight quotes. **Always preserve these
126 characters exactly as they appear in the source.** Do **not** convert them
127 to 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
144 double quote `"` (U+0022) is the **string delimiter**. If a translation
145 contains a curly quote that is incorrectly converted to `"` (U+0022),
146 the PO parser will interpret it as the end of the string, causing:
147
148 1. **String truncation**: The `msgstr` value is cut short at the
149 spurious quote character.
150 2. **Syntax errors**: `msgfmt --check` fails with parse errors at
151 the line where the string was prematurely terminated.
152 3. **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
170 When reordering placeholders relative to `msgid`, use positional syntax (`%n$`)
171 where *n* is the 1-based argument index, so each argument still binds to the
172 right value. Preserve width and precision modifiers, and place `%n$` before
173 them (see examples below).
174
175 **Example 1** (placeholder reordering with precision):
176
177 ```po
178 msgid "missing environment variable '%s' for configuration '%.*s'"
179 msgstr "配置 '%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
188 msgid ""
189 "Path updated: %s renamed to %s in %s, inside a directory that was renamed in "
190 "%s; moving it to %s."
191 msgstr ""
192 "路径已更新:%1$s 在 %3$s 中被重命名为 %2$s,而其所在目录又在 %4$s 中被重命"
193 "名,因此将其移动到 %5$s。"
194 ```
195
196 Original order 1,2,3,4,5; in translation 1,3,2,4,5. Each line must be a
197 complete quoted string.
198
199 **Example 3** (no placeholder reordering):
200
201 ```po
202 msgid "MIDX %s must be an ancestor of %s"
203 msgstr "MIDX %s 必须是 %s 的祖先"
204 ```
205
206 Argument order is still 1,2 in translation, so `%n$` is not needed.
207 If no placeholder reordering occurs, you **must not** introduce `%n$`
208 syntax; keep the original non-positional placeholders (`%s`, `%d`, etc.).
209
210
211 ### Validating PO File Format
212
213 Check the PO file using the command below:
214
215 ```shell
216 msgfmt --check -o /dev/null po/XX.po
217 ```
218
219 Common 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
226 On 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
240 git-po-helper version --ge 0.9.1
241 ```
242
243 If the command is missing or the exit status is non-zero, print the error (use
244 the command's own output when available) and **refuse** the task; do not
245 continue.
246
247
248 #### Splitting large PO files
249
250 When a PO file is too large for translation or review, use `git-po-helper
251 msg-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)
267 git-po-helper msg-select --range "-50" po/in.po -o po/out.po
268
269 # Entries 51–100
270 git-po-helper msg-select --range "51-100" po/in.po -o po/out.po
271
272 # Entries 101 to end
273 git-po-helper msg-select --range "101-" po/in.po -o po/out.po
274
275 # Entries 1–50 without header (content only)
276 git-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
279 git-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
287 changed entries; otherwise it contains a valid PO header.
288
289 ```shell
290 # Get full context of local changes (HEAD vs working tree)
291 git-po-helper compare po/XX.po -o po/out.po
292
293 # Get full context of changes in a specific commit (parent vs commit)
294 git-po-helper compare --commit <commit> po/XX.po -o po/out.po
295
296 # Get full context of changes since a commit (commit vs working tree)
297 git-po-helper compare --since <commit> po/XX.po -o po/out.po
298
299 # Get full context between two commits
300 git-po-helper compare -r <commit1>..<commit2> po/XX.po -o po/out.po
301
302 # Get full context of two worktree files
303 git-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
306 git-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.
324 Duplicate `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)
329 git-po-helper msg-cat --unset-fuzzy -o po/out.po po/in.json
330
331 # Merge multiple PO files
332 git-po-helper msg-cat -o po/out.po po/in-1.po po/in-2.json
333 ```
334
335
336 #### GETTEXT JSON format
337
338 The **GETTEXT JSON** format is an internal format defined by `git-po-helper`
339 for 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`
341 read 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
454 For common housekeeping tasks, follow the steps in the matching subsection
455 below.
456
457
458 ### Task 1: Generating or updating po/git.pot
459
460 When asked to generate or update `po/git.pot` (or the like):
461
462 1. **Directly execute** the command `make po/git.pot` without checking
463 if the file exists beforehand.
464
465 2. **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
471 When asked to update `po/XX.po` (or the like):
472
473 1. **Directly execute** the command `make po-update PO_FILE=po/XX.po`
474 without reading or checking the file content beforehand.
475
476 2. **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
482 To 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
484 the 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
488 is when step 2 finds `po/l10n-pending.po` empty. Do not skip step 7 or jump to
489 step 8 after step 6.
490
491 1. **Extract entries to translate**: **Directly execute** the script below—it is
492 authoritative; do not reimplement. It generates `po/l10n-pending.po` 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.po"
500 rm -f "$PENDING"
501
502 git-po-helper msg-select --untranslated --fuzzy --no-obsolete -o "$PENDING" "$PO_FILE"
503 if test -s "$PENDING"
504 then
505 msgfmt --stat -o /dev/null "$PENDING" || true
506 echo "Pending file is not empty; there are still entries to translate."
507 else
508 echo "No entries need translation."
509 return 1
510 fi
511 }
512 # Run the extraction. Example: l10n_extract_pending po/zh_CN.po
513 l10n_extract_pending po/XX.po
514 ```
515
516 2. **Check generated file**: If `po/l10n-pending.po` is empty or does not exist,
517 translation is complete; go to step 8. Otherwise proceed to step 3.
518
519 3. **Prepare one batch for translation**: Batching keeps each run small so the
520 model can complete translation within limited context. **BEFORE translating**,
521 **directly execute** the script below—it is authoritative; do not reimplement.
522 It writes `po/l10n-todo.json`; then go to step 4.
523
524 ```shell
525 l10n_one_batch () {
526 test $# -ge 1 || { echo "Usage: l10n_one_batch <po-file> [min_batch_size]" >&2; return 1; }
527 PO_FILE="$1"
528 min_batch_size=${2:-100}
529 PENDING="po/l10n-pending.po"
530 TODO_JSON="po/l10n-todo.json"
531 DONE_JSON="po/l10n-done.json"
532 DONE_PO="po/l10n-done.po"
533 rm -f "$TODO_JSON" "$DONE_JSON" "$DONE_PO"
534
535 ENTRY_COUNT=$(grep -c '^msgid ' "$PENDING" 2>/dev/null || true)
536 ENTRY_COUNT=${ENTRY_COUNT:-0}
537 ENTRY_COUNT=$((ENTRY_COUNT > 0 ? ENTRY_COUNT - 1 : 0))
538 if test "$ENTRY_COUNT" -gt $min_batch_size
539 then
540 if test "$ENTRY_COUNT" -gt $((min_batch_size * 8))
541 then
542 NUM=$((min_batch_size * 2))
543 elif test "$ENTRY_COUNT" -gt $((min_batch_size * 4))
544 then
545 NUM=$((min_batch_size + min_batch_size / 2))
546 else
547 NUM=$min_batch_size
548 fi
549 git-po-helper msg-select --json --head "$NUM" -o "$TODO_JSON" "$PENDING"
550 echo "Processing batch of $NUM entries (out of $ENTRY_COUNT remaining)"
551 else
552 git-po-helper msg-select --json -o "$TODO_JSON" "$PENDING"
553 echo "Processing all $ENTRY_COUNT entries at once"
554 fi
555 }
556 # Prepare one batch; shrink 2nd arg when batches exceed agent capacity.
557 l10n_one_batch po/XX.po 100
558 ```
559
560 4. **Translate JSON batch** (`po/l10n-todo.json` → `po/l10n-done.json`):
561
562 - **Task**: Translate `po/l10n-todo.json` (input, GETTEXT JSON) into
563 `po/l10n-done.json` (output, GETTEXT JSON). See the "GETTEXT JSON format"
564 section above for format details and translation rules.
565 - **Reference glossary**: Read the glossary from the batch file's
566 `header_comment` (see "Glossary Section" above) and use it for
567 consistent terminology.
568 - **When translating**: Follow the "Quality checklist" above for correctness
569 and quality. Handle escape sequences (`\n`, `\"`, `\\`, `\t`), placeholders,
570 and quotes correctly as in `msgid`. For JSON, correctly escape and unescape
571 these sequences when reading and writing. Modify `msgstr` and `msgstr[n]`
572 (for plural entries); clear the fuzzy flag (omit or set `fuzzy` to `false`).
573 Do **not** modify `msgid` or `msgid_plural`.
574
575 5. **Validate `po/l10n-done.po`**:
576
577 Run the validation script below. If it fails, fix per the errors and notes,
578 re-run until it succeeds.
579
580 ```shell
581 l10n_validate_done () {
582 DONE_PO="po/l10n-done.po"
583 DONE_JSON="po/l10n-done.json"
584 PENDING="po/l10n-pending.po"
585
586 if test -f "$DONE_JSON" && { ! test -f "$DONE_PO" || test "$DONE_JSON" -nt "$DONE_PO"; }
587 then
588 git-po-helper msg-cat --unset-fuzzy -o "$DONE_PO" "$DONE_JSON" || {
589 echo "ERROR [JSON to PO conversion]: Fix $DONE_JSON and re-run." >&2
590 return 1
591 }
592 fi
593
594 # Check 1: msgid should not be modified
595 MSGID_OUT=$(git-po-helper compare -q --msgid --assert-no-changes \
596 "$PENDING" "$DONE_PO" 2>&1)
597 MSGID_RC=$?
598 if test $MSGID_RC -ne 0 || test -n "$MSGID_OUT"
599 then
600 echo "ERROR [msgid modified]: The following entries appeared after" >&2
601 echo "translation because msgid was altered. Fix in $DONE_PO." >&2
602 echo "$MSGID_OUT" >&2
603 return 1
604 fi
605
606 # Check 2: PO format (see "Validating PO File Format" for error handling)
607 MSGFMT_OUT=$(msgfmt --check -o /dev/null "$DONE_PO" 2>&1)
608 MSGFMT_RC=$?
609 if test $MSGFMT_RC -ne 0
610 then
611 echo "ERROR [PO format]: Fix errors in $DONE_PO." >&2
612 echo "$MSGFMT_OUT" >&2
613 return 1
614 fi
615
616 echo "Validation passed."
617 }
618 l10n_validate_done
619 ```
620
621 If the script fails, fix **directly in `po/l10n-done.po`**. Re-run
622 `l10n_validate_done` until it succeeds. Editing `po/l10n-done.json` is not
623 recommended because it adds an extra JSON-to-PO conversion step. Use the
624 error message to decide:
625
626 - **`[msgid modified]`**: The listed entries have altered `msgid`; restore
627 them to match `po/l10n-pending.po`.
628 - **`[PO format]`**: `msgfmt` reports line numbers; fix the errors in place.
629 See "Validating PO File Format" for common issues.
630
631
632 6. **Merge translation results into `po/XX.po`**: Run the script below. If it
633 fails, fix the file the error names: **`[JSON to PO conversion]`** →
634 `po/l10n-done.json`; **`[msgcat merge]`** → `po/l10n-done.po`. Re-run until
635 it succeeds.
636
637 ```shell
638 l10n_merge_batch () {
639 test $# -ge 1 || { echo "Usage: l10n_merge_batch <po-file>" >&2; return 1; }
640 PO_FILE="$1"
641 DONE_PO="po/l10n-done.po"
642 DONE_JSON="po/l10n-done.json"
643 MERGED="po/l10n-done.merged"
644 TODO_JSON="po/l10n-todo.json"
645 if test -f "$DONE_JSON" && { ! test -f "$DONE_PO" || test "$DONE_JSON" -nt "$DONE_PO"; }
646 then
647 git-po-helper msg-cat --unset-fuzzy -o "$DONE_PO" "$DONE_JSON" || {
648 echo "ERROR [JSON to PO conversion]: Fix $DONE_JSON and re-run." >&2
649 return 1
650 }
651 fi
652 msgcat --use-first "$DONE_PO" "$PO_FILE" >"$MERGED" || {
653 echo "ERROR [msgcat merge]: Fix errors in $DONE_PO and re-run." >&2
654 return 1
655 }
656 mv "$MERGED" "$PO_FILE"
657 rm -f "$TODO_JSON" "$DONE_JSON" "$DONE_PO"
658 }
659 # Run the merge. Example: l10n_merge_batch po/zh_CN.po
660 l10n_merge_batch po/XX.po
661 ```
662
663 7. **Loop**: **MUST** return to step 1 (Extract entries) and repeat the cycle.
664 Do **not** skip this step or go to step 8. Step 8 (below) runs **only**
665 when step 2 finds no more entries and redirects there.
666
667 8. **Only after loop exits**: Run the command below to validate the PO file and
668 display the report. The process ends here.
669
670 ```shell
671 msgfmt --check --stat -o /dev/null po/XX.po
672 ```
673
674
675 ### Task 4: Review translation quality
676
677 Review may target the full `po/XX.po`, a specific commit, or changes since a
678 commit. When asked to review, follow the steps below.
679
680 **Workflow**: Follow steps in order. Do **NOT** use `git show`, `git diff`,
681 `git format-patch`, or similar to get changes—they break PO context; use **only**
682 `git-po-helper compare` for extraction. **Require** `git-po-helper` (see
683 "Using git-po-helper" for the version check); without a passing check, refuse
684 the task. Steps 3→4→5→6→7 loop: after step 6, **always** go to step 7 (back to
685 step 3). The **only** ways to step 8 are when step 4 finds `po/review-todo.json`
686 missing or empty (no batch left to review), or when step 1 finds
687 `po/review-result.json` already present.
688
689 1. **Check for existing review (resume support)**: Evaluate the following in order:
690
691 - If `po/review-input.po` does **not** exist, proceed to step 2 (Extract
692 entries) for a fresh start.
693 - Else If `po/review-result.json` exists, go to step 8 (only after loop exits).
694 - Else If `po/review-done.json` exists, go to step 6 (Rename result).
695 - Else if `po/review-todo.json` exists, go to step 5 (Review the current
696 batch).
697 - Else go to step 3 (Prepare one batch).
698
699 2. **Extract entries**: Run `git-po-helper compare` with the desired range and
700 redirect the output to `po/review-input.po`. See "Comparing PO files for
701 translation and review" under git-po-helper for options.
702
703 3. **Prepare one batch**: Batching keeps each run small so the model can
704 complete review within limited context. **Directly execute** the script
705 below—it is authoritative; do not reimplement.
706
707 ```shell
708 review_one_batch () {
709 min_batch_size=${1:-100}
710 INPUT_PO="po/review-input.po"
711 PENDING="po/review-pending.po"
712 TODO="po/review-todo.json"
713 DONE="po/review-done.json"
714 BATCH_FILE="po/review-batch.txt"
715
716 if test ! -f "$INPUT_PO"
717 then
718 rm -f "$TODO"
719 echo >&2 "cannot find $INPUT_PO, nothing for review"
720 return 1
721 fi
722 if test ! -f "$PENDING" || test "$INPUT_PO" -nt "$PENDING"
723 then
724 rm -f "$BATCH_FILE" "$TODO" "$DONE"
725 rm -f po/review-result*.json
726 cp "$INPUT_PO" "$PENDING"
727 fi
728
729 ENTRY_COUNT=$(grep -c '^msgid ' "$PENDING" 2>/dev/null || true)
730 ENTRY_COUNT=${ENTRY_COUNT:-0}
731 ENTRY_COUNT=$((ENTRY_COUNT > 0 ? ENTRY_COUNT - 1 : 0))
732 if test "$ENTRY_COUNT" -eq 0
733 then
734 rm -f "$TODO"
735 echo >&2 "No entries left for review"
736 return 1
737 fi
738
739 if test "$ENTRY_COUNT" -gt $min_batch_size
740 then
741 if test "$ENTRY_COUNT" -gt $((min_batch_size * 8))
742 then
743 NUM=$((min_batch_size * 2))
744 elif test "$ENTRY_COUNT" -gt $((min_batch_size * 4))
745 then
746 NUM=$((min_batch_size + min_batch_size / 2))
747 else
748 NUM=$min_batch_size
749 fi
750 else
751 NUM=$ENTRY_COUNT
752 fi
753
754 BATCH=$(cat "$BATCH_FILE" 2>/dev/null || true)
755 BATCH=${BATCH:-0}
756 BATCH=$((BATCH + 1))
757 echo "$BATCH" >"$BATCH_FILE"
758
759 git-po-helper msg-select --json --head "$NUM" -o "$TODO" "$PENDING"
760 git-po-helper msg-select --since "$((NUM + 1))" -o "${PENDING}.tmp" "$PENDING"
761 mv "${PENDING}.tmp" "$PENDING"
762 echo "Processing batch $BATCH ($NUM entries out of $ENTRY_COUNT)"
763 }
764 # The parameter controls batch size; reduce if the batch file is too large.
765 review_one_batch 100
766 ```
767
768 4. **Check todo file**: If `po/review-todo.json` does not exist or is empty,
769 review is complete; go to step 8 (only after loop exits). Otherwise proceed to
770 step 5.
771
772 5. **Review the current batch**: Review translations in `po/review-todo.json`
773 and write findings to `po/review-done.json` as follows:
774 - Use "Background knowledge for localization workflows" for PO/JSON structure,
775 placeholders, and terminology.
776 - If `header_comment` includes a glossary, follow it for consistency.
777 - Do **not** review the header (`header_comment`, `header_meta`).
778 - For every other entry, check the entry's `msgstr` **array** (translation
779 forms) against `msgid` / `msgid_plural` using the "Quality checklist" above.
780 - Write JSON per "Review result JSON format" below; use `{"issues": []}` when
781 there are no issues. **Always** write `po/review-done.json`—it marks the
782 batch complete.
783
784 6. **Rename result**: Rename `po/review-done.json` to `po/review-result-<N>.json`,
785 where N is the value in `po/review-batch.txt` (the batch just completed).
786 Run the script below:
787
788 ```shell
789 review_rename_result () {
790 TODO="po/review-todo.json"
791 DONE="po/review-done.json"
792 BATCH_FILE="po/review-batch.txt"
793 if test -f "$DONE"
794 then
795 N=$(cat "$BATCH_FILE" 2>/dev/null) || { echo "ERROR: $BATCH_FILE not found." >&2; return 1; }
796 mv "$DONE" "po/review-result-$N.json"
797 echo "Renamed to po/review-result-$N.json"
798 fi
799 rm -f "$TODO"
800 }
801 review_rename_result
802 ```
803
804 7. **Loop**: **MUST** return to step 3 (Prepare one batch) and repeat the cycle.
805 Do **not** skip this step or go to step 8. Step 8 is reached **only** when
806 step 4 finds `po/review-todo.json` missing or empty.
807
808 8. **Only after loop exits**: **Directly execute** the command below. It merges
809 results, applies suggestions, and displays the report. The process ends here.
810
811 ```shell
812 git-po-helper agent-run review --report po
813 ```
814
815 **Do not** run cleanup or delete intermediate files. Keep them for inspection
816 or resumption.
817
818 **Review result JSON format**:
819
820 The **Review result JSON** format defines the structure for translation
821 review reports. For each entry with translation issues, create an issue
822 object as follows:
823
824 - Copy the original entry's `msgid`, optional `msgid_plural`, and optional
825 `msgstr` array (original translation forms) into the issue object. Use the
826 same shape as GETTEXT JSON: `msgstr` is **always a JSON array** when present
827 (one element singular, multiple for plural).
828 - Write a summary of all issues found for this entry in `description`.
829 - Set `score` according to the severity of issues found for this entry,
830 from 0 to 3 (0 = critical; 1 = major; 2 = minor; 3 = perfect, no issues).
831 **Lower score means more severe issues.**
832 - Place the suggested translation in **`suggest_msgstr`** as a **JSON array**:
833 one string for singular, multiple strings for plural forms in order. This is
834 required for `git-po-helper` to apply suggestions.
835 - Include only entries with issues (score less than 3). When no issues are
836 found in the batch, write `{"issues": []}`.
837
838 Example review result (with issues):
839
840 ```json
841 {
842 "issues": [
843 {
844 "msgid": "commit",
845 "msgstr": ["委托"],
846 "score": 0,
847 "description": "Terminology error: 'commit' should be translated as '提交'",
848 "suggest_msgstr": ["提交"]
849 },
850 {
851 "msgid": "repository",
852 "msgid_plural": "repositories",
853 "msgstr": ["版本库", "版本库"],
854 "score": 2,
855 "description": "Consistency issue: suggest using '仓库' consistently",
856 "suggest_msgstr": ["仓库", "仓库"]
857 }
858 ]
859 }
860 ```
861
862 Field descriptions for each issue object (element of the `issues` array):
863
864 - `msgid` (and optional `msgid_plural` for plural entries): Original source text.
865 - `msgstr` (optional): JSON array of original translation forms (same meaning as
866 in GETTEXT JSON entries).
867 - `suggest_msgstr`: JSON array of suggested translation forms; **must be an
868 array** (e.g. `["提交"]` for singular). Plural entries use multiple elements
869 in order.
870 - `score`: 0–3 (0 = critical; 1 = major; 2 = minor; 3 = perfect, no issues).
871 - `description`: Brief summary of the issue.
872
873
874 ## Human translators remain in control
875
876 Git translation is human-driven; language team leaders and contributors are
877 responsible for maintaining translation quality and consistency.
878
879 AI-generated output should always be treated as drafts that must be reviewed
880 and approved by someone who understands both the technical context and the
881 target language. The best results come from combining AI efficiency with human
882 judgment, cultural insight, and community engagement.