Support Log in

26. Email Notifications for Translators

Developer Guide
Prefer video? Watch the Lang Forge tutorials 9 short guides covering every feature Watch

Configure email alerts for translation events such as new content needing translation, deadline reminders, and status changes.

Lang Forge’s built-in new-content translator emails use the shared Forge Email Template renderer. It outputs email-safe table markup with inline CSS, a Lang Forge accent color, Outlook-compatible structure, mobile row stacking, and a plain-text fallback where the mail transport supports it. Custom notification extensions should use the same renderer instead of building free-form HTML bodies.

Basic Notification Setup

php
/**
 * Send an email to the translation team when new content needs translation.
 */
add_action('lf_translation_created', function ($original_id, $new_id, $lang) {
    $notification_enabled = get_option('lf_email_notifications', false);
    if (!$notification_enabled) return;

    $original = get_post($original_id);
    $languages = lf_get_languages();
    $lang_name = $languages[$lang]['name'] ?? $lang;

    // Get translator email for this language
    $translators = get_option('lf_translator_emails', []);
    $to = $translators[$lang] ?? get_option('admin_email');

    $subject = sprintf('[%s] New %s translation: %s', get_bloginfo('name'), $lang_name, $original->post_title);

    $body = sprintf(
        "Hello,nn" .
        "A new %s translation has been created and needs your attention.nn" .
        "Original: %sn" .
        "Edit translation: %snn" .
        "Post type: %sn" .
        "Created by: %sn",
        $lang_name,
        $original->post_title,
        admin_url("post.php?post={$new_id}&action=edit"),
        $original->post_type,
        get_the_author_meta('display_name', $original->post_author)
    );

    wp_mail($to, $subject, $body);
}, 10, 3);
Example: Configure translator emails per language
php
// Store translator assignments in options
$translators = [
    'en' => '[email protected]',
    'de' => '[email protected]',
    'fr' => '[email protected], [email protected]',
];
update_option('lf_translator_emails', $translators);
Example: Notification when translation is marked as complete
php
add_action('transition_post_status', function ($new_status, $old_status, $post) {
    if ($new_status !== 'publish' || $old_status === 'publish') return;

    $is_translation = get_post_meta($post->ID, '_lf_translation_status', true);
    if ($is_translation !== 'pending') return;

    // Mark as completed
    update_post_meta($post->ID, '_lf_translation_status', 'completed');

    // Notify the content owner
    $translations = lf_get_post_translations($post->ID);
    $default_lang = lf_get_default_language();
    $original_id = $translations[$default_lang] ?? null;

    if ($original_id) {
        $original = get_post($original_id);
        $lang = lf_get_post_language($post->ID);
        $languages = lf_get_languages();

        wp_mail(
            get_the_author_meta('user_email', $original->post_author),
            sprintf('%s translation completed: %s', $languages[$lang]['name'] ?? $lang, $original->post_title),
            sprintf("The %s translation of "%s" has been published.nView: %s",
                $languages[$lang]['name'] ?? $lang,
                $original->post_title,
                get_permalink($post->ID)
            )
        );
    }
}, 10, 3);

Forge AI Assistant Online

Hi! I'm the Lang Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs