Grunt Transifex WordPress
Prepared for WordCamp SLC 2015 by Dovy Paukstys
A set of grunt tasks to integrate i18n tools and Transifex to your WordPress plugin/theme Grunt workflow.
-
Create a
.pot
file -
Create a
.pot
file and push it to Transifex -
Pulls translations from Transifex and create the needed .mo files
-
Compile: Builds a zip folder of all your files - ready to deploy
Also light support for WebTranslateIt if preferred.
Requirements
- Node.js - Install Node.js
- Grunt-cli and Grunt (
npm install grunt-cli -g
) - Transifex Client - Install tx client
- Gettext - Install Gettext or
brew install gettext
-> Homebrew formula for OS X
Getting started
If you haven't used Grunt before, check out Chris Coyier's post on getting started with Grunt.
And for more WP-Grunt optimization Supercharging your Gruntfile.
All Grunt configuration are separated into different files already setup for you and almost all Grunt config setups are done in the package.json file
Clone this repo, cd to the directory, run npm install
to install the necessary packages.
git clone https://github.com/reduxframework/grunt-transifex-wordpress
cd grunt-transifex-wordpress
npm install
grunt
Setup & Configuration
Transifex
TX configuration
Make sure you have a ~/.transifexrc. It is unique per user and stores the hostname, username and password for every Transifex server that you are using. It is stored in the user's home directory.
[https://www.transifex.com]
username = user
token =
password = p@ssw0rd
hostname = https://www.transifex.com
More info about setting up your Transifex client
TX client config file
In .tx->config replace the project_slug
and the pot_slug
by your own Transifex project and organization.
packages.json
All variables are setup in this file. Change all settings to reflect your own project details. Should be pretty strait forward.
package.json customizations
In your package.json, replace in the section named pot
the data below:
"directories": {
"js": "",
"sass": "",
"css": "",
"build": "./build",
"languages": "./languages"
},
"pull_percentage": "75",
"pot": {
"type": "wp-plugin", // wp-plugin or wp-theme
"textdomain": "example-textdomain", // Your custom textdomain
"default_lang": "en_US", // Default language of your project
"include": [], // Files you want to include outside of this directory
"exclude": [], // Files you want to exclude from within this directory
"header": {
"bugs": "http://dovy.io/", // Header for your pot file
"team": "Dovy.io <me@dovy.io>", // Team name
"last_translator": "Dovy.io <me@dovy.io>" // Last person to update the pot
}
},
That's it you're ready to take over the world with these commands!
How it works
.pot
file
Generate grunt makepot
Check/replace textdomains and run makepot
grunt build:i18n
.pot
file and push it to Transifex
Generate grunt tx-push
Pulls translations from Transifex and create the .mo files
grunt tx-pull
Automatically change all textdomains in the project with the declared pot.textdomain value
BE SURE to include all possible textdomains in your project to the grunt/addtextdomain.js file under updateDomains OR you'll get duplicated domains added to functions that will mess things up.
grunt updatedomains
Extras: Builds a zip folder of all your files - ready to use
grunt build
Thanks to:
grunt-transifex-wordpress by FX Bénard of WP-Translations.org for the base of this repo.
grunt-potomo by AxisThemes to generate automatically the .mo files.
transifex client the client command tool and much more ...
All the Grunt Crew & @grappler, the i18n Petit-Suisse expert ;)