Skip to content

Commit bd1068f

Browse files
pattonwebzclaude
andcommitted
Keep translators comments in the built bundles
The make-pot run on develop reported 27 strings with placeholders and no `translators:` comment, and every one of them is in build/*.bundle.js - none in PHP. Adding those comments to src/ would have had no effect: Terser's default `format.comments` keeps only license banners, so the comments were being stripped before `wp i18n make-pot` ever saw the bundle. The result would have been 27 comments written, a rebuild, and no change to either the warnings or the POT. Verified with a real webpack run using this repo's exact terserOptions: current config comment stripped, LICENSE.txt emitted + format.comments = /translators:/i comment kept, LICENSE.txt emitted + extractComments: false as well comment kept, LICENSE.txt dropped So only the format.comments line is added. @wordpress/scripts also sets extractComments: false in its own config, but copying that here would stop the 8 *.bundle.js.LICENSE.txt files being emitted for no benefit - preserving a comment and extracting one are separate things. Confirmed end to end that make-pot then picks it up from minified output, which is the part that was not obvious: Terser keeps the comment on its own line ahead of the statement, and make-pot associates it correctly. #. translators: 1: current issue number, 2: total issues #: build/b.bundle.js:4 #, js-format msgid "Issue %1$d of %2$d" The warning disappears for that string, and both the `#.` comment and the `#,` flag are kept by make-pot.yml's diff filter, so documenting these strings will correctly be detected as a POT change and raise the update PR. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019LoLgW7oFjBPxGea9kiZJ2
1 parent cc72684 commit bd1068f

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

webpack.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ module.exports = {
6969
reserved: [ '__', '_n', '_x', '_nx' ], // Prevent webpack from using these translation function names and mangling them in the source.
7070
},
7171
keep_fnames: /(__|_n|_x|_nx)$/,
72+
format: {
73+
// Keep `translators:` comments in the built bundles. Terser's
74+
// default drops every comment except license banners, and
75+
// `wp i18n make-pot` scans build/*.bundle.js rather than src/,
76+
// so without this a translators comment written in src/ never
77+
// reaches the POT and the string stays undocumented.
78+
// This only preserves the comment, it does not extract it, so
79+
// the existing *.LICENSE.txt output is unaffected.
80+
comments: /translators:/i,
81+
},
7282
},
7383
} ),
7484
new CssMinimizerPlugin(),

0 commit comments

Comments
 (0)