sultann/wp-addtextdomain

A Composer package to automatically replace text domains in WordPress gettext functions

Installs: 12

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:composer-plugin

v1.0.0 2025-04-08 04:55 UTC

This package is auto-updated.

Last update: 2025-04-08 04:59:39 UTC


README

A Composer package that automatically replaces text domains in WordPress gettext functions. It can be used as a Composer plugin that runs automatically after package installation/update, or as a standalone CLI tool.

Features

  • Automatically replaces text domains in WordPress gettext functions
  • Runs as a Composer plugin or standalone CLI tool
  • Configurable through composer.json or command-line arguments
  • Supports all WordPress gettext functions
  • Excludes vendor and node_modules directories by default

Installation

Via Composer (recommended)

composer require sultann/wp-addtextdomain

Manual Installation

  1. Clone the repository:
git clone https://github.com/sultann/wp-addtextdomain.git
  1. Install dependencies:
composer install

Usage

As a Composer Plugin

Add the configuration to your project's composer.json:

{
    "require": {
        "sultann/wp-addtextdomain": "^1.0"
    },
    "extra": {
        "addtextdomain": {
            "textdomain": "my-new-domain",
            "updateDomains": ["old-domain", "another-old-domain"],
            "files": ["src/", "templates/"]
        }
    }
}

As a CLI Tool

# Replace single text domain
vendor/bin/addtextdomain new-domain old-domain

# Replace multiple text domains
vendor/bin/addtextdomain new-domain old-domain1 old-domain2

# Process specific directory
vendor/bin/addtextdomain new-domain old-domain --dir=src/

Configuration

Add the configuration to your project's composer.json under the extra section:

{
    "extra": {
        "addtextdomain": {
            "textdomain": "my-new-domain",        // Required: New text domain to use
            "updateDomains": ["old-one", "old2"], // Required: List of old domains to replace
            "files": [                            // Optional: Files or directories to scan
                "includes/",
                "functions.php"
            ]
        }
    }
}

Configuration Options

  • textdomain: (Required) The new text domain to use for replacement
  • updateDomains: (Required) Array of old text domains to be replaced
  • files: (Optional) Array of files or directories to scan. If not provided, all PHP files in the root and subdirectories will be scanned

Automatic Exclusions

The following directories are automatically excluded from scanning:

  • vendor/
  • node_modules/

Supported WordPress Functions

The package processes the following WordPress gettext functions:

  • __()
  • _e()
  • _x()
  • _n()
  • _nx()
  • _ex()
  • _n_noop()
  • _nx_noop()
  • translate()
  • esc_html__()
  • esc_html_e()
  • esc_html_x()
  • esc_attr__()
  • esc_attr_e()
  • esc_attr_x()

License

GPL-2.0-or-later