at commit 312e271f

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=$(git-po-helper stat -c "$PENDING" 2>/dev/null || true)
536 ENTRY_COUNT=${ENTRY_COUNT:-0}
537 if test "$ENTRY_COUNT" -gt $min_batch_size
538 then
539 if test "$ENTRY_COUNT" -gt $((min_batch_size * 8))
540 then
541 NUM=$((min_batch_size * 2))
542 elif test "$ENTRY_COUNT" -gt $((min_batch_size * 4))
543 then
544 NUM=$((min_batch_size + min_batch_size / 2))
545 else
546 NUM=$min_batch_size
547 fi
548 git-po-helper msg-select --json --head "$NUM" -o "$TODO_JSON" "$PENDING"
549 echo "Processing batch of $NUM entries (out of $ENTRY_COUNT remaining)"
550 else
551 git-po-helper msg-select --json -o "$TODO_JSON" "$PENDING"
552 echo "Processing all $ENTRY_COUNT entries at once"
553 fi
554 }
555 # Prepare one batch; shrink 2nd arg when batches exceed agent capacity.
556 l10n_one_batch po/XX.po 100
557 ```
558
559 4. **Translate JSON batch** (`po/l10n-todo.json` → `po/l10n-done.json`):
560
561 - **Task**: Translate `po/l10n-todo.json` (input, GETTEXT JSON) into
562 `po/l10n-done.json` (output, GETTEXT JSON). See the "GETTEXT JSON format"
563 section above for format details and translation rules.
564 - **Reference glossary**: Read the glossary from the batch file's
565 `header_comment` (see "Glossary Section" above) and use it for
566 consistent terminology.
567 - **When translating**: Follow the "Quality checklist" above for correctness
568 and quality. Handle escape sequences (`\n`, `\"`, `\\`, `\t`), placeholders,
569 and quotes correctly as in `msgid`. For JSON, correctly escape and unescape
570 these sequences when reading and writing. Modify `msgstr` and `msgstr[n]`
571 (for plural entries); clear the fuzzy flag (omit or set `fuzzy` to `false`).
572 Do **not** modify `msgid` or `msgid_plural`.
573
574 5. **Validate `po/l10n-done.po`**:
575
576 Run the validation script below. If it fails, fix per the errors and notes,
577 re-run until it succeeds.
578
579 ```shell
580 l10n_validate_done () {
581 DONE_PO="po/l10n-done.po"
582 DONE_JSON="po/l10n-done.json"
583 PENDING="po/l10n-pending.po"
584
585 if test -f "$DONE_JSON" && { ! test -f "$DONE_PO" || test "$DONE_JSON" -nt "$DONE_PO"; }
586 then
587 git-po-helper msg-cat --unset-fuzzy -o "$DONE_PO" "$DONE_JSON" || {
588 echo "ERROR [JSON to PO conversion]: Fix $DONE_JSON and re-run." >&2
589 return 1
590 }
591 fi
592
593 # Check 1: msgid should not be modified
594 MSGID_OUT=$(git-po-helper compare -q --msgid --assert-no-changes \
595 "$PENDING" "$DONE_PO" 2>&1)
596 MSGID_RC=$?
597 if test $MSGID_RC -ne 0 || test -n "$MSGID_OUT"
598 then
599 echo "ERROR [msgid modified]: The following entries appeared after" >&2
600 echo "translation because msgid was altered. Fix in $DONE_PO." >&2
601 echo "$MSGID_OUT" >&2
602 return 1
603 fi
604
605 # Check 2: PO format (see "Validating PO File Format" for error handling)
606 MSGFMT_OUT=$(msgfmt --check -o /dev/null "$DONE_PO" 2>&1)
607 MSGFMT_RC=$?
608 if test $MSGFMT_RC -ne 0
609 then
610 echo "ERROR [PO format]: Fix errors in $DONE_PO." >&2
611 echo "$MSGFMT_OUT" >&2
612 return 1
613 fi
614
615 echo "Validation passed."
616 }
617 l10n_validate_done
618 ```
619
620 If the script fails, fix **directly in `po/l10n-done.po`**. Re-run
621 `l10n_validate_done` until it succeeds. Editing `po/l10n-done.json` is not
622 recommended because it adds an extra JSON-to-PO conversion step. Use the
623 error message to decide:
624
625 - **`[msgid modified]`**: The listed entries have altered `msgid`; restore
626 them to match `po/l10n-pending.po`.
627 - **`[PO format]`**: `msgfmt` reports line numbers; fix the errors in place.
628 See "Validating PO File Format" for common issues.
629
630
631 6. **Merge translation results into `po/XX.po`**: Run the script below. If it
632 fails, fix the file the error names: **`[JSON to PO conversion]`** →
633 `po/l10n-done.json`; **`[msgcat merge]`** → `po/l10n-done.po`. Re-run until
634 it succeeds.
635
636 ```shell
637 l10n_merge_batch () {
638 test $# -ge 1 || { echo "Usage: l10n_merge_batch <po-file>" >&2; return 1; }
639 PO_FILE="$1"
640 DONE_PO="po/l10n-done.po"
641 DONE_JSON="po/l10n-done.json"
642 MERGED="po/l10n-done.merged"
643 TODO_JSON="po/l10n-todo.json"
644 if test -f "$DONE_JSON" && { ! test -f "$DONE_PO" || test "$DONE_JSON" -nt "$DONE_PO"; }
645 then
646 git-po-helper msg-cat --unset-fuzzy -o "$DONE_PO" "$DONE_JSON" || {
647 echo "ERROR [JSON to PO conversion]: Fix $DONE_JSON and re-run." >&2
648 return 1
649 }
650 fi
651 msgcat --use-first "$DONE_PO" "$PO_FILE" >"$MERGED" || {
652 echo "ERROR [msgcat merge]: Fix errors in $DONE_PO and re-run." >&2
653 return 1
654 }
655 mv "$MERGED" "$PO_FILE"
656 rm -f "$TODO_JSON" "$DONE_JSON" "$DONE_PO"
657 }
658 # Run the merge. Example: l10n_merge_batch po/zh_CN.po
659 l10n_merge_batch po/XX.po
660 ```
661
662 7. **Loop**: **MUST** return to step 1 (Extract entries) and repeat the cycle.
663 Do **not** skip this step or go to step 8. Step 8 (below) runs **only**
664 when step 2 finds no more entries and redirects there.
665
666 8. **Only after loop exits**: Run the command below to validate the PO file and
667 display the report. The process ends here.
668
669 ```shell
670 msgfmt --check --stat -o /dev/null po/XX.po
671 ```
672
673
674 ### Task 4: Review translation quality
675
676 Review may target the full `po/XX.po`, a specific commit, or changes since a
677 commit. When asked to review, follow the steps below.
678
679 **Workflow**: Follow steps in order. Do **NOT** use `git show`, `git diff`,
680 `git format-patch`, or similar to get changes—they break PO context; use **only**
681 `git-po-helper compare` for extraction. **Require** `git-po-helper` (see
682 "Using git-po-helper" for the version check); without a passing check, refuse
683 the task. Steps 3→4→5→6→7 loop: after step 6, **always** go to step 7 (back to
684 step 3). The **only** ways to step 8 are when step 4 finds `po/review-todo.json`
685 missing or empty (no batch left to review), or when step 1 finds
686 `po/review-result.json` already present.
687
688 1. **Check for existing review (resume support)**: Evaluate the following in order:
689
690 - If `po/review-input.po` does **not** exist, proceed to step 2 (Extract
691 entries) for a fresh start.
692 - Else If `po/review-result.json` exists, go to step 8 (only after loop exits).
693 - Else If `po/review-done.json` exists, go to step 6 (Rename result).
694 - Else if `po/review-todo.json` exists, go to step 5 (Review the current
695 batch).
696 - Else go to step 3 (Prepare one batch).
697
698 2. **Extract entries**: Run `git-po-helper compare` with the desired range and
699 redirect the output to `po/review-input.po`. See "Comparing PO files for
700 translation and review" under git-po-helper for options.
701
702 3. **Prepare one batch**: Batching keeps each run small so the model can
703 complete review within limited context. **Directly execute** the script
704 below—it is authoritative; do not reimplement.
705
706 ```shell
707 review_one_batch () {
708 min_batch_size=${1:-100}
709 INPUT_PO="po/review-input.po"
710 PENDING="po/review-pending.po"
711 TODO="po/review-todo.json"
712 DONE="po/review-done.json"
713 BATCH_FILE="po/review-batch.txt"
714
715 if test ! -f "$INPUT_PO"
716 then
717 rm -f "$TODO"
718 echo >&2 "cannot find $INPUT_PO, nothing for review"
719 return 1
720 fi
721 if test ! -f "$PENDING" || test "$INPUT_PO" -nt "$PENDING"
722 then
723 rm -f "$BATCH_FILE" "$TODO" "$DONE"
724 rm -f po/review-result*.json
725 cp "$INPUT_PO" "$PENDING"
726 fi
727
728 ENTRY_COUNT=$(git-po-helper stat -c "$PENDING" 2>/dev/null || true)
729 ENTRY_COUNT=${ENTRY_COUNT:-0}
730 if test "$ENTRY_COUNT" -eq 0
731 then
732 rm -f "$TODO"
733 echo >&2 "No entries left for review"
734 return 1
735 fi
736
737 if test "$ENTRY_COUNT" -gt $min_batch_size
738 then
739 if test "$ENTRY_COUNT" -gt $((min_batch_size * 8))
740 then
741 NUM=$((min_batch_size * 2))
742 elif test "$ENTRY_COUNT" -gt $((min_batch_size * 4))
743 then
744 NUM=$((min_batch_size + min_batch_size / 2))
745 else
746 NUM=$min_batch_size
747 fi
748 else
749 NUM=$ENTRY_COUNT
750 fi
751
752 BATCH=$(cat "$BATCH_FILE" 2>/dev/null || true)
753 BATCH=${BATCH:-0}
754 BATCH=$((BATCH + 1))
755 echo "$BATCH" >"$BATCH_FILE"
756
757 git-po-helper msg-select --json --head "$NUM" -o "$TODO" "$PENDING"
758 git-po-helper msg-select --since "$((NUM + 1))" -o "${PENDING}.tmp" "$PENDING"
759 mv "${PENDING}.tmp" "$PENDING"
760 echo "Processing batch $BATCH ($NUM entries out of $ENTRY_COUNT)"
761 }
762 # The parameter controls batch size; reduce if the batch file is too large.
763 review_one_batch 100
764 ```
765
766 4. **Check todo file**: If `po/review-todo.json` does not exist or is empty,
767 review is complete; go to step 8 (only after loop exits). Otherwise proceed to
768 step 5.
769
770 5. **Review the current batch**: Review translations in `po/review-todo.json`
771 and write findings to `po/review-done.json` as follows:
772 - Use "Background knowledge for localization workflows" for PO/JSON structure,
773 placeholders, and terminology.
774 - If `header_comment` includes a glossary, follow it for consistency.
775 - Do **not** review the header (`header_comment`, `header_meta`).
776 - For every other entry, check the entry's `msgstr` **array** (translation
777 forms) against `msgid` / `msgid_plural` using the "Quality checklist" above.
778 - Write JSON per "Review result JSON format" below; use `{"issues": []}` when
779 there are no issues. **Always** write `po/review-done.json`—it marks the
780 batch complete.
781
782 6. **Rename result**: Rename `po/review-done.json` to `po/review-result-<N>.json`,
783 where N is the value in `po/review-batch.txt` (the batch just completed).
784 Run the script below:
785
786 ```shell
787 review_rename_result () {
788 TODO="po/review-todo.json"
789 DONE="po/review-done.json"
790 BATCH_FILE="po/review-batch.txt"
791 if test -f "$DONE"
792 then
793 N=$(cat "$BATCH_FILE" 2>/dev/null) || { echo "ERROR: $BATCH_FILE not found." >&2; return 1; }
794 mv "$DONE" "po/review-result-$N.json"
795 echo "Renamed to po/review-result-$N.json"
796 fi
797 rm -f "$TODO"
798 }
799 review_rename_result
800 ```
801
802 7. **Loop**: **MUST** return to step 3 (Prepare one batch) and repeat the cycle.
803 Do **not** skip this step or go to step 8. Step 8 is reached **only** when
804 step 4 finds `po/review-todo.json` missing or empty.
805
806 8. **Only after loop exits**: **Directly execute** the command below. It merges
807 results, applies suggestions, and displays the report. The process ends here.
808
809 ```shell
810 git-po-helper agent-run review --report po
811 ```
812
813 **Do not** run cleanup or delete intermediate files. Keep them for inspection
814 or resumption.
815
816 **Review result JSON format**:
817
818 The **Review result JSON** format defines the structure for translation
819 review reports. For each entry with translation issues, create an issue
820 object as follows:
821
822 - Copy the original entry's `msgid`, optional `msgid_plural`, and optional
823 `msgstr` array (original translation forms) into the issue object. Use the
824 same shape as GETTEXT JSON: `msgstr` is **always a JSON array** when present
825 (one element singular, multiple for plural).
826 - Write a summary of all issues found for this entry in `description`.
827 - Set `score` according to the severity of issues found for this entry,
828 from 0 to 3 (0 = critical; 1 = major; 2 = minor; 3 = perfect, no issues).
829 **Lower score means more severe issues.**
830 - Place the suggested translation in **`suggest_msgstr`** as a **JSON array**:
831 one string for singular, multiple strings for plural forms in order. This is
832 required for `git-po-helper` to apply suggestions.
833 - Include only entries with issues (score less than 3). When no issues are
834 found in the batch, write `{"issues": []}`.
835
836 Example review result (with issues):
837
838 ```json
839 {
840 "issues": [
841 {
842 "msgid": "commit",
843 "msgstr": ["委托"],
844 "score": 0,
845 "description": "Terminology error: 'commit' should be translated as '提交'",
846 "suggest_msgstr": ["提交"]
847 },
848 {
849 "msgid": "repository",
850 "msgid_plural": "repositories",
851 "msgstr": ["版本库", "版本库"],
852 "score": 2,
853 "description": "Consistency issue: suggest using '仓库' consistently",
854 "suggest_msgstr": ["仓库", "仓库"]
855 }
856 ]
857 }
858 ```
859
860 Field descriptions for each issue object (element of the `issues` array):
861
862 - `msgid` (and optional `msgid_plural` for plural entries): Original source text.
863 - `msgstr` (optional): JSON array of original translation forms (same meaning as
864 in GETTEXT JSON entries).
865 - `suggest_msgstr`: JSON array of suggested translation forms; **must be an
866 array** (e.g. `["提交"]` for singular). Plural entries use multiple elements
867 in order.
868 - `score`: 0–3 (0 = critical; 1 = major; 2 = minor; 3 = perfect, no issues).
869 - `description`: Brief summary of the issue.
870
871
872 ## Human translators remain in control
873
874 Git translation is human-driven; language team leaders and contributors are
875 responsible for maintaining translation quality and consistency.
876
877 AI-generated output should always be treated as drafts that must be reviewed
878 and approved by someone who understands both the technical context and the
879 target language. The best results come from combining AI efficiency with human
880 judgment, cultural insight, and community engagement.