Commit
ab902cf3aa76c3e654cb8b6bb7194e6e32197375
l10n: AGENTS.md: use JSON intermediates in workflow
Make/l10n compiles every po/*.po file. The AGENTS.md workflow keeps its intermediate files in po/, so any .po file written there can be picked up by a normal `make` run and cause build failures. Switch the workflow to use GETTEXT JSON for pending/input/review work files instead of PO, and rename the remaining PO scratch file to l10n-done.po.tmp so Make/l10n ignores it. This only affects the helper scripts documented in po/AGENTS.md. Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
Jiang Xin <worldhello.net@gmail.com> · 2026-09-17 09:45 UTC
1 file changed,
+45
−42
modified po/AGENTS.md
| @@ -291,10 +291,10 @@ changed entries; otherwise it contains a valid PO header. | |||
| 291 | 291 | git-po-helper compare po/XX.po -o po/out.po | |
| 292 | 292 | ||
| 293 | 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 | |
| 294 | + | git-po-helper compare --json --commit <commit> po/XX.po -o po/out.json | |
| 295 | 295 | ||
| 296 | 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 | |
| 297 | + | git-po-helper compare --json --since <commit> po/XX.po -o po/out.json | |
| 298 | 298 | ||
| 299 | 299 | # Get full context between two commits | |
| 300 | 300 | git-po-helper compare -r <commit1>..<commit2> po/XX.po -o po/out.po | |
| @@ -485,24 +485,26 @@ the task. Batches are GETTEXT JSON for translation. | |||
| 485 | 485 | ||
| 486 | 486 | **Workflow loop**: Steps 1→2→3→4→5→6→7 form a loop. After step 6 succeeds, | |
| 487 | 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 | |
| 488 | + | is when step 2 finds `po/l10n-pending.json` empty. Do not skip step 7 or jump to | |
| 489 | 489 | step 8 after step 6. | |
| 490 | 490 | ||
| 491 | 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 | |
| 492 | + | authoritative; do not reimplement. It generates `po/l10n-pending.json` with | |
| 493 | 493 | messages that need translation. | |
| 494 | 494 | ||
| 495 | 495 | ```shell | |
| 496 | 496 | l10n_extract_pending () { | |
| 497 | 497 | test $# -ge 1 || { echo "Usage: l10n_extract_pending <po-file>" >&2; return 1; } | |
| 498 | 498 | PO_FILE="$1" | |
| 499 | - | PENDING="po/l10n-pending.po" | |
| 499 | + | PENDING="po/l10n-pending.json" | |
| 500 | 500 | rm -f "$PENDING" | |
| 501 | 501 | ||
| 502 | - | git-po-helper msg-select --untranslated --fuzzy --no-obsolete -o "$PENDING" "$PO_FILE" | |
| 503 | - | if test -s "$PENDING" | |
| 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 | |
| 504 | 506 | then | |
| 505 | - | msgfmt --stat -o /dev/null "$PENDING" || true | |
| 507 | + | git-po-helper stat "$PENDING" || true | |
| 506 | 508 | echo "Pending file is not empty; there are still entries to translate." | |
| 507 | 509 | else | |
| 508 | 510 | echo "No entries need translation." | |
| @@ -513,8 +515,9 @@ step 8 after step 6. | |||
| 513 | 515 | l10n_extract_pending po/XX.po | |
| 514 | 516 | ``` | |
| 515 | 517 | ||
| 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 | + | 2. **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. | |
| 518 | 521 | ||
| 519 | 522 | 3. **Prepare one batch for translation**: Batching keeps each run small so the | |
| 520 | 523 | model can complete translation within limited context. **BEFORE translating**, | |
| @@ -526,11 +529,11 @@ step 8 after step 6. | |||
| 526 | 529 | test $# -ge 1 || { echo "Usage: l10n_one_batch <po-file> [min_batch_size]" >&2; return 1; } | |
| 527 | 530 | PO_FILE="$1" | |
| 528 | 531 | min_batch_size=${2:-100} | |
| 529 | - | PENDING="po/l10n-pending.po" | |
| 532 | + | PENDING="po/l10n-pending.json" | |
| 530 | 533 | TODO_JSON="po/l10n-todo.json" | |
| 531 | 534 | DONE_JSON="po/l10n-done.json" | |
| 532 | - | DONE_PO="po/l10n-done.po" | |
| 533 | - | rm -f "$TODO_JSON" "$DONE_JSON" "$DONE_PO" | |
| 535 | + | DONE_PO_TMP="po/l10n-done.po.tmp" | |
| 536 | + | rm -f "$TODO_JSON" "$DONE_JSON" "$DONE_PO_TMP" | |
| 534 | 537 | ||
| 535 | 538 | ENTRY_COUNT=$(git-po-helper stat -c "$PENDING" 2>/dev/null || true) | |
| 536 | 539 | ENTRY_COUNT=${ENTRY_COUNT:-0} | |
| @@ -571,20 +574,20 @@ step 8 after step 6. | |||
| 571 | 574 | (for plural entries); clear the fuzzy flag (omit or set `fuzzy` to `false`). | |
| 572 | 575 | Do **not** modify `msgid` or `msgid_plural`. | |
| 573 | 576 | ||
| 574 | - | 5. **Validate `po/l10n-done.po`**: | |
| 577 | + | 5. **Validate `po/l10n-done.po.tmp`**: | |
| 575 | 578 | ||
| 576 | 579 | Run the validation script below. If it fails, fix per the errors and notes, | |
| 577 | 580 | re-run until it succeeds. | |
| 578 | 581 | ||
| 579 | 582 | ```shell | |
| 580 | 583 | l10n_validate_done () { | |
| 581 | - | DONE_PO="po/l10n-done.po" | |
| 584 | + | DONE_PO_TMP="po/l10n-done.po.tmp" | |
| 582 | 585 | DONE_JSON="po/l10n-done.json" | |
| 583 | - | PENDING="po/l10n-pending.po" | |
| 586 | + | PENDING="po/l10n-pending.json" | |
| 584 | 587 | ||
| 585 | - | if test -f "$DONE_JSON" && { ! test -f "$DONE_PO" || test "$DONE_JSON" -nt "$DONE_PO"; } | |
| 588 | + | if test -f "$DONE_JSON" && { ! test -f "$DONE_PO_TMP" || test "$DONE_JSON" -nt "$DONE_PO_TMP"; } | |
| 586 | 589 | then | |
| 587 | - | git-po-helper msg-cat --unset-fuzzy -o "$DONE_PO" "$DONE_JSON" || { | |
| 590 | + | git-po-helper msg-cat --unset-fuzzy -o "$DONE_PO_TMP" "$DONE_JSON" || { | |
| 588 | 591 | echo "ERROR [JSON to PO conversion]: Fix $DONE_JSON and re-run." >&2 | |
| 589 | 592 | return 1 | |
| 590 | 593 | } | |
| @@ -592,22 +595,22 @@ step 8 after step 6. | |||
| 592 | 595 | ||
| 593 | 596 | # Check 1: msgid should not be modified | |
| 594 | 597 | MSGID_OUT=$(git-po-helper compare -q --msgid --assert-no-changes \ | |
| 595 | - | "$PENDING" "$DONE_PO" 2>&1) | |
| 598 | + | "$PENDING" "$DONE_PO_TMP" 2>&1) | |
| 596 | 599 | MSGID_RC=$? | |
| 597 | 600 | if test $MSGID_RC -ne 0 || test -n "$MSGID_OUT" | |
| 598 | 601 | then | |
| 599 | 602 | echo "ERROR [msgid modified]: The following entries appeared after" >&2 | |
| 600 | - | echo "translation because msgid was altered. Fix in $DONE_PO." >&2 | |
| 603 | + | echo "translation because msgid was altered. Fix in $DONE_PO_TMP." >&2 | |
| 601 | 604 | echo "$MSGID_OUT" >&2 | |
| 602 | 605 | return 1 | |
| 603 | 606 | fi | |
| 604 | 607 | ||
| 605 | 608 | # Check 2: PO format (see "Validating PO File Format" for error handling) | |
| 606 | - | MSGFMT_OUT=$(msgfmt --check -o /dev/null "$DONE_PO" 2>&1) | |
| 609 | + | MSGFMT_OUT=$(msgfmt --check -o /dev/null "$DONE_PO_TMP" 2>&1) | |
| 607 | 610 | MSGFMT_RC=$? | |
| 608 | 611 | if test $MSGFMT_RC -ne 0 | |
| 609 | 612 | then | |
| 610 | - | echo "ERROR [PO format]: Fix errors in $DONE_PO." >&2 | |
| 613 | + | echo "ERROR [PO format]: Fix errors in $DONE_PO_TMP." >&2 | |
| 611 | 614 | echo "$MSGFMT_OUT" >&2 | |
| 612 | 615 | return 1 | |
| 613 | 616 | fi | |
| @@ -617,43 +620,43 @@ step 8 after step 6. | |||
| 617 | 620 | l10n_validate_done | |
| 618 | 621 | ``` | |
| 619 | 622 | ||
| 620 | - | If the script fails, fix **directly in `po/l10n-done.po`**. Re-run | |
| 623 | + | If the script fails, fix **directly in `po/l10n-done.po.tmp`**. Re-run | |
| 621 | 624 | `l10n_validate_done` until it succeeds. Editing `po/l10n-done.json` is not | |
| 622 | 625 | recommended because it adds an extra JSON-to-PO conversion step. Use the | |
| 623 | 626 | error message to decide: | |
| 624 | 627 | ||
| 625 | 628 | - **`[msgid modified]`**: The listed entries have altered `msgid`; restore | |
| 626 | - | them to match `po/l10n-pending.po`. | |
| 629 | + | them to match `po/l10n-pending.json`. | |
| 627 | 630 | - **`[PO format]`**: `msgfmt` reports line numbers; fix the errors in place. | |
| 628 | 631 | See "Validating PO File Format" for common issues. | |
| 629 | 632 | ||
| 630 | 633 | ||
| 631 | 634 | 6. **Merge translation results into `po/XX.po`**: Run the script below. If it | |
| 632 | 635 | 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 | |
| 636 | + | `po/l10n-done.json`; **`[msgcat merge]`** → `po/l10n-done.po.tmp`. Re-run until | |
| 634 | 637 | it succeeds. | |
| 635 | 638 | ||
| 636 | 639 | ```shell | |
| 637 | 640 | l10n_merge_batch () { | |
| 638 | 641 | test $# -ge 1 || { echo "Usage: l10n_merge_batch <po-file>" >&2; return 1; } | |
| 639 | 642 | PO_FILE="$1" | |
| 640 | - | DONE_PO="po/l10n-done.po" | |
| 643 | + | DONE_PO_TMP="po/l10n-done.po.tmp" | |
| 641 | 644 | DONE_JSON="po/l10n-done.json" | |
| 642 | 645 | MERGED="po/l10n-done.merged" | |
| 643 | 646 | TODO_JSON="po/l10n-todo.json" | |
| 644 | - | if test -f "$DONE_JSON" && { ! test -f "$DONE_PO" || test "$DONE_JSON" -nt "$DONE_PO"; } | |
| 647 | + | if test -f "$DONE_JSON" && { ! test -f "$DONE_PO_TMP" || test "$DONE_JSON" -nt "$DONE_PO_TMP"; } | |
| 645 | 648 | then | |
| 646 | - | git-po-helper msg-cat --unset-fuzzy -o "$DONE_PO" "$DONE_JSON" || { | |
| 649 | + | git-po-helper msg-cat --unset-fuzzy -o "$DONE_PO_TMP" "$DONE_JSON" || { | |
| 647 | 650 | echo "ERROR [JSON to PO conversion]: Fix $DONE_JSON and re-run." >&2 | |
| 648 | 651 | return 1 | |
| 649 | 652 | } | |
| 650 | 653 | fi | |
| 651 | - | msgcat --use-first "$DONE_PO" "$PO_FILE" >"$MERGED" || { | |
| 652 | - | echo "ERROR [msgcat merge]: Fix errors in $DONE_PO and re-run." >&2 | |
| 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 | |
| 653 | 656 | return 1 | |
| 654 | 657 | } | |
| 655 | 658 | mv "$MERGED" "$PO_FILE" | |
| 656 | - | rm -f "$TODO_JSON" "$DONE_JSON" "$DONE_PO" | |
| 659 | + | rm -f "$TODO_JSON" "$DONE_JSON" "$DONE_PO_TMP" | |
| 657 | 660 | } | |
| 658 | 661 | # Run the merge. Example: l10n_merge_batch po/zh_CN.po | |
| 659 | 662 | l10n_merge_batch po/XX.po | |
| @@ -687,7 +690,7 @@ missing or empty (no batch left to review), or when step 1 finds | |||
| 687 | 690 | ||
| 688 | 691 | 1. **Check for existing review (resume support)**: Evaluate the following in order: | |
| 689 | 692 | ||
| 690 | - | - If `po/review-input.po` does **not** exist, proceed to step 2 (Extract | |
| 693 | + | - If `po/review-input.json` does **not** exist, proceed to step 2 (Extract | |
| 691 | 694 | entries) for a fresh start. | |
| 692 | 695 | - Else If `po/review-result.json` exists, go to step 8 (only after loop exits). | |
| 693 | 696 | - Else If `po/review-done.json` exists, go to step 6 (Rename result). | |
| @@ -695,9 +698,9 @@ missing or empty (no batch left to review), or when step 1 finds | |||
| 695 | 698 | batch). | |
| 696 | 699 | - Else go to step 3 (Prepare one batch). | |
| 697 | 700 | ||
| 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 | + | 2. **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. | |
| 701 | 704 | ||
| 702 | 705 | 3. **Prepare one batch**: Batching keeps each run small so the model can | |
| 703 | 706 | complete review within limited context. **Directly execute** the script | |
| @@ -706,23 +709,23 @@ missing or empty (no batch left to review), or when step 1 finds | |||
| 706 | 709 | ```shell | |
| 707 | 710 | review_one_batch () { | |
| 708 | 711 | min_batch_size=${1:-100} | |
| 709 | - | INPUT_PO="po/review-input.po" | |
| 710 | - | PENDING="po/review-pending.po" | |
| 712 | + | INPUT_JSON="po/review-input.json" | |
| 713 | + | PENDING="po/review-pending.json" | |
| 711 | 714 | TODO="po/review-todo.json" | |
| 712 | 715 | DONE="po/review-done.json" | |
| 713 | 716 | BATCH_FILE="po/review-batch.txt" | |
| 714 | 717 | ||
| 715 | - | if test ! -f "$INPUT_PO" | |
| 718 | + | if test ! -f "$INPUT_JSON" | |
| 716 | 719 | then | |
| 717 | 720 | rm -f "$TODO" | |
| 718 | - | echo >&2 "cannot find $INPUT_PO, nothing for review" | |
| 721 | + | echo >&2 "cannot find $INPUT_JSON, nothing for review" | |
| 719 | 722 | return 1 | |
| 720 | 723 | fi | |
| 721 | - | if test ! -f "$PENDING" || test "$INPUT_PO" -nt "$PENDING" | |
| 724 | + | if test ! -f "$PENDING" || test "$INPUT_JSON" -nt "$PENDING" | |
| 722 | 725 | then | |
| 723 | 726 | rm -f "$BATCH_FILE" "$TODO" "$DONE" | |
| 724 | 727 | rm -f po/review-result*.json | |
| 725 | - | cp "$INPUT_PO" "$PENDING" | |
| 728 | + | cp "$INPUT_JSON" "$PENDING" | |
| 726 | 729 | fi | |
| 727 | 730 | ||
| 728 | 731 | ENTRY_COUNT=$(git-po-helper stat -c "$PENDING" 2>/dev/null || true) | |
| @@ -755,7 +758,7 @@ missing or empty (no batch left to review), or when step 1 finds | |||
| 755 | 758 | echo "$BATCH" >"$BATCH_FILE" | |
| 756 | 759 | ||
| 757 | 760 | git-po-helper msg-select --json --head "$NUM" -o "$TODO" "$PENDING" | |
| 758 | - | git-po-helper msg-select --since "$((NUM + 1))" -o "${PENDING}.tmp" "$PENDING" | |
| 761 | + | git-po-helper msg-select --json --since "$((NUM + 1))" -o "${PENDING}.tmp" "$PENDING" | |
| 759 | 762 | mv "${PENDING}.tmp" "$PENDING" | |
| 760 | 763 | echo "Processing batch $BATCH ($NUM entries out of $ENTRY_COUNT)" | |
| 761 | 764 | } | |