Giter Site home page Giter Site logo

grunt-wp-i18n's Introduction

grunt-wp-i18n Build Status

Internationalize WordPress plugins and themes.

WordPress has a robust suite of tools to help internationalize plugins and themes. This plugin brings the power of those existing tools to Grunt in order to make it easy for you to automate the i18n process and make your projects more accessible to an international audience.

If you're not familiar with i18n concepts, read the Internationalization entries in the Plugin Developer Handbook or Theme Developer Handbook.

Getting Started

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-wp-i18n --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks( 'grunt-wp-i18n' );

Requirements

  • This plugin requires Grunt ^1.0.0.
  • PHP CLI must be in your system path.

Tasks

This plugin consists of two configurable tasks:

grunt-wp-i18n's People

Contributors

andreg avatar atimmer avatar bradyvercher avatar claudiosanches avatar garyjones avatar marcochiesi avatar ntwb avatar rdoursenaud avatar shakyshane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-wp-i18n's Issues

Reduce dependencies: include WP i18n tools

Distributing a tool like this throughout a team becomes much easier if the only dependency is node and grunt. It think that the WP i18n tools should be wrapped into the npm package. The tools are not that heavy, so adding them wouldn't have much of an adverse impact.

Adjust docs for options.potHeaders

Hi!
First of all a big thank you for your grunt task! It makes things so much nicer to handle!

I'd like to suggest, that you adjust the docs for options.potHeaders to reflect the fact that one is required to use them lowercased to replace existsing headers. It took quite a while to realise that as the result has them uppercased again.

Disabling potComments

Hello,

Trying to disable/remove the copyright notice at the beginning of the .pot file, can someone tell if there's a better alternative to the following?

makepot: {
    target: {
        options: {
            potComments: ' '
        }
    }
}

Note the needed space between ' '.

I've tried setting it to ''. And false, which displays the following error:

Fatal error: o.potComments.replace is not a function

Exclude page templates

I was trying to exclude a page template from the makepot. After looking at the code I realized it is not possible.

It would be nice if the code would first check if the file excluded before running
$potextmeta->append( $dir . '/' . $file, $output, array( 'Template Name' ) )

Load Plugin Information according to wish

        // Generate POT files.
        makepot: {
            options: {
                type: 'wp-plugin',
                domainPath: 'i18n/languages',
                potHeaders: {
                    'report-msgid-bugs-to': 'https://github.com/axisthemes/axis-builder/issues',
                    'language-team': 'LANGUAGE <EMAIL@ADDRESS>'
                }
            },
            frontend: {
                options: {
                    potFilename: 'axisbuilder.pot',
                    exclude: [
                        'api/.*',
                        'tmp/.*',
                        'tests/.*',
                        'includes/admin/.*'
                    ],
                    processPot: function ( pot ) {
                        pot.headers['project-id-version'] += ' Frontend';
                        return pot;
                    }
                }
            },
            admin: {
                options: {
                    potFilename: 'axisbuilder-admin.pot',
                    include: [
                        'includes/admin/.*'
                    ],
                    processPot: function ( pot ) {
                        pot.headers['project-id-version'] += ' Admin';
                        return pot;
                    }
                }
            }
        },

But, while looking after the transifex, I figure out that plugin information for the both pot files are generated. How can I generate plugin information for axisbuilder-admin.pot and not for the axisbuilder.pot as localization is done in admin and frontend respectively by each mo files generated by grunt-potomo.

keyword "msgctxt" unknown

After running the makepot task, I get the following errors:

(null):D:\Dev\wordpress\bxslider-integration\languages\bxsg.pot:88: keyword "msgctxt" unknown
[...]
(null): found 6 fatal errors

Those are my options for the task:

exclude: [
    "node_modules/.*",
    "libs/.*",
    "grunt/.*",
    "assets/.*"
],
include: [
    "bxslider-integration.php",
    "src/php/.*"
],

And these are the lines I think are guilty in the generated POT (only an exerpt, if needed I can paste all of them too):

#: node_modules/grunt-checktextdomain/test/expected/incorrect-domain-autocorrect.php:4
[...]
#: node_modules/grunt-checktextdomain/test/fixtures/variable-domain-autocorrect.php:17
msgctxt "verb"
msgid "Post"
msgstr ""

I have the latest i18n tools from WP's SVN, also installed the latest GNU Gettext utils for Windows.

I even wrote a function to get rid of them but that does not seem to remove them before writing to the POT:

processPot: function (pot) {
    for (var translation in pot.translations['']) {
        var tr = pot.translations[''][translation];

        if ("" == translation.trim()) {
            grunt.log.writeln("Removed empty string");
            delete pot.translations[''][translation];
            continue;
        }

        if (( 'undefined' !== typeof tr.comments.reference )
            && (tr.comments.reference.indexOf("node_modules") >= 0)) {
            grunt.log.writeln("Removed node_modules string: " + translation);
            delete pot.translations[''][translation];
            continue;
        }
    }
    return pot;
},

Include Directories for creating POT

Similar like exclude please also add the include options. Sometime theme and plugin developers have to make several pot. If they want to create admin.pot and frontend.pot for some suitable reason. If they want to build pot file only for admin folder then excluding several not used folder is troublesome. Any thought to add include options @bradyvercher .

Ignore certain domain (e.g. via an options.dontUpdateDomains)

It would be great to be able to set certain text domains to be left alone, something along

options: {
            dontUpdateDomains: [ 'thirpartydomain' ]
}

My use case is that my theme does some slight modifications of markup via a plugin hook, but although the order of things shifts the actual string to translate remains the same as in the plugin. So it doesn't really make sense to move/duplicate that string in my plugin.
Now I could just ignore that file in target but that is an issue as the file does have other translatable strings with my own textdomain in it.

I know this probably is an edge case, but maybe I am not the only one having this issue. ๐Ÿ˜„

Exclude directories

@bradyvercher What are your thoughts on adding an option to exclude directories from being processed through the i18n tools? A use case is including a library via a submodule and not including those internationalized strings in the main .pot file. I imagine that this could require modifying the PHP tools. Any thoughts?

Output notices when running grunt makepot

When running grunt makepot in my local environment, I get the following output:

Warning: date(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /***/node_modules/grunt-wp-i18n/vendor/wp-i18n-tools/makepot.php on line 180

As the error message clearly identifies, the date.timezone is not set in my local php.ini. However, I have an unmodified VVV installation with what I consider to be a very typical homebrew installation of PHP. Since it's mostly turn-key, I suspect it's possible others may see similar output.

An easy fix is to switch calls to date() to gmdate() in two places:

Similar strings

I'd love to see a new feature that could generate a report (in the TTY or saved to a reportFile) that listed the location of any similar strings. Strings that are similar could then be decided by the developer to be made the same, to reduce the size of the POT and PO/MO files, and reduce workload for translators as well as bring consistency to the UI.

For example, if my project had three strings of foo, bar and baz, then looping through and comparing each one to each one using http://php.net/manual/en/function.similar-text.php or equivalent would give percentage scores, with the one between bar and baz being 66%. If this value was above a trigger value (say 80% by default), then it would get reported (as a notice, not a warning or error).

Config would be something like:

similarstrings: {
    options: {
        triggerValue: 80, // % value above which similarities are reported
        reportFile: false // Report to screen. Can be path to external file e.g. 'logs/similarity.txt'
    },
    php: {
        files: {
            src: [
                '**/*.php'
            ]
        }
    }
}

Each notice would have both strings, both files and lines, and the percentage score. This tool would be reporting only - not to make decisions and do any automatic replacements.

Obviously, if this feature gets added, then it's probably going to be useful to submit upstream to the official wp-i18n tools as well. The process of finding and extracting location data for each string for this is probably going to share a lot of code with how the makepot task does it, so there's likely room for some abstraction in there.

Add X-Generator header

The makepot task could have an extra header added by default:

"X-Generator: grunt-wp-i18n 0.4.3\n"

...where the version number is whatever version of this plugin is currently installed.

Extract core into a standalone node module

Awhile back, I researched the possibility to remove the PHP CLI dependency to allow grunt-wp-i18n to run anywhere node can run, but didn't come across anything super promising. While researching that, I started thinking about extracting the core code into a separate package and turning this module into a simple Grunt wrapper.

This would allow for creating plugins for other task runners like Gulp or incorporating the functionality into other modules that don't use Grunt.

I'm also considering adding a basic CLI utility to the node module so it could be installed globally and run in a plugin or theme directory without having to install and configure Grunt for every project.

The tests should ensure the Grunt interface continues working without any issues. The one thing I'm planning to remove is the ability to pass in a custom path for the PHP tools to make maintenance and new features easier to add. A GitHub search didn't turn up any projects that were actually using it.

I've made a bit of progress on the node module already, but figured I'd open this up for discussion in case anyone has any thoughts or concerns.

Add ability to switch textdomains

I ran into this recently where a project was changing names (this can happen for many reasons, but I would imagine the most common is when doing an official fork).

So, I needed to change all the references to 'original-textdomain' to 'new-textdomain'. But as far as I could tell, if a string already has a textomain, it gets ignored, even if the textdomain it has doesn't match the one in package.json.

So, I had to do a manual search and replace to get all the strings switched to the new textdomain.

Is there any way to have this grunt tool do a replacement, either with a new task, or make it the default behavior of addtextdomain?

Makepot output errors, and renaming pot file to include theme name

I'm just starting to use Grunt and the grunt-wp-i18n plugin and am experiencing a couple of issues.

First off I'm running Grunt on Windows 8.1, with the latest versions of Grunt and grunt-wp-i18n. Here are the Grunt files I'm using:

Gruntfile.js:

'use strict';
module.exports = function(grunt) {

 // When this Gruntfile.js runs it:
 //
 // - Does an initial build of style.css.
 // - Builds the theme pot file.
 // - Watches the theme sass folder for any changes to *.scss files and rebuilds style.css when any changes are detected.

 // Project configuration.
 grunt.initConfig({
   pkg: grunt.file.readJSON('package.json'),

   // Config

    // watch for file changes
    watch: {
        compass: {
            files: ['sass/**/*.{scss,sass}'],
            tasks: ['compass']
        }
    },

    // compass and scss
    compass: {
        dist: {
            options: {
                config: 'config.rb',
                force: true
            }
        }
    },

    // compile theme pot file
    makepot: {
        target: {
            options: {
                domainPath: '/languages',
                potFilename: 'wpgo-theme.pot',
                processPot: function( pot ) {
                    var translation,
                        excluded_meta = [
                            'Theme Name of the plugin/theme',
                            'Theme URI of the plugin/theme',
                            'Author of the plugin/theme',
                            'Author URI of the plugin/theme'
                        ];

                    for ( translation in pot.translations[''] ) {
                        if ( 'undefined' !== typeof pot.translations[''][ translation ].comments.extracted ) {
                            if ( excluded_meta.indexOf( pot.translations[''][ translation ].comments.extracted ) >= 0 ) {
                                console.log( 'Excluded meta: ' + pot.translations[''][ translation ].comments.extracted );
                                delete pot.translations[''][ translation ];
                            }
                        }
                    }

                    return pot;
                },
                type: 'wp-theme'
            }
        }
    }

 });

 // Dependent plugins
 grunt.loadNpmTasks( 'grunt-contrib-watch' );
 grunt.loadNpmTasks( 'grunt-contrib-compass' );
 //grunt.loadNpmTasks( 'grunt-contrib-uglify' );
 grunt.loadNpmTasks( 'grunt-wp-i18n' );

 // Default task(s).
 grunt.registerTask('default', ['compass', 'makepot', 'watch']);

};

package.json:

{
  "name": "wpgo-themes-grunt",
  "version": "1.0.0",
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-autoprefixer": "^2.0.0",
    "grunt-contrib-compass": "^1.0.1",
    "grunt-contrib-uglify": "^0.6.0",
    "grunt-contrib-watch": "^0.6.1",
    "grunt-cssjanus": "^0.2.2",
    "grunt-wp-i18n": "^0.4.9"
  }
}

Issue 1:

When running makepot I get warning errors of the type show below (there are quite a lot of them). The resulting pot file seems to be fine so are these warning errors that can safely be ignored? If so is there a way of suppressing them?

Running "makepot:target" (makepot) task

Warning: scandir(.,.): Result too large in C:\Users\David\Documents\Websites\www
.wpgothemes.dev\wp-content\themes\modd-wpgothemes\node_modules\grunt-wp-i18n\ven
dor\wp-i18n-tools\extract.php on line 28

Call Stack:
    0.0004     157936   1. {main}() C:\Users\David\Documents\Websites\www.wpgoth
emes.dev\wp-content\themes\modd-wpgothemes\node_modules\grunt-wp-i18n\vendor\wp-
i18n-tools\grunt-makepot.php:0
    0.0064     611624   2. call_user_func:{C:\Users\David\Documents\Websites\www
.wpgothemes.dev\wp-content\themes\modd-wpgothemes\node_modules\grunt-wp-i18n\ven
dor\wp-i18n-tools\grunt-makepot.php:174}() C:\Users\David\Documents\Websites\www
.wpgothemes.dev\wp-content\themes\modd-wpgothemes\node_modules\grunt-wp-i18n\ven
dor\wp-i18n-tools\grunt-makepot.php:174
...
...
...

Issue 2:

I'd like to be able to rename the pot file after it is generated and include the theme name and version number automatically. This way the I could easily reuse the Grunt files across any theme without the need to edit the pot file name every time it's generated.

I know this may be a more general question and not related to the grunt-wp-i18n as such but any help would be appreciated.


This is a great plugin by the way! Thanks to all contributors for your work putting it together.

Custom build process troubleshooting with bbPress

I'm having some issues trying to get this working with a custom build process.

Project source: https://bbpress.trac.wordpress.org/browser/trunk

(Because of gettext/xgettext issues I'd like to switch from grunt-pot to grunt-wp-i18n)

My latest 'working' version of patching this is 2542.12.diff in bbPress Ticket #2452

Am I_doing_it_wrong and there is a more eloquent way of achieving the same goal?

With the above and below it lappears bbpress.pot is correctly generated, so that's ๐Ÿ‘

    SOURCE_DIR = 'src/',
    BUILD_DIR = 'build/',
        makepot: {
            target: {
                options: {
                    cwd: SOURCE_DIR,
                    mainFile: SOURCE_DIR + 'bbpress.php',
                    potFilename: '../../' + BUILD_DIR + 'bbpress.pot',
                    type: 'wp-plugin'
                }
            }
        },

cwd:

It appears from the errors below grunt-wp-i18n is looking for a file and not a folder. (I get the same error on Windows if I use cwd: 'src/ or cwd: 'src

  • cwd: SOURCE_DIR
    Warning: fopen(C:\xampp\htdocs\bbp.wp.nw\wp-content\plugins\bbpress\src/src.php): failed to open stream: No such file or directory in C:\xampp\htdocs\ bbp.wp.nw\wp-content\plugins\bbpress\node_modules\grunt-wp-i18n\vendor\wp-i18n-tools\makepot.php on line 392

domainPath:

bbPress has Domain Path: /languages/ defined in bbpress.php so to override it and create the bbpress.pot file in /build/bbpress.pot I am using `potFilename: '../../' + BUILD_DIR + 'bbpress.pot',``

"updateTimestamp: false" is not working properly

First of thank you such an awesome plugin ๐Ÿ‘

There is just one little thing that bugs me. POT-Creation-Date is updated every time even if there are no changes. This is a bit annoying in a version controlled environment, where you don't want to see unnecessary changes.

Edit: Just found updateTimestamp in the documentations. I think it is exactly what I'm looking for. But when I tried it, it stops updating POT-Creation-Date, altogether even if there changes in the translation strings.

Update all text domains in the addtextdomain task

Per @GaryJones in #22:

updateDomains: true would replace ALL domains with the right textdomain. This helps when you don't know what all the existing domains are (perhaps PHP functions copied and pasted from multiple sources), but you know they should all be a single one for the project.

This would likely require building a list of all translation functions and the index of their text domain arguments. The list should be readily available since it's typically used in Poedit headers.

Currently the addtextdomain task just does a blind match/replace/insert without being aware of the argument's position in the method definition, so that would need to be updated. Adding this kind of awareness to the tool would likely be valuable upstream as well.

Make PO task

The grunt-potomo task is useful for creating a .mo from a .po, but the missing link is being able to create a .po file from a .pot file and having saved to a custom directory.

Is that something this package could do? Dependency on grunt copy package, perhaps accepting a command line arg for the language-locale? e.g. grunt makepo en_GB

Plugin's meta data

Is there a way to control which plugin meta data are included in the .pot file?
In example I would like only plugin's description (and maybe name) to be translatable, while plugin's author and URI's not.

Missing uppercase letter in pot.headers['x-poedit-searchpath-0']

The processPot: function( pot, options ) {

        pot.headers['x-poedit-searchpath-0'] = 'foo'

creates this in the file
"X-Poedit-Searchpath-0:

it should be
"X-Poedit-SearchPath-0: ..\n": with a Uppercase P

The result for now the data isn't displaying in Poedit

Possible to search for strings with a specific textdomain?

I was wondering if it's possible to scan a folder for strings containing only a specific text domain? I'm asking because my theme also contains other text domains (BuddyPress ones) because I have to overwrite certain BuddyPress templates. When I used Grunt-Pot these strings are picked up again and I'd like to find a way around this. The developer of Grunt Pot kindly pointed me to this set of tools, but before I dive in I thought it'd ask first :-)

Reduce dependencies: explore node gettext alternatives

Installing gettext on your computer can be a real pain. It increases the barrier to entry for using this package. In fact, I've avoided installing gettext on OS X and opted to install in a VM instead.

I understand the major difficulties with this change. It would likely require forking the PHP based tools. I think it is worth exploring node based gettext alternatives. The usability of this package would be exponentially improved.

Here's what I've found so far:

I know nothing about the internals of the WP i18n tools, so this suggestion might be absolutely absurd. It is at least worth exploration.

Fix project-id-version issues ...

When developer have to generate more than single pot files then they have to make some changes. For ease, if we want to create seperate two pot for admin interface and frontend interface for specific plugin similar like WooCommerce then how could we modify the project-id-version ? Also please adapt this in potHeaders and make its documentation in readme soon?

makepot: {
    backend: {
        options: {
            cwd: 'i18n/languages',
            processPot: function( pot, options ) {
                pot.headers['project-id-version'] = '{name} {version} Admin Interface';
                return pot;
            },
            type: 'wp-plugin'
        }
    }
}

windows and deep paths

Windows has a limit of ~250 char path when used with php.

it would seem even though node_modules is excluded, its still having subdirs looped over. this causes issues with grunt packages like grunt-contrib-imagemin which is 5+ levels deep of node_modules

I realize this project mainly pulls in i18n tools but i felt this should be brought up.

User Feedback

When doing makepot and addtextdomain tasks, I'd like to see a little bit more feedback about what happened. At the moment, the only thing given is where the POT file is saved (and that's a good thing). Some suggestions below; I've indicated where I think some should only show up with the --verbose flag:

makepot

  • Number of files scanned.
    • A list of scanned files (verbose).
  • Number of strings found.

addtextdomain

  • Number of files scanned.
    • A list of scanned files (verbose).
  • Number of text domains added.
    • A list of the files and line numbers where they were added (verbose).
  • Number of text domains updated.
    • A list of the files and line numbers where they were updated (verbose).

How can I use addtextdomain

@bradyvercher I have to use grunt-contrib-copy module too. I have to copy all the files from the root directory excluding some text, markdown and documentation files. After deployment tasks deploy directory is created where my wp-theme resides.

The thought is:
I want to create a wp-theme in root directory with axisthemes and there is my own framework's textdomain too called axisframework, and after deployment necessary files from the theme and framework is copied to deploy directory. What I want is how can I run addtextdomain to replace all the textdomain matching axisthemes and axisframework only in the deploy directory (i.e not in root where Gruntfile.js) is present. Can we use cwd or not. It will be better if addtextdomain has support for cwd. Please so me an example to demonstrate how we can through snippet.

Move to Cedaro organization

I'll be looking into moving this repo over to the @cedaro organization soon to help keep things organized and aid in discoverability (we'll be more active over there).

GitHub should take care of any redirects automatically and nobody should need to make any changes unless it's to update bookmarks. Nevertheless, let me know if you have any questions or concerns.

Gulp version

Do you know or have version?
gulp-wp-i18n maybe? But nothing...
Thanks.

Exclude strings WITHOUT textdomain

If a string is in the wp core translation files it is sometimes feasible to use it to improve translation consistency.
Any idea how to filter out these strings used in the plugin/theme?

Report-Msgid-Bugs-To link

Hey,

So I ran grunt with this configuration and the Report-Msgid-Bugs-To link was http://wordpress.org/support/plugin/flowplayer instead of http://wordpress.org/support/plugin/flowplayer5

        makepot: {
            target: {
                options: {
                    domainPath: '/languages',    // Where to save the POT file.
                    mainFile: 'flowplayer.php',      // Main project file.
                    potFilename: 'flowplayer5.pot',   // Name of the POT file.
                    type: 'wp-plugin'  // Type of project (wp-plugin or wp-theme).
                }
            }
        },

Would it be possible to define the link for paid products that are not on the WordPress repo?

Missing uppercase letter in pot.headers['x-poedit-sourcecharset']

The processPot: function( pot, options ) {

        pot.headers['x-poedit-sourcecharset'] = 'foo'

creates this in the file
"X-Poedit-Sourcecharset:

it should be
"X-Poedit-Sourcecharset: ..\n": with a Uppercase C

The result for now the data isn't displaying in Poedit

`addtextdomain --dry-run` is not working

When I try using dry run with the addtextdomain task I see a bunch of failed to open stream errors and don't see the expected changes:

Warning: file_get_contents(woocommerce-dev-helper): failed to open stream: No such file or directory in /*/node_modules/grunt-wp-i18n/vendor/wp-i18n-tools/add-textdomain.php on line 37

When dry run is used it looks like arguments are shifted and the domain gets passed here instead of the filepath

Add an option to include common Poedit headers

Given that Poedit is one of the more popular tools that people use to translate WordPress projects, adding a few headers to make that process easier without using the error-prone processPot() callback seems worthwhile.

A quick search turns up that WordPress SEO seems to be the most forked project on GitHub using grunt-wp-i18n (thanks @deFries!) and they've defined some commonly-used headers.

Obviously this would be toggled on with an option and could still be updated in the processPot() callback, but it could help standardize a few tricky headers like the keyword list and reduce boilerplate in Gruntfile.js for anyone who wants to make working with their POT files a little easier.

I'm considering these for the default values:

{
    'language': 'en',
    'plural-forms': 'nplurals=2; plural=(n != 1);',
    'x-poedit-country': 'United States',
    'x-poedit-sourcecharset': 'UTF-8',
    'x-poedit-keywordslist': '__;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c;_nc:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;',
    'x-poedit-basepath': '../',
    'x-poedit-searchpath-0': '.',
    'x-poedit-bookmarks': '',
    'x-textdomain-support': 'yes'
}

Warning: Cannot read property 'split' of undefined

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.
                }
            }
        },

Warning: Arguments to path.join must be strings

I am getting this error:

Running "makepot:target" (makepot) task
Warning: Arguments to path.join must be strings Use --force to continue.
Aborted due to warnings.

I am a grunt beginner but love to get this to work.

This is how my Gruntfile.js looks like.

module.exports = function(grunt) {

    grunt.initConfig({
        makepot: {
            target: {
                domainPath: '/languages',    // Where to save the POT file.
                mainFile: 'flowplayer.php',      // Main project file.
                potFilename: 'flowplayer5.pot',   // Name of the POT file.
                type: 'wp-plugin'  // Type of project (wp-plugin or wp-theme).
            }
        }
    });

    grunt.loadNpmTasks( 'grunt-wp-i18n' );

};

Support for merging .pot file into .po file

#39 talks about being able to create a new .po file from the .pot file, but after that has happened and you add new strings you want to merge the .pot file into the .po file. Currently I use poedit for this, but this is cumbersome at times.

The gettext command msgmerge can be used to achieve this behaviour. I found this gist that basically does what I want: https://gist.github.com/ccprog/12c10d6e611882ff2fc2

My main question is, is this something you want to provide in this grunt plugin, or is this out of scope? If so, I could provide a pull request to add this task.

Exclude doesn't included in .pot file

Hi, probably my bad but I unable to set the exclude dir list. here the options list.

makepot: {
            dist: {
                options: {
                    cwd: './',
                    domainPath: 'languages/',
                    exclude: [
                        'bower_components/.*',
                        'node_modules/.*',
                        'vendor/.*',
                        'assets/.*'
                    ],
                    include: [],
                    mainFile: 'index.php',
                    potComments: '',
                    potFilename: 'plugin-name.pot',
                    potHeaders: {
                        poedit: true,
                        'Project-Id-Version': 'Plugin Name',
                        'POT-Creation-Date': '2017-09-06 13:08+0200',
                        'PO-Revision-Date': '2017-01-08 19:27+0100',
                        'Last-Translator': '',
                        'Language-Team': '',
                        'Language': 'en',
                        'MIME-Version': '1.0',
                        'Content-Type': 'text/plain; charset=UTF-8',
                        'X-Poedit-Basepath': '../',
                        'Plural-Forms': 'nplurals=2; plural=(n != 1);',
                        'X-Poedit-KeywordsList': true
                    },
                    processPot: null,
                    type: 'wp-plugin',
                    updateTimestamp: true,
                    updatePoFiles: true
                }
            }
        },

I expecting to view a list like this

"X-Poedit-SearchPathExcluded-0: bower_components\n"
"X-Poedit-SearchPathExcluded-1: node_modules\n"
"X-Poedit-SearchPathExcluded-2: vendor\n"
"X-Poedit-SearchPathExcluded-3: assets\n"

it's right?

Change constructors

Just a warning today, might be an issue in the future, as per a PHP warning message, methods with the same name as their class will not be constructors in a future version of PHP; there are a bunch of these here and there, and they should probably be converted to __construct instead.

Keep it up!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.