-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overriding minified JavaScript file exclusion in i18n make-pot #174
Comments
From @swissspidy
From the code in #87 it seems I should be using |
I wish to include all PHP files except specific directories (e.g. So while it solves the minified JS problem it creates a new problem when attempting to include/ignore PHP files. |
I've also been testing the It seems to work for unminified files but files that have been passed through uglify, even with Here is an example minified JS file: "use strict";wp.domReady(function(){var e=wp.i18n.__;wp.blocks.registerBlockStyle("core/list",{name:"checkmark-list",label:e("Checkmark","wp-rig")})}); edit: here is the source file that minified JS was created from: /**
* File editor-filters.js.
*
* Modify the behavior of the block editor.
*/
wp.domReady( function() {
const { __ } = wp.i18n;
wp.blocks.registerBlockStyle( 'core/list', {
name: 'checkmark-list',
label: __( 'Checkmark', 'wp-rig' ),
} );
} );
|
To try and provide some better context to what we are doing, WP Rig runs as a development theme. There is a gulp workflow to compile CSS/JS, optimize images, run BrowserSync, etc. That process has lots of dev dependencies and overhead but allows developers to work efficiently. Once development is done there is a gulp task to bundle a production version of the theme. This production version does not contain unnecessary files, such as dev dependencies and un-minified source files. Instead, a new directory is created with just what is needed for production. Once the production theme is built, I would like to use wp-cli to generate the An additional challenge here is that wp-cli is being run as a |
Include/excludes are based on scores since #104, which means a more exact match takes precedence.
That is absolutely correct and I think the main issue you're running into here. No string extraction tool would like this. Tools like WP-CLI's You'd need to ensure that You mentioned PS. you'd need to make sure to preserve NB: ideally you would run the string extraction on the source files in Unfortunately we don't have the best solution for this scenario just yet, see #127. |
Thank you for all the information @swissspidy. Currently, our production build does not ship source files, which would be problematic for using them as a translation source. I am going to recommend that we completely skip file minification when WP Rig creates translation files. Currently, translation creation is opt-out but I think we will need to flip that and make it opt-in. |
I just had problems extracting strings from a minified JS file too. First of all I deactivated optimization but the file was still ignored. Then I tried all kind of versions without success. After debugging for some hours I renamed the file from gutenberg.min.js to gutenberg.js and it suddenly worked. Are some file patterns automatically excluded or are the two dots a problem? |
Well, a.b.js works but a.min.js doesn't. Again, the JS content is not minified only the file name makes the difference. |
Got it to work with --include="*.min.js". |
@cbratschi Yes, see i18n-command/src/MakePotCommand.php Lines 41 to 44 in b02ecdc
|
I am struggling with minified JavaScript files being ignored by the
i18n make-pot
command implementing translations in WP Rig.The WP Rig starter theme, and other projects (e.g. the
create-guten-block
framework mentioned here), have both source JavaScript files and compiled, minified JavaScript files.The JavaScript developers write is run through a build process and turned into the JavaScript files consumed by WordPress. This may mean transpiling JavaScript not yet supported by browsers, running minification, etc.
An example of our specific directory structure is:
Files in
assets/js/src
are the ones edited by developers and a gulp build process creates the files inassets/js
that are used by WordPress.Even when the gulp build process uses the
keep_fnames
option ofuglify
, which will keep all function names from being transformed,wp i18n make-pot
ignores JavaScript files with.min
in the name.edit: the command I am attempting to run is
wp i18n make-pot . languages/wp-rig.pot --exclude=vendor,node_modules,.git,gulp,tests,config,optional,assets/js/src
.However, these are the files I wish to generate a
.pot
file from as they are the ones being enqueued in WordPress, not the source files.WP-CLI has a hard-coded
exclude
array for thei18n make-pot
command that can not be overwritten with the--include
or--exclude
options.I would like for a way to negate the exclusion of minified JavaScript files when creating the
.pot
file in this case (they should remain excluded by default).Maybe a new option
force_include
which gets run afterinclude
andexclude
?The text was updated successfully, but these errors were encountered: