Let me provide
For Sublime fans – quick end: In case you are not using phpStorm, but you still want to update the language files faster, I highly recommend you a grunt module called grunt-wp-i18n. I assume it’s easier to run a grunt command in the terminal than updating the from source files manually.
How it all started?
For me, this idea came into my mind while reading Otto’s comment on this specific topic. There is a wide range of solutions to create a .pot file, but Otto’s answer uses a tool which is bullet proof in the WordPress community aka respecting some high standards. So why not use it? Well, maybe because it’s pretty hard and annoying to repeat all those commands every time you change the syntax in your theme or plugin.
Smarter is simpler
I’m using phpStorm, and this IDE has a bunch of tools to help developers. One of them is Task Manager, which has various types of configurable default tasks. By the way—if you can’t find a task that you need, then I’m pretty sure that somewhere in the digital world there is a plugin for that. On top of that, you can easily check my article about running Gulp Tasks from IDE. The tool is powerful, and it can help you cut tons of redundant, and time-consuming tasks.
First of all, we need to BashSupport plugin for phpStorm. This will provide all we need (aside phpStorm) to automate Otto’s suggestions. So go in phpStorm preferences, Look for Plugins, Hit the Browse Repositories button and then search for BashSupport plugin to install.
To quickly brief you about my WordPress installation setup, I must say I use pressmatic.io, which influences my folders structure but it’s very helpful in order to keep me organized. Beside what pressmatic.io gives me (WordPress installation, configs, and logs) I also get the WordPress SVN Trunk version because it contains all the grunt and internalization tools. It’s always good to have them, right?
The makepot.php file is actually all we need to use. This can by executed with PHP and it takes commands like:
- wp-theme – creates a pot file for a theme
- wp-plugin – creates a pot file for a plugin
- The file has other commands for WordPress internalization like admin area, time zones, glotpress, wordpress.org but this is out of our topic.
This should be your Create Theme pot task:
Hot points above:
- The Name is free to edit
- The Script can be wp-theme or wp-plugin
- Interpreter path: This needs to be the path to your local PHP. If you don’t how to manage it, just run the which PHP command in your terminal and you will find out (or take a closer look at a phpinfo() page);
- Program arguments: Contains the path to your theme / plugin and the name of the pot file.
- Working directory: Remember about the makepot.php file? The working directory must be the way to that file.
If now you’d like to have your “Create” task set, you can run it for a test. You may observe that the script is creating a file near makepot.php, called as your required in your second program arguments.
Cool, now we have the file! Big thanks! But wait, the magic deal was about 1click automatisation, right? The job is ready when the pot file is in the right place.
Create a task which moves the pot file
We can create a task that moves the theme.pot file from his birthplace into our theme or plugin. This is what I usually use:
- Name – Free to change
- Script – The file destination path. I know it doesn’t sound intuitive, but the Script is an argument to the Interpreter.
- Interpreter path – We need a terminal command to move the file. On Mac OSX and Linux I use mv. Windows fans should see this.
- Interpreter options – The only option we need is the new file name.
- Working directory – The path to the makepot.php file.
- One Before launch command – The beauty of the phpStorm Task manager is that we can chain tasks. What I did here is to chain the Create Theme task described above.
At the end of the journey, the flow should be easy-peasy:
- Click On Moving Task.
- The Create Task will be called first and create a new .pot file.
- The moving Task will do the rest of the job and put the file where it belongs.
This is it, dear WordPress lovers! Feel free to hit me with a tweet or comment if you like or if you have any questions. Bonus: let me give a nice spoiler about the next article on this subject: GULP.