Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is unable to translate the content of the gender field (Male / Female) in BuddyPress, even though the word "Gender" gets translated.
Solution:
We recommend using the following custom code to translate BuddyPress profile fields:

//WPML Workaround wpml_compsupp-7149
add_filter( 'bp_get_the_profile_field_value', 'wpml_compsupp6144_translate_buddypress_profile_fields', 10, 3 ); 
  
function wpml_compsupp6144_translate_buddypress_profile_fields( $value, $type, $id ) {
      
    if ($type == 'textbox' || $type == 'wp-textbox' || $type == 'wp-biography' || $type == 'gender') {
        //remove html tags from value and limit it's size, so we can use it as string name
        $filtered_value = substr(strip_tags($value), 0, 60);
        //register string
        do_action( 'wpml_register_single_string', 'BuddyPress Profile Fields', $type.' - '.$filtered_value , $value );
        //translate string
        $value = apply_filters('wpml_translate_single_string', $value, 'BuddyPress Profile Fields', $type.' - '.$filtered_value  );
    }   
     
    return $value;
}

Please add this code to your theme's functions.php file or a custom plugin. For more information, you can refer to our errata page: https://wpml.org/errata/buddypress-profile-fields-are-not-being-translated-on-the-frontend/.

If this solution doesn't look relevant, please open a new support ticket at our support forum.

100% of people find this useful.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Dražen 1 year ago.

Assisted by: Dražen.

Author Posts
January 15, 2024 at 9:28 pm #15187102

babakB

Hi!

I'm trying to translate the content of the gender field (Male / Female) but it seems that this field is not covered by the fix found here: https://wpml.org/errata/buddypress-profile-fields-are-not-being-translated-on-the-frontend/

The word "Gender" gets translated but not the words "Female" / "Male".

Is there anything else I can do to fix it?

With best regards,

bb

January 16, 2024 at 7:58 am #15188070

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hello,

Let's check it out and if needed escalate to our compatibility team.

I created a minimal installation of WordPress, WPML, and all necessary WPML add-ons.

You can access the WordPress dashboard using the link below:
- hidden link

Kindly follow the steps below:
- Set up WPML
- Install the necessary plugins.
- Try to replicate the issue with simple example
- Share with me step by step guide on how can I check the issue

This will help us to report the probable issue to the compatibility team and solve the possible problem faster.

Thanks,
Drazen

January 17, 2024 at 5:34 pm #15196431

babakB

hidden link = secondary language page
hidden link = original

Look at the term "Gender". It is translated to "Kön" which is correct. But the choice "Male" or "Female" can't be translated because it can't be found.

I need to be able to translate "Male" and "Female"

With best regards,

bb

January 18, 2024 at 8:07 am #15198369

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hello,

thanks for taking time.

I have escalated this issue to our compatibility team to check further.

I will update you when I have some news.

Regards,
Drazen

January 22, 2024 at 7:37 am #15209585

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hello,

thanks, we checked, and you can follow the next errata just the code is a bit different for your case:

- https://wpml.org/errata/buddypress-profile-fields-are-not-being-translated-on-the-frontend/

//WPML Workaround wpml_compsupp-7149
add_filter( 'bp_get_the_profile_field_value', 'wpml_compsupp6144_translate_buddypress_profile_fields', 10, 3 ); 
  
function wpml_compsupp6144_translate_buddypress_profile_fields( $value, $type, $id ) {
      
    if ($type == 'textbox' || $type == 'wp-textbox' || $type == 'wp-biography' || $type == 'gender') {
        //remove html tags from value and limit it's size, so we can use it as string name
        $filtered_value = substr(strip_tags($value), 0, 60);
        //register string
        do_action( 'wpml_register_single_string', 'BuddyPress Profile Fields', $type.' - '.$filtered_value , $value );
        //translate string
        $value = apply_filters('wpml_translate_single_string', $value, 'BuddyPress Profile Fields', $type.' - '.$filtered_value  );
    }   
     
    return $value;
}

Regards,
Drazen