If you’re using Polylang on your site, you can make the Share Text, the My Account Text, and the Reward Box Texts from Refer a Friend fully translatable.
Follow this step-by-step guide to enable translations for these options.
Step 1: Register the Dynamic Texts for Translation
You need to tell Polylang which fields should be translatable.
Add the following code to your theme’s functions.php file or inside your custom plugin:
add_action( 'init', function() {
if ( function_exists( 'pll_register_string' ) ) {
// Share Text (product pages / shortcode)
pll_register_string( 'Refer a Friend Share Text', get_option( 'gens_raf_share_text' ), 'Refer a Friend' );
// My Account tab text
pll_register_string( 'Refer a Friend My Account Text', get_option( 'gens_raf_myaccount_text' ), 'Refer a Friend' );
// Rewards Box Texts
pll_register_string( 'Refer a Friend - Rewards Box', get_option( 'gens_raf_rewards_box' ), 'Refer a Friend' );
pll_register_string( 'Refer a Friend - You Receive Label', get_option( 'gens_raf_you_receive' ), 'Refer a Friend' );
pll_register_string( 'Refer a Friend - You Receive Reward', get_option( 'gens_raf_you_receive_reward' ), 'Refer a Friend' );
pll_register_string( 'Refer a Friend - Friend Receives Label', get_option( 'gens_raf_friend_receive' ), 'Refer a Friend' );
pll_register_string( 'Refer a Friend - Friend Receives Reward', get_option( 'gens_raf_friend_receive_reward' ), 'Refer a Friend' );
}
});
Explanation:
- Each option value is registered separately.
- They are grouped under “Refer a Friend” inside Polylang.
Step 2: Adjust Your Templates to Use Translations
First copy template files to your theme per: https://wpgens.com/docs/how-to-edit-template-files-and-keep-them-after-plugin-update/
2.1. Update the Share / My Account Text Template
The modern/parts/text.php template is shared: on product pages it receives the Share Text, and on the My Account tab it receives the My Account Text. So do not hardcode a single option here, instead translate the value that is passed in. Update modern/parts/text.php to this:
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// This template is shared by the product page (Share Text) and the
// My Account tab (My Account Text). $share_text is passed in by the
// plugin, so we translate whichever value it holds.
if ( function_exists( 'pll__' ) && ! empty( $share_text ) ) {
$share_text = pll__( $share_text );
}
?>
<div class="gens-raf-text">
<?php echo wp_kses_post( $share_text ); ?>
</div>
Notes:
pll__()fetches the translated text.wp_kses_post()safely allows basic HTML tags like<a>,<strong>, etc.- Because this template is shared, do not hardcode
get_option('gens_raf_share_text')here, or the My Account tab will show the product Share Text instead of the My Account Text.
2.2. Update the Reward Box Template
Under modern/parts/rewards.php update code to this:
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$rewards_box = get_option( 'gens_raf_rewards_box' );
$you_receive = get_option( 'gens_raf_you_receive' );
$you_reward = get_option( 'gens_raf_you_receive_reward' );
$friend_receive = get_option( 'gens_raf_friend_receive' );
$friend_reward = get_option( 'gens_raf_friend_receive_reward' );
if ( function_exists( 'pll__' ) ) {
$rewards_box = pll__( $rewards_box );
$you_receive = pll__( $you_receive );
$you_reward = pll__( $you_reward );
$friend_receive = pll__( $friend_receive );
$friend_reward = pll__( $friend_reward );
}
if ( ! $rewards_box ) {
return;
}
?>
<div class="gens-raf-reward">
<div><?php echo wp_kses_post( $you_receive ); ?><span><?php echo wp_kses_post( $you_reward ); ?></span></div>
<span></span>
<div><?php echo wp_kses_post( $friend_receive ); ?><span><?php echo wp_kses_post( $friend_reward ); ?></span></div>
</div>
Notes:
- Again, we use
pll__()for translation andwp_kses_post()for safe output. - If the Reward Box content is empty, nothing will be displayed.
Step 3: Translate the Texts in Polylang
Once the code is added:
- Log into your WordPress Dashboard.
- Navigate to: Languages → Translations.
- Search by group: Refer a Friend.
- You will find all the texts:
- Share Text
- My Account Text
- Rewards Box
- You Receive Label
- You Receive Reward
- Friend Receives Label
- Friend Receives Reward
- Enter your translations for each language.
- Save Changes.
Done! Now the Share Text, the My Account Text, and the Reward Box Texts will dynamically appear in the correct language.