Skip to content

Latest commit

 

History

History
67 lines (49 loc) · 2.15 KB

addtextdomain.md

File metadata and controls

67 lines (49 loc) · 2.15 KB

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().

grunt.initConfig({
    addtextdomain: {
        options: {
            textdomain: '',    // Project text domain.
            updateDomains: []  // List of text domains to replace.
        },
        target: {
            files: {}
        }
    }
});

Options

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.

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.