Add the text domain to gettext functions in your plugin or theme.
Warning: This task will overwrite files in your project. Be sure to have a backup or commit any changes before running it. Viewing a diff after the task has run is a good way to verify any changes. To preview changes without updating files, use the --dry-run
switch when running the task.
Run this task with the grunt addtextdomain
command (or grunt addtextdomain --dry-run
to preview).
In your project's Gruntfile, add a section named addtextdomain
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
addtextdomain: {
options: {
textdomain: '', // Project text domain.
updateDomains: [] // List of text domains to replace.
},
target: {
files: {}
}
}
});
Type: String
Default value: ''
Example value: 'plugin-or-theme-slug'
Defaults to the "Text Domain" header if it exists, otherwise uses the project directory name.
Type: Array|true
Default value: []
Example value: [ 'original-domain', 'vendor-domain' ]
A list of text domains to replace with the new text domain. Setting the value to true
will update all text domains with the new text domain.
Options may be specified at the task or target level, but are optional. Each target must define the files that should be processed. It's not necessary to declare a destination since the files will be updated in place.
grunt.initConfig({
addtextdomain: {
target: {
files: {
src: [
'*.php',
'**/*.php',
'!node_modules/**',
'!tests/**'
]
}
}
}
});
This task supports the same file mapping format Grunt supports. Please read Globbing patterns and Building the files object dynamically for additional details.