Files
piratepoet/tasks/makepot/node_modules/grunt-wp-i18n/docs/addtextdomain.md

74 lines
2.5 KiB
Markdown

# Addtextdomain task
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)._
## Overview
In your project's Gruntfile, add a section named `addtextdomain` to the data object passed into `grunt.initConfig()`.
```js
grunt.initConfig({
addtextdomain: {
options: {
i18nToolsPath: '', // Path to the i18n tools directory.
textdomain: '', // Project text domain.
updateDomains: [] // List of text domains to replace.
},
target: {
files: {}
}
}
});
```
## Options
### options.i18nToolsPath
Type: `String`
Path to a local copy of the WordPress i18n tools. May be relative to the project or an absolute path. Defaults to a bundled version of the i18n tools.
### options.textdomain
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.
### options.updateDomains
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.
## Usage Examples
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.
```js
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](http://gruntjs.com/configuring-tasks#globbing-patterns) and [Building the files object dynamically](http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically) for additional details.