cedaro / grunt-wp-i18n

Internationalize WordPress themes and plugins with Grunt.
MIT License
160 stars 25 forks source link

Warning: Cannot read property 'split' of undefined #66

Closed pixeline closed 8 years ago

pixeline commented 8 years ago

Hello, While working on a WP Theme, I keep getting this error message: Warning: Cannot read property 'split' of undefined. I can't seem to make sense of it. Can you help ?

Here is the dump


Running "makepot:target" (makepot) task
Verifying property makepot.target exists in config...OK
File: [no files]
Options: cwd="src/", domainPath="languages", exclude=["assets/**/*","acf-json/.*","layouts/.*"], include=[], i18nToolsPath="/Users/xxx/GITHUB/yyyyy/node_modules/grunt-wp-i18n/vendor/wp-i18n-tools", mainFile="", potComments="Base Digital 2016", potFilename="filename.pot", potHeaders={"poedit":true,"x-poedit-keywordslist":true}, processPot=null, type="wp-plugin", updateTimestamp, updatePoFiles=false
Reading 404.php...OK
Reading archive.php...OK
Reading footer-clean.php...OK
Reading footer.php...OK
Reading front-page.php...OK
Reading functions.php...OK
Reading header.php...OK
Reading index.php...OK
Reading page.php...OK
Reading page_parent.php...OK
Reading search.php...OK
Reading single.php...OK
Warning: Cannot read property 'split' of undefined Use --force to continue.

Aborted due to warnings.

Here is the task config :

/**
         * Generate translation file.
         */
        makepot: {
            target: {
                options: {
                    cwd: '<%= project.src_dir %>',
                    // Directory of files to internationalize.
                    domainPath: 'languages',
                    // Where to save the POT file.
                    exclude: ['assets/**/*', 'acf-json/.*', 'layouts/.*'],
                    // List of files or directories to ignore.
                //  include: [],
                    // List of files or directories to include.
                //  mainFile: '',
                    // Main project file.
                    potComments: 'My Company 2016',
                    // The copyright at the beginning of the POT file.
                    potFilename: 'filename.pot',
                    // Name of the POT file.
                    potHeaders: {
                        poedit: true,
                        // Includes common Poedit headers.
                        'x-poedit-keywordslist': true // Include a list of all possible gettext functions.
                    },
                    type: 'wp-plugin',  // Type of project (wp-plugin or wp-theme).
                    updateTimestamp: true, // Whether the POT-Creation-Date should be updated without other changes.
                    updatePoFiles: false // Whether to update PO files in the same directory as the POT file.
                }
            }
        },
GaryJones commented 8 years ago

What version of grunt-wp-i18n are you using?

pixeline commented 8 years ago

Package.json says: "grunt-wp-i18n": "^0.5.4"

npm list --depth=0 prints grunt-wp-i18n@0.5.4

GaryJones commented 8 years ago

You've got mainFile commented out, so this package tries to guess which is the main plugin file. Your main file .php filename should match your plugin slug i.e. `wp-content/plugin/my-foobar-plugin/my-foobar-plugin.php. If it's not, either rename the file, or populate mainFile.

pixeline commented 8 years ago

Thank you very much Gary. In the case of a WP Theme, what is the "main" file: style.css, functions.php, ... ?

GaryJones commented 8 years ago

It's style.css, but in this case the problem is now obvious - you've got type set to wp-plugin. Update that to wp-theme (keep mainFile commented out if you want), and it should work.

I've made the same mistake in the past.

Reference: https://github.com/cedaro/grunt-wp-i18n/blob/develop/tasks/lib/wordpress.js#L46-L63

pixeline commented 8 years ago

Oh my gosh _ I can't believe I overlooked that. Thank you and awefully sorry for wasting your time. It now works perfectly.