From 53a25b54aad54ada5896805f0a07932533a37dfa Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Thu, 30 Jul 2026 23:55:47 +0000 Subject: [PATCH 1/3] Translate the Swedish source comments to English (GitHub #29) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #29 ## Reasoning The original author's comments were Swedish throughout, which meant half the explanatory context in a 7000-line file was unreadable to most of the people and tools now maintaining it. 103 comment lines translated. Scope is comments only, as the issue specified. Identifiers stay Swedish -- $sidor, %behandlad, $utfil, skrivSida(), analysera(). Renaming them would touch hundreds of lines across a file with thin test coverage for zero functional gain, and it is a separate decision. A translated comment above Swedish identifiers still helps: "# Find pages" over the $sidor logic is more than was there before. The issue estimated 64 lines by counting non-ASCII. The real figure is 103 -- many Swedish comments are pure ASCII ("Hitta root", "Behandla en bild") and do not show up in a byte scan. Translating them all leaves the file with zero non-ASCII bytes, which incidentally makes the #27 encoding question permanently moot rather than merely resolved. Judgement calls worth recording: - "Hängslen" / "Svångrem för att undvika oändliga loopar" is the Swedish idiom "hängslen och svångrem", belt and braces. Rendered as "# Belt" / "# and braces, to avoid infinite loops" to keep the pairing rather than flattening both to "guard against infinite loops". - Six comments appear twice on duplicated code paths (getPage/byggForm and the two resource-dictionary blocks). Verified they sit on genuinely parallel code before applying one translation to both. - Passive Swedish constructions ("Objekten sorteras", "Resurserna läses") are rendered as imperatives where the comment describes what the code does next, since that reads as a code comment in English rather than a narration. ## Verification The diff is comment-only, and that is checked rather than claimed: 103 added, 103 removed, and for every changed line the text before the '#' is byte-identical. Zero lines where code moved. 40 tests pass. t/Reuse.t compares generated PDF output byte-for-byte against its __DATA__ block and needed no edit. podchecker still passes. Confirmed nothing was missed: zero non-ASCII bytes remain, and a scan for distinctly Swedish tokens with no English homographs returns nothing. --- lib/PDF/Reuse.pm | 206 +++++++++++++++++++++++------------------------ 1 file changed, 103 insertions(+), 103 deletions(-) diff --git a/lib/PDF/Reuse.pm b/lib/PDF/Reuse.pm index 89108b6..f556355 100644 --- a/lib/PDF/Reuse.pm +++ b/lib/PDF/Reuse.pm @@ -75,7 +75,7 @@ our $ddir = ''; our $log = ''; ######################### -# Konstanter för objekt +# Constants for objects ######################### use constant oNR => 0; @@ -90,7 +90,7 @@ use constant oTYPE => 8; use constant oNAME => 9; ################################### -# Konstanter för formulär +# Constants for forms ################################### use constant fOBJ => 0; @@ -104,7 +104,7 @@ use constant fID => 7; use constant fVALID => 8; #################################### -# Konstanter för images +# Constants for images #################################### use constant imWIDTH => 0; @@ -116,7 +116,7 @@ use constant imYSCALE => 5; use constant imIMAGENO => 6; ##################################### -# Konstanter för interaktiva objekt +# Constants for interactive objects ##################################### use constant iNAMES => 1; @@ -127,7 +127,7 @@ use constant iSTARTSIDA => 5; use constant iAAPAGE => 6; ##################################### -# Konstanter för fonter +# Constants for fonts ##################################### use constant foREFOBJ => 0; @@ -139,7 +139,7 @@ use constant foTYP => 5; use constant foFONTOBJ => 6; ########## -# Övrigt +# Miscellaneous ########## use constant IS_MODPERL => $ENV{MOD_PERL}; # For mod_perl 1. @@ -338,7 +338,7 @@ sub prFile @kids = (); @counts = (); @objekt = (); - $objNr = 2; # Reserverat objekt 1 för root och 2 för initial sidnod + $objNr = 2; # Object 1 reserved for root and 2 for the initial page node $parents[0] = 2; $page = 0; $formNr = 0; @@ -402,7 +402,7 @@ sub prPage $sidObjNr = $objNr; # - # Resurserna nollställs + # Reset the resources # %sidXObject = (); @@ -461,7 +461,7 @@ sub prText if (! $aktuellFont[foINTNAMN]) { findFont(); } - my $Font = $aktuellFont[foINTNAMN]; # Namn i strömmen + my $Font = $aktuellFont[foINTNAMN]; # Name in the stream $sidFont{$Font} = $aktuellFont[foREFOBJ]; my $fontname = $aktuellFont[foEXTNAMN]; my $ttfont = $font{$fontname} ? $font{$fontname}[foFONTOBJ] : undef; @@ -576,7 +576,7 @@ sub prAdd } ########################## -# Ett grafiskt "formulär" +# A graphical "form" ########################## sub prForm @@ -649,11 +649,11 @@ sub prForm } else { if ($tolerant) - { if ((defined $refNr) && ($refNr eq '0')) # Sidnumret existerar inte, men ok + { if ((defined $refNr) && ($refNr eq '0')) # The page number does not exist, but that is ok { $namn = '0'; } else - { undef $namn; # Sidan kan inte användas som form + { undef $namn; # The page cannot be used as a form } } elsif (! defined $refNr) @@ -770,18 +770,18 @@ sub prDefaultGrState } ###################################################### -# En font lokaliseras och fontobjektet skrivs ev. ut +# Locate a font and write out the font object if needed ###################################################### sub findFont { no warnings; my $Font = shift || ''; - if (! (exists $fontSource{$Font})) # Fonten måste skapas + if (! (exists $fontSource{$Font})) # The font must be created { if (exists $stdFont{$Font}) { $Font = $stdFont{$Font};} else - { $Font = $genFont; } # Helvetica sätts om inget annat finns + { $Font = $genFont; } # Helvetica is used if nothing else is available if (! (exists $font{$Font})) { $objNr++; $fontNr++; @@ -797,7 +797,7 @@ sub findFont } } else - { if (defined $font{$Font}[foREFOBJ]) # Finns redan i filen + { if (defined $font{$Font}[foREFOBJ]) # Already present in the file { ; } else { if ($fontSource{$Font}[foSOURCE] eq 'Standard') @@ -863,7 +863,7 @@ sub skrivSida my $parent = $parents[0]; ########################################## - # Interaktiva funktioner läggs ev. till + # Interactive functions are added if needed ########################################## if ($interAktivSida) @@ -925,12 +925,12 @@ sub skrivSida my $resursObjekt; if (exists $resurser{$resursDict}) - { $resursObjekt = $resurser{$resursDict}; # Fanns ett identiskt, - } # använd det + { $resursObjekt = $resurser{$resursDict}; # An identical one existed, + } # use that one else { $objNr++; if ( keys(%resurser) < 10) - { $resurser{$resursDict} = $objNr; # Spara 10 första resursobjekten + { $resurser{$resursDict} = $objNr; # Save the first 10 resource objects } $resursObjekt = $objNr; $objekt[$objNr] = $pos; @@ -941,7 +941,7 @@ sub skrivSida if (! $touchUp) { # - # Contents objektet skapas + # Create the Contents object # my $devX = "900"; @@ -1010,7 +1010,7 @@ sub skrivSida $pos += syswrite UTFIL, $streamObjekt; $streamObjekt = $objNr; ################################## - # Så skapas och skrivs sidobjektet + # Then create and write the page object ################################## $sidObjekt = "$sidObjNr 0 obj< $VERSION might give different results, if comparing two runs \n"; @@ -4558,7 +4558,7 @@ sub xRefs ($Root) || errLog("The Root object in $infil couldn't be found, aborting"); ############################################################## - # Objekten sorteras i fallande ordning (efter offset i filen) + # Sort the objects in descending order (by offset in the file) ############################################################## my @offset = sort { $oldObject{$b} <=> $oldObject{$a} } keys %oldObject; @@ -4703,7 +4703,7 @@ sub xrefSection { my ($nr, $xref, $infil) = @_; my ($i, $root, $antal); $nr++; - $oldObject{('xref' . "$nr")} = $xref; # Offset för xref sparas + $oldObject{('xref' . "$nr")} = $xref; # The offset for xref is saved sysseek INFIL, $xref, 0; sysread INFIL, my $buf, 30; if ($buf =~ /xref/) { @@ -4943,7 +4943,7 @@ sub unZipPrepare } ############################################ -# En definitionerna för en sida extraheras +# Extract the definitions for a page ############################################ sub getPage @@ -5001,7 +5001,7 @@ sub getPage } ############# - # Hitta root + # Find root ############# my $objektet = getObject($root);; @@ -5014,9 +5014,9 @@ sub getPage { $Names = $1; } ################################################# - # Finns ett dictionary för Additional Actions ? + # Is there a dictionary for Additional Actions ? ################################################# - if ($objektet =~ m|/AA$ws*\<\<$ws*[^\>]+[^\>]+|so) # AA är ett dictionary + if ($objektet =~ m|/AA$ws*\<\<$ws*[^\>]+[^\>]+|so) # AA is a dictionary { my $k; my ($dummy, $obj) = split /\/AA/, $objektet; $obj =~ s/\<\ $sidnr) || ($bryt2 > $sidnr)) # Bryt oändliga loopar + if (($bryt1 > $sidnr) || ($bryt2 > $sidnr)) # Break infinite loops { last; } } @@ -5106,16 +5106,16 @@ sub getPage if ($sidor == 1) { ################################################# - # Kontrollera Page-objektet för annoteringar + # Check the Page object for annotations ################################################# if ($objektet =~ m|/Annots$ws*([^\/]+)|so) { $Annots = $1; } ################################################# - # Finns ett dictionary för Additional Actions ? + # Is there a dictionary for Additional Actions ? ################################################# - if ($objektet =~ m|/AA$ws*\<\<$ws*[^\>]+[^\>]+|so) # AA är ett dictionary. Hela kopieras + if ($objektet =~ m|/AA$ws*\<\<$ws*[^\>]+[^\>]+|so) # AA is a dictionary. The whole thing is copied { my $k; my ($dummy, $obj) = split /\/AA/, $objektet; $obj =~ s/\<\[fNOKIDS]}) @@ -5573,7 +5573,7 @@ sub byggForm } ####################################################### - # Objekt med referenser kopieras, behandlas och skrivs + # Objects with references are copied, processed and written ####################################################### for my $key (@{$form{$fSource}->[fKIDS]}) { if ((defined $old{$key}) && ($objekt[$old{$key}])) # already processed @@ -5612,7 +5612,7 @@ sub byggForm } ################################# - # Formulärobjektet behandlas + # Process the form object ################################# my $key = $form{$fSource}->[fMAIN]; @@ -5653,7 +5653,7 @@ sub byggForm } ################## -# En bild läses +# Read an image ################## sub getImage @@ -5693,7 +5693,7 @@ sub getImage binmode INFIL; ######################################################### - # En bild med referenser kopieras, behandlas och skrivs + # An image with references is copied, processed and written ######################################################### $nr = ++$objNr; @@ -5712,7 +5712,7 @@ sub getImage } $pos += syswrite UTFIL, $utrad; ################################## - # Skriv ut underordnade objekt + # Write out subordinate objects ################################## while (scalar @skapa) { my @process = @skapa; @@ -5741,7 +5741,7 @@ sub getImage } ############################################################## -# Interaktiva funktioner knutna till ett formulär återskapas +# Interactive functions attached to a form are recreated ############################################################## sub AcroFormsEtc @@ -5782,7 +5782,7 @@ sub AcroFormsEtc } ################################## - # Referenser behandlas och skrivs + # References are processed and written ################################## if (defined $intAct{$fSource}[iACROFORM]) @@ -5805,7 +5805,7 @@ sub AcroFormsEtc } ################################## - # Skriv ut underordnade objekt + # Write out subordinate objects ################################## while (scalar @skapa) { my @process = @skapa; @@ -5845,7 +5845,7 @@ sub AcroFormsEtc } ############################## -# Ett namnobjekt extraheras +# Extract a name object ############################## sub extractName @@ -5891,7 +5891,7 @@ sub extractName binmode INFIL; ################################# - # Resurserna läses + # Read the resources ################################# $formRes = $form{$fSource}->[fRESOURCE]; @@ -6011,7 +6011,7 @@ sub extractName $pos += syswrite UTFIL, $utrad; ################################## - # Skriv ut underordnade objekt + # Write out subordinate objects ################################## while (scalar @skapa) @@ -6042,7 +6042,7 @@ sub extractName } ######################## -# Ett objekt extraheras +# Extract an object ######################## sub extractObject @@ -6171,7 +6171,7 @@ sub extractObject $pos += syswrite UTFIL, $utrad; ################################## - # Skriv ut underordnade objekt + # Write out subordinate objects ################################## while (scalar @skapa) @@ -6203,7 +6203,7 @@ sub extractObject ########################################## -# En fil analyseras och sidorna kopieras +# Analyse a file and copy the pages ########################################## sub analysera @@ -6250,7 +6250,7 @@ sub analysera { $root = xRefs($stati[7], $infil); } ############# - # Hitta root + # Find root ############# my $offSet; @@ -6272,11 +6272,11 @@ sub analysera } ################################################# - # Finns ett dictionary för Additional Actions ? + # Is there a dictionary for Additional Actions ? ################################################# - if ($objektet =~ m|/AA($ws+\d+$ws+\d+$ws+R)|os) # Hänvisning + if ($objektet =~ m|/AA($ws+\d+$ws+\d+$ws+R)|os) # Reference { $AARoot = $1; } - elsif ($objektet =~ m|/AA$ws*\<\<$ws*[^\>]+[^\>]+|so) # AA är ett dictionary + elsif ($objektet =~ m|/AA$ws*\<\<$ws*[^\>]+[^\>]+|so) # AA is a dictionary { my $k; my ($dummy, $obj) = split /\/AA/, $objektet; $obj =~ s/\<\>endobj\n"; @@ -6714,7 +6714,7 @@ sub sidAnalys { $del1 .= "/Resources $resources"; } - if (defined $streamObjekt) # En ny ström ska läggas till + if (defined $streamObjekt) # A new stream is to be added { if ($del1 =~ m|/Contents$ws+(\d+)$ws+\d+$ws+R|os) { my $oldCont = $1; $del1 =~ s|/Contents$ws+(\d+)$ws+\d+$ws+R|'/Contents [' . "$oldCont 0 R $streamObjekt" . ']'|oes; @@ -6819,7 +6819,7 @@ sub behandlaNames my $antal = 0; my $antNodUpp = 0; if ($namnObj) - { if ($iForm) # Läsning via interntabell + { if ($iForm) # Read via the internal table { $objektet = getObject($namnObj, 1); if ($objektet =~ m'<<(.+)>>'ogs) @@ -6849,7 +6849,7 @@ sub behandlaNames } } } - else # Läsning av ett "doc" + else # Read a "doc" { $objektet = getObject($namnObj); if ($objektet =~ m'<<(.+)>>'ogs) { $objektet = $1; } @@ -6891,8 +6891,8 @@ sub behandlaNames { if (exists $nyaFunk{$key}) { $initScript{$key} = $nyaFunk{$key}; } - if (exists $script{$key}) # företräde för nya funktioner ! - { delete $script{$key}; # gammalt script m samma namn plockas bort + if (exists $script{$key}) # new functions take precedence ! + { delete $script{$key}; # old script with the same name is removed } my @fall = ($initScript{$key} =~ m'([\w\d\_\$]+)\s*\('ogs); for (@fall) @@ -6984,7 +6984,7 @@ sub behandlaNames } } if ($antal > 0) - { if ($antNodUpp == 0) # inget i noderna över + { if ($antNodUpp == 0) # nothing in the nodes above { $obj .= ']>>' . "endobj\n"; $pos += syswrite UTFIL, $obj; } From d783161319f886f7afa1a6ea4d6fe253dd85620f Mon Sep 17 00:00:00 2001 From: "vsits-codex-review-agent[bot]" <279859562+vsits-codex-review-agent[bot]@users.noreply.github.com> Date: Fri, 31 Jul 2026 00:01:28 +0000 Subject: [PATCH 2/3] Add Codex review for PR 35 round 1 --- docs/reviews/pr-35-round-1-codex.md | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 docs/reviews/pr-35-round-1-codex.md diff --git a/docs/reviews/pr-35-round-1-codex.md b/docs/reviews/pr-35-round-1-codex.md new file mode 100644 index 0000000..a386d25 --- /dev/null +++ b/docs/reviews/pr-35-round-1-codex.md @@ -0,0 +1,38 @@ +# Review: PR #35 Swedish source comment translation + +Date: 2026-07-30 +Reviewed: `lib/PDF/Reuse.pm` at `53a25b54aad54ada5896805f0a07932533a37dfa` +Round: 1 +Label applied: `changes-requested` + +## What Is Correct + +The PR is limited to one file, `lib/PDF/Reuse.pm`, with a one-for-one comment translation shape: 103 added lines and 103 deleted lines. + +I independently verified the no-code-change claim with a diff parser over `origin/master...HEAD`: for each changed line, the byte string before the first `#` is identical between the removed and added sides. The check reported 103 removed lines, 103 added lines, and 0 prefix mismatches. + +The duplicated translations around the resource-dictionary reuse blocks are on parallel code paths. The `skrivSida` block at lines 927-934 and the `sidAnalys` block at lines 6636-6643 both check `%resurser`, reuse an existing identical resource object, and save the first 10 resource objects. A single rendering is appropriate in both places. + +The duplicated tolerant-page comments in `prForm` and `prDocForm` also sit on parallel code paths. The same English rendering fits both contexts. + +Leaving Swedish identifiers in place is the right scope call for this PR. Renaming identifiers in a 7000-line CPAN-shipped module would be a functional-risk change with little direct value for the comment-translation issue. + +## Blockers + +1. `lib/PDF/Reuse.pm:5072` translates the first half of the Swedish idiom incorrectly when read line-by-line. `Hängslen` is the braces/suspenders side, while `Svångrem` is the belt side. The current English split makes line 5072 say `# Belt`, which is the wrong word for that Swedish source line and is misleading as a standalone code comment. Prefer neutral comments such as `# Loop guard 1` and `# Loop guard 2, to avoid infinite loops`, or otherwise avoid splitting the English idiom across the two declarations. + +## What Needs Attention + +None beyond the blocker. + +## Bloat / Non-Functional + +None. The diff is 103 additions and 103 deletions, all in comment text, so it does not trigger the additive-change concern. + +## Recommendations + +Replace the split idiom at lines 5072-5073 with direct guard wording. That keeps the intent clear and avoids relying on an English idiom spread across two unrelated scalar declarations. + +## Bottom Line + +Revise before merge. The implementation is mechanically comment-only and the broad translation choices look sound, but the idiom at lines 5072-5073 should be corrected because this PR's core risk is a confidently wrong English comment. From 42fd3995868684684b87e5649d5d4b3d4eb75939 Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Fri, 31 Jul 2026 00:04:15 +0000 Subject: [PATCH 3/3] Fix the belt-and-braces idiom translation (Codex review of #35) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ref #29 ## Reasoning I had the two halves of the idiom backwards. "Hängslen" is braces/suspenders and "svångrem" is the belt, so rendering line 5072 as "# Belt" put the wrong word against the wrong Swedish source line. Verified rather than taken on authority: hängslen are the shoulder straps, svångrem the waist belt, and the Swedish idiom "hängslen och svångrem" corresponds to English "belt and braces" with the order reversed -- which is exactly the trap. The deeper problem was splitting an English idiom across two unrelated scalar declarations. Even correctly ordered, "# Braces" sitting alone on one line is not a useful code comment; it only means anything once the reader has found the other half. A confidently wrong or cryptic English comment is worse than the Swedish it replaced, because a reader will trust it rather than go look at the code. Now each line carries a comment that stands on its own, with the idiom intact on the second where it reads correctly: my $bryt1 = -20; # Loop guard 1 my $bryt2 = -20; # Loop guard 2 -- belt and braces against infinite loops Kept the idiom rather than dropping it entirely, per Codex's "or otherwise avoid splitting" alternative: the author's joke is apt, since $bryt1 and $bryt2 really are two redundant counters OR-checked at line 5100, and the redundancy is the point. ## Verification 40 tests pass. The comment-only property still holds against master: stripping every comment from both sides yields byte-identical text. --- lib/PDF/Reuse.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/PDF/Reuse.pm b/lib/PDF/Reuse.pm index f556355..68460d9 100644 --- a/lib/PDF/Reuse.pm +++ b/lib/PDF/Reuse.pm @@ -5069,8 +5069,8 @@ sub getPage { push @sidObj, $1; } - my $bryt1 = -20; # Belt - my $bryt2 = -20; # and braces, to avoid infinite loops + my $bryt1 = -20; # Loop guard 1 + my $bryt2 = -20; # Loop guard 2 -- belt and braces against infinite loops while ($sidAcc < $sidnr) { @underObjekt = @sidObj;