Code Monkey home page Code Monkey logo

Comments (8)

GaryJones avatar GaryJones commented on June 18, 2024

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.

from grunt-wp-i18n.

dgwyer avatar dgwyer commented on June 18, 2024

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?

from grunt-wp-i18n.

bradyvercher avatar bradyvercher commented on June 18, 2024

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.

from grunt-wp-i18n.

dgwyer avatar dgwyer commented on June 18, 2024

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.

from grunt-wp-i18n.

bradyvercher avatar bradyvercher commented on June 18, 2024

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?

from grunt-wp-i18n.

dgwyer avatar dgwyer commented on June 18, 2024

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.

from grunt-wp-i18n.

GaryJones avatar GaryJones commented on June 18, 2024

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/

from grunt-wp-i18n.

bradyvercher avatar bradyvercher commented on June 18, 2024

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.

from grunt-wp-i18n.

Related Issues (20)

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.