Skip Navigation
Updated
September 26, 2022

The ACF plugin allows you to create Field Labels and add Choices to Select, Checkbox, and Radio Button field types. We’ll show you how to translate ACF Field Labels and the labels for Choices with WPML.

To learn how to translate ACF custom fields in general, please see Translate Sites Built with Advanced Custom Fields (ACF).

Before getting started, make sure to install and activate the Advanced Custom Fields, WPML core, WPML String Translation, and Advanced Custom Fields Multilingual plugins.

In order to translate Field Labels and labels for Choices, you need to follow a two-step process. Read on to learn how to:

  • Adjust the function in your theme’s files to make the labels translation-ready
  • Scan your theme for new strings and translate the labels using WPML’s String Translation

On This Page

Making Field Labels Translatable

In ACF, each custom field contains a Field Label, Field Name, and Field Type. As an example, take a look at this Text field on the Custom Fields backend:

A Text field on the Custom Fields backend

For most custom fields, you may only want to return the field value. Sometimes, however, you may want to translate and display both the field’s label and value on the front-end. 

In such cases, you should adjust the function in your theme’s files with code that wraps the content you want to translate into a WordPress-standard getttext function. Note that the Field Labels you provide in ACF will be ignored. You will need to enter the Field Label into your code.

Making the ACF field label translatable
<?php $field = get_field_object('recipe_short_description'); ?>
<p><strong><?php _e( 'Short description', 'twentyfifteen-child' ); ?></strong>: <?php echo $field['value']; ?></p>

Of course, you need to adjust the snippet to fit your custom field settings. Below, we briefly explain the parameters of the function shown above.

  • recipe_short_description‘ is the name of the field. Here, you need to input the Field Name of your custom field.
  • Short description‘ is the label of the field. Here, you need to input the Field Label of your custom field.
  • twentyfifteen-child‘ is the textdomain, or unique identifier you create. It wraps the static text string, such as Short description, in a translation function and makes it available for translation. It also makes it easier for WordPress to distinguish between translations and know which theme or plugin your strings belong to. 

Once you add the function to your theme files and are ready to translate your Field Label, jump over to the section about Translating Field Labels and Labels for Choices.

Making the Labels for Choices Translatable

To translate the labels for Choices, you need to follow three steps:

In the sections below, we cover each of the steps you need to take in detail.

Setting the Translation Preferences for Select, Checkbox, and Radio Button Field Types

Before you make the labels for Choices translatable, make sure you set the translation preferences of your Select, Checkbox, or Radio Button fields to Copy. You can do this by going to WPMLSettings and scrolling down to the Custom Fields Translation section.

Setting the translation preferences of a Choice field to Copy

You can learn more about which translation preference to use for each custom field type by checking out the page about Recommended Custom Field Translation Preferences for ACF and WPML.

Making the Labels for Choices Translatable

When you create a Select, Checkbox, or Radio Button field type, ACF allows you to add Choices. In the Choices section, you can specify both a value and a label. 

A Radio Button field with values and labels added in Choices

In the example above, beginner, intermediate, and expert are the values, while Beginner, Intermediate, and Expert are the labels.

To translate the labels for Choices and display them correctly on the front end, you need to add some additional code to your theme files. This code wraps the content you want to translate into a WordPress-standard getttext function

With the example above in mind, here’s the code we need to add to our theme files: 

Making the ACF labels for Choices translatable
<?php
		$field = get_field_object('recipe_level_of_difficulty');
		$level_options = [
		    'beginner'      => __( 'Beginner', 'twentyfifteen-child' ),
         'intermediate' => __( 'Intermediate', 'twentyfifteen-child' ),
         'expert'       => __( 'Expert', 'twentyfifteen-child' ),
		];
		?>
		<p><strong><?php echo $field['label']; ?></strong>: <?php echo $level_options[ $field['value'] ]; ?></p>

You need to adjust the snippet to fit your custom field settings. Below, we briefly explain the parameters of the function.

  • beginner’, ‘intermediate’, and ‘expert’ are the Choice values. Here, you need to input the exact same value(s) as you did in the Choices section of your Select, Checkbox, or Radio Button field on the Custom Fields backend.
  • Beginner‘, ‘Intermediate’, and ‘Expert’ are the Choice labels. Here, you need to input the label(s) you want to translate and display on the front-end. If you only specified a value when setting up your Choices, you can add any label to your code. However, if you specified a label when setting up the Choices for your Select, Checkbox, or Radio Button fields in Custom Fields, you need to input the exact same label into your code.
  • twentyfifteen-child’ is the name, or unique identifier you create. It makes it easier for WordPress to distinguish between translations and know which theme or plugin your strings belong to. 
  • Level of difficulty‘ is the label of the field. Here, you need to input the Field Label of your custom field.

You can then scan your theme for the texts and translate them using WPML’s String Translation, which allows you to translate texts that are not found in posts or pages. This includes texts from other themes and plugins on your site.

Translating Field Labels and Labels for Choices

Once you make your Field Labels and labels for Choices translatable, you can follow the steps below to translate them.

  1. Go to WPML → Theme and plugins localization and scroll to the Strings in the themes section.
  2. Select your theme and click on Scan selected theme for strings
Scanning the theme for strings
  1. Once scanning is complete, you should see the unique identifier you added to your code appear in the Textdomain column. This means the new texts for translation have been found and added to the WPML’s String Translation table.
A new Textdomain appears once scanning is complete
  1. Now, navigate to WPML → String Translation.
  2. Using the display filter at the top of the String Translation page, select the domain your texts belong to. In this case, we are searching for In domain: twentyfifteen-fields.
Using the In domain dropdown menu to search for the new strings
  1. Click the plus icon next to the string(s) you want to translate and hit enter to save the translation.