@@ -460,6 +460,13 @@ async function translateFileWithSections(client, file, systemPrompt, localesDir,
460460 let storedData = null ;
461461 try {
462462 storedData = JSON . parse ( await fs . readFile ( hashFile , 'utf-8' ) ) ;
463+ // Detect old-format positional paragraph IDs (e.g. "h2-foo-p1", "preamble-p3").
464+ // Paragraph IDs now use 8-char content hashes (e.g. "h2-foo-pa3f7c1b2") so any
465+ // cache entry ending in -p<digits> is stale — discard it to trigger re-seeding.
466+ if ( storedData ?. sections ) {
467+ const hasOldIds = Object . keys ( storedData . sections ) . some ( id => / - p \d + $ / . test ( id ) ) ;
468+ if ( hasOldIds ) storedData = { fileHash : storedData . fileHash } ;
469+ }
463470 } catch { /* no cache */ }
464471
465472 // Seed section cache from existing translation when no section-level cache exists.
@@ -1539,10 +1546,11 @@ function postProcessTranslation(content, lang) {
15391546 `from '../../../components/$1'`
15401547 ) ;
15411548
1542- // Ensure a blank line between import statements and headings .
1549+ // Ensure a blank line after the last import statement .
15431550 // The model sometimes strips the trailing blank line from the preamble section,
1544- // which causes MDX/acorn parse errors when an import is directly followed by ##.
1545- content = content . replace ( / ^ ( i m p o r t [ ^ \n ] + ) \n ( # { 1 , 6 } ) / gm, '$1\n\n$2' ) ;
1551+ // causing MDX/acorn parse errors when an import is directly followed by content
1552+ // (a heading, a paragraph, a callout, a component, etc.).
1553+ content = content . replace ( / ^ ( i m p o r t [ ^ \n ] + ) \n ( [ ^ \n ] ) / gm, '$1\n\n$2' ) ;
15461554
15471555 return content ;
15481556}
0 commit comments