Compare

b2bc011edd388c3e2f4d7e2b22d3463315faf6d5..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

Browse files
1 file changed, +47 −46
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,15 +529,14 @@ 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 - ENTRY_COUNT=$(grep -c '^msgid ' "$PENDING" 2>/dev/null || true)
538 + ENTRY_COUNT=$(git-po-helper stat -c "$PENDING" 2>/dev/null || true)
536 539 ENTRY_COUNT=${ENTRY_COUNT:-0}
537 - ENTRY_COUNT=$((ENTRY_COUNT > 0 ? ENTRY_COUNT - 1 : 0))
538 540 if test "$ENTRY_COUNT" -gt $min_batch_size
539 541 then
540 542 if test "$ENTRY_COUNT" -gt $((min_batch_size * 8))
@@ -572,20 +574,20 @@ step 8 after step 6.
572 574 (for plural entries); clear the fuzzy flag (omit or set `fuzzy` to `false`).
573 575 Do **not** modify `msgid` or `msgid_plural`.
574 576
575 - 5. **Validate `po/l10n-done.po`**:
577 + 5. **Validate `po/l10n-done.po.tmp`**:
576 578
577 579 Run the validation script below. If it fails, fix per the errors and notes,
578 580 re-run until it succeeds.
579 581
580 582 ```shell
581 583 l10n_validate_done () {
582 - DONE_PO="po/l10n-done.po"
584 + DONE_PO_TMP="po/l10n-done.po.tmp"
583 585 DONE_JSON="po/l10n-done.json"
584 - PENDING="po/l10n-pending.po"
586 + PENDING="po/l10n-pending.json"
585 587
586 - 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"; }
587 589 then
588 - 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" || {
589 591 echo "ERROR [JSON to PO conversion]: Fix $DONE_JSON and re-run." >&2
590 592 return 1
591 593 }
@@ -593,22 +595,22 @@ step 8 after step 6.
593 595
594 596 # Check 1: msgid should not be modified
595 597 MSGID_OUT=$(git-po-helper compare -q --msgid --assert-no-changes \
596 - "$PENDING" "$DONE_PO" 2>&1)
598 + "$PENDING" "$DONE_PO_TMP" 2>&1)
597 599 MSGID_RC=$?
598 600 if test $MSGID_RC -ne 0 || test -n "$MSGID_OUT"
599 601 then
600 602 echo "ERROR [msgid modified]: The following entries appeared after" >&2
601 - echo "translation because msgid was altered. Fix in $DONE_PO." >&2
603 + echo "translation because msgid was altered. Fix in $DONE_PO_TMP." >&2
602 604 echo "$MSGID_OUT" >&2
603 605 return 1
604 606 fi
605 607
606 608 # Check 2: PO format (see "Validating PO File Format" for error handling)
607 - MSGFMT_OUT=$(msgfmt --check -o /dev/null "$DONE_PO" 2>&1)
609 + MSGFMT_OUT=$(msgfmt --check -o /dev/null "$DONE_PO_TMP" 2>&1)
608 610 MSGFMT_RC=$?
609 611 if test $MSGFMT_RC -ne 0
610 612 then
611 - echo "ERROR [PO format]: Fix errors in $DONE_PO." >&2
613 + echo "ERROR [PO format]: Fix errors in $DONE_PO_TMP." >&2
612 614 echo "$MSGFMT_OUT" >&2
613 615 return 1
614 616 fi
@@ -618,43 +620,43 @@ step 8 after step 6.
618 620 l10n_validate_done
619 621 ```
620 622
621 - 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
622 624 `l10n_validate_done` until it succeeds. Editing `po/l10n-done.json` is not
623 625 recommended because it adds an extra JSON-to-PO conversion step. Use the
624 626 error message to decide:
625 627
626 628 - **`[msgid modified]`**: The listed entries have altered `msgid`; restore
627 - them to match `po/l10n-pending.po`.
629 + them to match `po/l10n-pending.json`.
628 630 - **`[PO format]`**: `msgfmt` reports line numbers; fix the errors in place.
629 631 See "Validating PO File Format" for common issues.
630 632
631 633
632 634 6. **Merge translation results into `po/XX.po`**: Run the script below. If it
633 635 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
636 + `po/l10n-done.json`; **`[msgcat merge]`** → `po/l10n-done.po.tmp`. Re-run until
635 637 it succeeds.
636 638
637 639 ```shell
638 640 l10n_merge_batch () {
639 641 test $# -ge 1 || { echo "Usage: l10n_merge_batch <po-file>" >&2; return 1; }
640 642 PO_FILE="$1"
641 - DONE_PO="po/l10n-done.po"
643 + DONE_PO_TMP="po/l10n-done.po.tmp"
642 644 DONE_JSON="po/l10n-done.json"
643 645 MERGED="po/l10n-done.merged"
644 646 TODO_JSON="po/l10n-todo.json"
645 - 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"; }
646 648 then
647 - 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" || {
648 650 echo "ERROR [JSON to PO conversion]: Fix $DONE_JSON and re-run." >&2
649 651 return 1
650 652 }
651 653 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 + msgcat --use-first "$DONE_PO_TMP" "$PO_FILE" >"$MERGED" || {
655 + echo "ERROR [msgcat merge]: Fix errors in $DONE_PO_TMP and re-run." >&2
654 656 return 1
655 657 }
656 658 mv "$MERGED" "$PO_FILE"
657 - rm -f "$TODO_JSON" "$DONE_JSON" "$DONE_PO"
659 + rm -f "$TODO_JSON" "$DONE_JSON" "$DONE_PO_TMP"
658 660 }
659 661 # Run the merge. Example: l10n_merge_batch po/zh_CN.po
660 662 l10n_merge_batch po/XX.po
@@ -688,7 +690,7 @@ missing or empty (no batch left to review), or when step 1 finds
688 690
689 691 1. **Check for existing review (resume support)**: Evaluate the following in order:
690 692
691 - - 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
692 694 entries) for a fresh start.
693 695 - Else If `po/review-result.json` exists, go to step 8 (only after loop exits).
694 696 - Else If `po/review-done.json` exists, go to step 6 (Rename result).
@@ -696,9 +698,9 @@ missing or empty (no batch left to review), or when step 1 finds
696 698 batch).
697 699 - Else go to step 3 (Prepare one batch).
698 700
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.
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.
702 704
703 705 3. **Prepare one batch**: Batching keeps each run small so the model can
704 706 complete review within limited context. **Directly execute** the script
@@ -707,28 +709,27 @@ missing or empty (no batch left to review), or when step 1 finds
707 709 ```shell
708 710 review_one_batch () {
709 711 min_batch_size=${1:-100}
710 - INPUT_PO="po/review-input.po"
711 - PENDING="po/review-pending.po"
712 + INPUT_JSON="po/review-input.json"
713 + PENDING="po/review-pending.json"
712 714 TODO="po/review-todo.json"
713 715 DONE="po/review-done.json"
714 716 BATCH_FILE="po/review-batch.txt"
715 717
716 - if test ! -f "$INPUT_PO"
718 + if test ! -f "$INPUT_JSON"
717 719 then
718 720 rm -f "$TODO"
719 - echo >&2 "cannot find $INPUT_PO, nothing for review"
721 + echo >&2 "cannot find $INPUT_JSON, nothing for review"
720 722 return 1
721 723 fi
722 - if test ! -f "$PENDING" || test "$INPUT_PO" -nt "$PENDING"
724 + if test ! -f "$PENDING" || test "$INPUT_JSON" -nt "$PENDING"
723 725 then
724 726 rm -f "$BATCH_FILE" "$TODO" "$DONE"
725 727 rm -f po/review-result*.json
726 - cp "$INPUT_PO" "$PENDING"
728 + cp "$INPUT_JSON" "$PENDING"
727 729 fi
728 730
729 - ENTRY_COUNT=$(grep -c '^msgid ' "$PENDING" 2>/dev/null || true)
731 + ENTRY_COUNT=$(git-po-helper stat -c "$PENDING" 2>/dev/null || true)
730 732 ENTRY_COUNT=${ENTRY_COUNT:-0}
731 - ENTRY_COUNT=$((ENTRY_COUNT > 0 ? ENTRY_COUNT - 1 : 0))
732 733 if test "$ENTRY_COUNT" -eq 0
733 734 then
734 735 rm -f "$TODO"
@@ -757,7 +758,7 @@ missing or empty (no batch left to review), or when step 1 finds
757 758 echo "$BATCH" >"$BATCH_FILE"
758 759
759 760 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 + git-po-helper msg-select --json --since "$((NUM + 1))" -o "${PENDING}.tmp" "$PENDING"
761 762 mv "${PENDING}.tmp" "$PENDING"
762 763 echo "Processing batch $BATCH ($NUM entries out of $ENTRY_COUNT)"
763 764 }