Translating Petitioner


Starting from v0.8.7, you can translate a petition without making a copy of it. Write the petition once, in one language. Polylang, WPML, or TranslatePress then translates that same petition’s text for each language on your site.

How it works

With Polylang or WPML, saving a petition sends its text to that plugin. You will find it in a group named Petitioner #123 (the number is the petition ID). TranslatePress uses the visual editor on the page instead, which is covered below.

Labels you changed under Petitioner → Settings live in a separate group named Petitioner Labels.

What you can translate

Country names and the plugin’s own phrases (such as “Select”) come from the Petitioner language files, not from that string list. The petition editor itself stays in the language you wrote the petition in. Visitors see the translation.

The alert after someone signs says “Thank you!” until you replace it. That default is a plugin phrase, so it is not in the petition’s translation list. Turn on Override success message? and write your own title and message. Translate that text with the rest of the petition.

Polylang

Add your languages

Add your languages under Languages.

Leave petitions untranslatable

In Languages → Settings, leave petitions out of the translated post types.

Write and save the petition

Write the petition in one language and save it. Its text is registered for translation on save.

Open string translations

Open Languages → String translations. Search for Petitioner # and your petition’s ID.

Translate and save

Fill in the translation for each string, then save.

Open the page in the other language. The form, the letter, and the thank-you email to that signer use the translation. Polylang matches a string by the exact text you saved, so if you edit the letter later, translate the new text as well.

WPML

Add your languages

Add your languages in WPML → Languages.

Set petitions to Not translatable

In WPML → Settings → Post Types Translation, set petitions to Not translatable.

Write and save the petition

Write and save the petition, then load any admin screen so the strings are registered.

Open String Translation

Open WPML → String Translation. Search for the domain Petitioner #123, using your petition’s ID.

Translate and save

Translate the strings and save.

TranslatePress

Open the petition, switch language, and translate the title, letter, and field labels in the visual editor. Petitioner leaves that page text alone, so TranslatePress can translate what it sees.

The language of that page is saved with the signature. The thank-you email reuses the translation you made on the page. A message that never appears on the site, such as a custom thank-you that is only sent by email, has nothing for TranslatePress to look up.

Redirects

A redirect is a URL, so it does not show up as text on the page. You can still give each language its own link.

There are three. Redirect URL after submission uses the language of the page the visitor signed on. Email confirmation success URL and Email confirmation error URL use the language saved with the signature. The confirmation link itself is not a translated page.

With Polylang or WPML, save the petition, then translate the URL in Petitioner #123 the same way you translate the letter.

TranslatePress does not see these URLs in the visual editor. View the petition in the other language once, then look under Regular and translate the after-sign URL there. The confirmation URLs show up in Regular after someone clicks the confirmation link in that language.

Only a URL you entered is translated. Leave a confirmation page empty and Petitioner keeps its own address.

Another translation tool

Any other tool can do the same job with two hooks. Put this in a child theme’s functions.php, or in a plugin such as Code Snippets.

PHP
add_action( 'av_petitioner_register_translation', function ( $form_id, $name, $value, $multiline ) {
    my_translator_register( $form_id, $name, $value, $multiline );
}, 10, 4 );

add_filter( 'av_petitioner_translate_string', function ( $value, $name, $form_id, $lang ) {
    $translated = my_translator_translate( $value, $name, $form_id, $lang );

    return is_string( $translated ) && $translated !== '' ? $translated : $value;
}, 10, 4 );

add_filter( 'av_petitioner_current_lang', function ( $lang ) {
    return my_translator_current_slug(); // "uk", not "uk_UA"
} );

av_petitioner_current_lang is what gets saved with the signature. Without it, Petitioner does not know which language that person used, and their email stays in the original language. If your tool speaks locales such as uk_UA rather than slugs, also map the slug with av_petitioner_locale. Polylang and WPML already do that.

Emails to a representative

The email to the signer uses the language of the page they signed on. The letter and subject sent to a representative stay in the language you wrote them in, on every signature.

To send that representative email in the signer’s language as well, add this:

PHP
add_filter( 'av_petitioner_representative_use_submission_lang', '__return_true' );