Multilingual Custom Fields

Overview

In its most simplest form, ACF is a UI for saving custom field values to a post object and because most multilingual plugins will create a new post for each translation, it is easy for ACF to work alongside your multilingual website without any configuration needed.

This article will provide instructions for a successful multilingual ACF installation.

WPML

The WPML plugin works well with ACF. Here are some instructions and tips to make sure your website runs smoothly:

1. Enable field group translation

Before creating a field group, please enable the “Field Groups” post type for translation. This is possible via the WPML -> Translation management page.

Please leave “Fields” as Do nothing as to avoid conflicts when loading fields.

WPML post type settings

2. Translate field groups

Each language will require it’s own translation of a field group. The easiest workflow is to create your field group in the default language and then use the ‘Duplicate’ tool to create a duplicate field group in the new language. You can then edit the field’s label, settings but the field’s name must remain constant across all translations. This is because ACF uses the field’s name to save it’s data.

WPML duplicate

3. Editing a post

When editing a post, only the relevant language field groups will be loaded.

To make a translation of the post, you may use the same ‘Duplicate’ tool as above, but be sure to click the ‘Translate Independently’ button to prevent the translated post’s custom fields from being modified by the original post.

WPML independant

4. Avoid data loss

When editing a post, WPML will display a metabox containing a list of all custom fields and options to ‘Translate’ or ‘Copy’ the data. These settings can prevent ACF from correctly saving data so it is important to understand when to use them.

WPML Content Setup

The ‘Copy’ setting will (upon update of the post) copy across the original post’s value and replace the translated post’s value. Please note that this setting deos not change to ‘Translate’ after the post has been saved, so if you have selected ‘Copy’, ACF will not be able to save a unique value for the translated post.

The ‘Translate’ setting will do nothing, and allow ACF to correctly save the custom field data to the post.

You will notice that WPML shows hidden custom field values such as ‘_image’. These should not be copied as the value relates to a field and because each field is different for each translation, these should also be. In short, ignore the underscore fields and leave as ‘Translate’

Further reading

WPML have also published a guide for compatibility between the two plugins which can be found here: https://wpml.org/documentation/plugins-compatibility/translate-sites-built-with-acf/

Translating Options Page Compatibility

To allow values saved in the wp_options table to be translated (options page), some code is required to tell ACF about the current/default language. ACF contains WPML support out of the box, but for all other multilingual plugins, please use the following code to add the curent/default language code.

This will allow ACF to modify the name used when saving the wp_options row, and allow multiple versions (translations) of the save value.

add_filter('acf/settings/default_language', 'my_acf_settings_default_language');
 
function my_acf_settings_default_language( $language ) {
 
    return 'en';
    
}

add_filter('acf/settings/current_language', 'my_acf_settings_current_language');
 
function my_acf_settings_current_language( $language ) {
 
    return 'fr';
    
}

Please note the above functions will require some logic to determine the current/default settings.

Save