Closed dgwyer closed 9 years ago
For 2), the .pot file name should match the slug of the theme, so version should not be included. The version indicator should go into the Project-Id-Version
and that is already handled by grunt-wp-i18n.
What you can do is something like this where the values within this (or any) grunt config is extracted into a variable, and can therefore be set once and used multiple times.
Thanks Gary. I'm still pretty new to Grunt and fully get, from your comments, how I could rename the pot file name to the theme slug (version number doesn't matter if it's against best practices).
I know in the processPot callback I can access pot.translations['Project-Id-Version'] for the theme name and version, but is it possible to access the theme slug (i.e. the name of the folder Grunt is running in) and to then rename the pot file name to this slug?
Hi @dgwyer, what does your directory structure look like? Are you trying to run Grunt for multiple projects at once?
Grunt configs are usually specific to each project, so after you've defined the potFilename
during initial setup, you shouldn't need to change it again. For most projects, potFilename
is optional, so if you leave it out, it will automatically use the theme's text domain or its directory name.
I'm running Grunt in my root theme folder. Is this the best approach for developing WordPress themes, or should I be looking at running Grunt in the root /wp-content/themes/ folder, or even just /wp-content/ for plugin and theme dev?
I forgot about potFilename so all I needed to do was to get the current working theme directory with this added near the top of Gruntfile.js
var fullPath = __dirname;
var filename = fullPath.replace(/^.*[\\\/]/, '');
And then adding the potFile name as: potFilename: filename + '.pot',
By the way, could you comment on the warning errors I posted above? I just want to know everything is as it should be. It would be nice to suppress the errors if they aren't anything to worry about though.
I was asking about the structure to see if perhaps makepot.php
was scanning more files than usual, which might cause that error you're receiving. If you do have a ton of files that shouldn't be scanned, you can exclude them using the exclude
option, otherwise you might need to bump your PHP memory limit.
Running Grunt from the root of your theme folder is the standard approach, so you shouldn't have any problems with that setup.
I'm not sure why you're having issues with the potFilename
option, though, since grunt-wp-i18n
should handle that automatically. For themes, the name of the POT file will either be the text domain you defined in your theme headers or the name of the theme directory. What happens when you remove the potFilename
option from your config altogether?
I tracked down the problem but it took me quite a while as it turned out to be something unexpected. I tried altering the PHP memory limit, and excluding all number of files/folders but nothing had any effect which I thought was weird.
Almost by chance I switched to a different local server that I had installed sometime ago and ran makepot on the (exact same) theme in that local server, and it worked! The only difference is total number of characters that make up the path to the themes folder. The path to the local server, that makepot threw errors, on was over 20 characters longer than on the one that worked.
There are some pretty deep levels inside the node_modules folder and Windows seems to have a fixed limit on the number of characters that can make up a path. So, I can only assume that the error was caused by a sensitivity to this character limit on one of my local servers!
As for the potFilename, you are correct. If I leave it blank then it defaults to the text domain. However, if I wanted that default fallback to be the theme directory instead of the text domain is there a way to set that? It's not a big issue if not as I can generate the name as described above.
As I said above, the theme directory (aka slug) should be the text domain (and .pot filename) anyway, since then everything matches up ready for language packs. See http://ottopress.com/2013/language-packs-101-prepwork/
Thanks for reporting back on what you found out about that character limit -- I never would have guessed.
Regarding the potFilename
, if you don't have a text domain in the headers, then it will attempt to use the theme directory name by default, which mimics the functionality in the underlying PHP tools. If you want the behavior to be different, then you'll need to manually configure that option for each project. Like @GaryJones mentioned, though, it's usually best add the text domain header and make it the same as the theme slug.
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:
package.json:
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?
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.