5454 if ( data [ key ] ) {
5555 /** @type {string[] } */
5656 const values = Array . isArray ( data [ key ] ) ? data [ key ] : [ data [ key ] ] ;
57- values . forEach ( ( value ) => {
58- if ( value . trim ( ) ) {
57+ values . forEach ( ( rawValue ) => {
58+ const value = rawValue . trim ( ) ;
59+ if ( value ) {
5960 if ( ! translationsMap . has ( value ) ) {
6061 translationsMap . set ( value , [ ] ) ;
6162 }
@@ -201,9 +202,9 @@ try {
201202
202203 console . log ( 'ℹ️ Creating .POT content...' ) ;
203204 // Step 3: Build POT content
205+ const generatedMsgids = new Set ( ) ;
204206 translationsMap . forEach ( ( files , value ) => {
205207 const uniqueFiles = [ ...new Set ( files ) ] ;
206- potContent += uniqueFiles . map ( ( file ) => `#: ${ file } ` ) . join ( '\n' ) + '\n' ;
207208
208209 // Handle multi-line strings
209210 const escapedValue = value
@@ -213,14 +214,27 @@ try {
213214 /** @type {string[] } */
214215 let lines = escapedValue . split ( '\n' ) ;
215216 lines = lines . filter ( ( line ) => line . trim ( ) ) ;
216- potContent +=
217- 'msgid ' +
218- lines
219- . map ( ( line , index ) =>
220- index === lines . length - 1 ? `"${ line } "` : `"${ line } \\n"`
221- )
222- . join ( '\n' ) +
223- '\n' ;
217+ const msgidContent = lines
218+ . map ( ( line , index ) =>
219+ index === lines . length - 1 ? `"${ line } "` : `"${ line } \\n"`
220+ )
221+ . join ( '\n' ) ;
222+
223+ // Skip if this msgid was already generated (safety net for edge cases
224+ // where two different source strings produce the same msgid after escaping).
225+ if ( generatedMsgids . has ( msgidContent ) ) {
226+ console . warn (
227+ `⚠️ Skipping duplicate msgid ${ msgidContent . slice (
228+ 0 ,
229+ 60
230+ ) } (from: ${ uniqueFiles . join ( ', ' ) } )`
231+ ) ;
232+ return ;
233+ }
234+ generatedMsgids . add ( msgidContent ) ;
235+
236+ potContent += uniqueFiles . map ( ( file ) => `#: ${ file } ` ) . join ( '\n' ) + '\n' ;
237+ potContent += 'msgid ' + msgidContent + '\n' ;
224238 potContent += 'msgstr ""\n\n' ;
225239 } ) ;
226240
0 commit comments