Integrate TranslationsPress with Your WordPress Project Using T15S Registry

Hero image

Easily connect your WordPress project to TranslationsPress for seamless translation updates using the T15S Registry, our helper library. By implementing T15S Registry, you can instruct WordPress to load translations directly from TranslationsPress.

Prerequisites

PHP Version: T15S Registry requires PHP 7.1 or higher.

Compatibility: Works with both single-site and multisite WordPress installations. For multisite setups, it’s recommended to use T15S Registry as a must-use plugin.

Getting Started with T15S Registry

The T15S Registry helps developers define and manage translations for their projects, whether it’s a WordPress plugin or theme. Here’s how to integrate it:

1. Add the Library to Your Project

Copy the following T15S Registry code to your project:

<?php
/**
 * Main T15S library.
 * @since 1.0.0
 * @package WP_Translations\T15S_registry
 */

use DateTime;

class YOUR_AWESOME_PROJECT_SLUG_Language_Packs {
    public function __construct( $type, $slug, $api_url ) {
        $this->type    = $type;
        $this->slug    = $slug;
        $this->api_url = $api_url;
    }

    /**
     * Adds a new project to load translations for.
     * @since 1.0.0
     */
}

2. Avoid Potential Conflicts

As more developers adopt T15S Registry, there’s a risk of conflicts if multiple plugins/themes use different versions of the library. To prevent this:

• Rename the class name and initialization function to something unique to your project.

Example:

  • YOUR_AWESOME_PROJECT_SLUG_Language_Packs
  • YOUR_AWESOME_PROJECT_SLUG_init_t15s

3. Parameters to Configure

When initializing the library, set these parameters:

Parameter Description Example Value

$type Type of the project: plugin or theme. plugin

$slug The directory name of your plugin/theme. your-plugin-slug

$api_url URL to your TranslationsPress translation API. https://packages.translationspress.com/your-team-slug/your-theme-slug/packages.json

⚠️ Ensure the $slug matches the exact folder name of your plugin or theme.

Example Implementation

Add the Project Initialization

Here’s how to initialize T15S Registry for your plugin or theme:

function YOUR_AWESOME_PROJECT_SLUG_init_t15s() {
    if (class_exists('YOUR_AWESOME_PROJECT_SLUG_Language_Packs')) {
        $t15s_updater = new YOUR_AWESOME_PROJECT_SLUG_Language_Packs(
            'plugin',
            'your-plugin-slug',
            'https://packages.translationspress.com/your-team-slug/your-plugin-slug/packages.json'
        );
        $project = $t15s_updater->add_project();
    }
}

add_action('init', 'YOUR_AWESOME_PROJECT_SLUG_init_t15s');

For Themes

$t15s_updater = new YOUR_AWESOME_PROJECT_SLUG_Language_Packs(
    'theme',
    'your-theme-slug',
    'https://packages.translationspress.com/your-team-slug/your-theme-slug/packages.json'
);

Best Practices

• Use unique naming conventions for classes and initialization functions to avoid conflicts with other plugins or themes using T15S Registry.

• For multisite installations, implement the library as a must-use plugin to ensure compatibility across your network.

By following this guide, you’ll have a seamless integration of TranslationsPress into your WordPress projects, ensuring real-time and conflict-free translation updates. For additional support, refer to the TranslationsPress documentation.