Skip Navigation

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

Problem:
The client is developing a multilingual site using WPML and ACF (flexible content) and needs to handle the 'wpml_cf_preferences' differently based on the editor mode (WP Editor or WPML translation editor) for specific posts. They encountered issues with repeater fields not syncing correctly between translations depending on the translation mode used.
Solution:
We do not have a direct hook to dynamically change 'wpml_cf_preferences' based on the editor mode at the moment. However, you can check the editor mode used for translation by querying the 'editor' column in the 'icl_translate_job' database table or the '_last_translation_edit_mode' meta. Based on this information, you can programmatically set the 'wpml_cf_preferences'. For detailed guidance on setting translation preferences for ACF fields, refer to our documentation here: Setting the Translation Preferences for ACF Fields Created Using PHP Code.

If this solution does not apply to your case, or if it seems outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If issues persist, please open a new support ticket at WPML support forum for further assistance.

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.

Our next available supporter will start replying to tickets in about 7.61 hours from now. Thank you for your understanding.

Tagged: 

This topic contains 10 replies, has 2 voices.

Last updated by duncanM-2 1 month, 3 weeks ago.

Assisted by: Bobby.

Author Posts
July 16, 2024 at 2:11 pm #15961025

duncanM-2

Background of the issue:
Hello, we're trying to develop a multilingual site using WPML + ACF (flexible content). The vast majority of pages will be translated automatically (WPML translation editor + deepL). However, some will be translated manually (WP Editor). When registering an ACF field (via PHP) we're able to add wpml_cf_preferences attribute to instruct how this field should be handled. The problem is that we need to handle it differently depending on which editor (WP Editor/WPML translation editor) is enabled for some specific post. A good example is repeater field. wpml_cf_preferences should be set to 'Copy once' when WP Editor is enabled and 'Copy' when WPML translation editor is enabled to make sure repeater items are always in sync between translations.

Symptoms:
I was not able to find any hook that could override wpml_cf_preferences when e.g. post is being updated.

Questions:
How can we handle wpml_cf_preferences differently depending on which editor (WP Editor/WPML translation editor) is enabled for a specific post?

July 16, 2024 at 11:57 pm #15963014

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hello,

Please note that we do not provide custom work within this forum. I will, however, try to point you in the correct direction.

I will discuss this with our developer's team and get back to you with some suggestions.

July 17, 2024 at 7:51 pm #15968324

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi,

While we do not have a ready to go solution or hook to help with this, based on the feedback I got you might want to look into the following:

In the database table icl_translate_job, we have a column called "editor."

wp = "Different Designs per language" mode
wpml = Classic WPML Editor
ate = Advanced Translation Editor as the name says

The only downside is that this is saved per job, not per page.

We also have meta "_last_translation_edit_mode" which contains the same values as mentioned above.

July 18, 2024 at 9:26 am #15971311

duncanM-2

Hi Bobby, thanks for getting back to me. However, I'm not sure were on the same page. The main problem we're facing is the way WPML handles custom fields. I'll try to provide an example. Let's assume there is a custom repeater field named features with wpml_cf_preferences attribute set to 'copy once'. It works just fine in wp mode (Different Designs per language) - it copies the features once and then you'e managing them for each language separately. But let's say I have another page with this ACF field in ate mode. In this case 'copy once' doesn't work ok - it doesn't keep features in sync (e.g. new feature was added, it doesn't appear in other languages). I would expect wpml_cf_preferences parameter having value 'copy' for this field when page is in ate mode so that items are always in sync. I know there is a way to change the WPML settings for ACF fields in admin but it's stored in icl settings and is global isn't it? Basically, we need an ability to amend wpml_cf_preferences setting on page level (based on editor mode) or some filter allowing to override it when post is being saved and processed by WPML. I hope all above makes sense.

July 18, 2024 at 6:39 pm #15974234

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

To verify I understand correctly.

You are using wpml_cf_preferences and setting the fields programmatically based on this documentation:
https://wpml.org/documentation/related-projects/translate-sites-built-with-acf/setting-the-translation-preferences-for-acf-fields-created-using-php-code/

The 'copy-once' setting takes effect when you translate using the WordPress Editor but it does not work when you use the ATE editor, correct?

I believe it should work regardless -- if that is the case I would like to take a closer look.

July 19, 2024 at 8:00 am #15976526

duncanM-2

Yes, that's correct Bobby. We register our ACF fields via PHP code and set wpml_cf_preferences based on documentation you've mentioned. This morning I performed a one more test.

- I've created a basic 'features' ACF group with a repeater field (copy once, wpml_cf_preferences=3) containing one text field (translate, wpml_cf_preferences=2)
- Created a new page which is in ate mode by default (we use Translate Everything Automatically mode)
- Added some items to the repeater field - all good, all items were translated
- Added one more item - it has not been added to other languages (due to copy once setting)

As you can see the above setup doesn't work ok with auto translation on the other hand, it is suitable for wp ("Different Designs per language") mode. That's why we have a need to have wpml_cf_preferences value dynamic based on editor mode.

What we expect:
- Page is always in sync when it's in ate mode which doesn't work ok with the above setup. Basically, it's an issue with fields supporting variable number of items e.g. relationship, flexible_content, repeater, etc. as it breaks when e.g. new items are added (they don't appear in translations)
- Users can manage content for each language separately when in wp mode. This part works ok with the above setup

I hope all above makes sense and thanks for your help!

July 19, 2024 at 10:33 pm #15980059

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

I would like to request temporary access (wp-admin and FTP) to your site to test the issue.
(preferably to a test site where the problem has been replicated if possible)

**Before we proceed It is necessary to take FULL BACKUP of your database and your website. Providing us with access, you agree that a backup has been taken **

I often use the Duplicator plugin for this purpose: http://wordpress.org/plugins/duplicator/
You will find the needed fields for this below the comment area when you log in to leave your next reply.
The information you enter is private which means only you and I have access to it.

NOTE: If access to the live site is not possible and the staging site does not exist please provide me with a duplicator package created with the duplicator plugin.

Thank you,
Bobby

July 25, 2024 at 12:31 am #16000735

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi there,

I was able to reproduce the issue, however, switching to the manual translation did not resolve it unless I use overwrite or copy content.

What are your results if you switch these from 'copy once' to 'copy'

pageComponents_0_features
pageComponents_0_options
pageComponents

At first I thought it was related to this issue https://wpml.org/errata/advanced-custom-fields-multilingual-reordering-repeater-fields-makes-the-translations-unsynchronised/, but this might be due to misconfiguration perhaps, because the new content is pulled into ATE but it never displays in the front end or gets pulled in the backend editor.

July 29, 2024 at 6:34 am #16013776

duncanM-2

Hi Bobby,

once I switch to 'copy' ATE works as expected (fields are in sync and translated ok). But then it breaks the wp (Different Designs per language) mode:

- Assume we have a page with some features added and 1:1 (structure wise) page in German to begin with
- Switched to German, added a new item and saved the post. Once it's saved the newly added item is gone
- Similar thing happens if I try to remove an item. Once page is saved and new empty item is appended to the end of the features list.

Basically, it tries to keep the number on items in sync with the main language. It works as expected from the config perspective but the issue is that the same config (wpml_cf_preferences value) doesn't work ok for both ATE and WP. Repeater like fields (repeater, flexible, etc.) should have wpml_cf_preferences set to 'copy' when in ATE mode and 'copy_once' when in WP mode to make it work as expected. That's why I asked for some hook that allows to override wpml_cf_preferences value provided in config on the moment the page is being saved.

July 29, 2024 at 7:53 pm #16017841

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

I got it, thank you for confirming.

I believe that is the expected case when using 'copy' it will always attempt to sync with the default language.

As a test, if you haven't tried already what are your results when using

translate instead? This option would not attempt to sync the items between the 2 languages.

July 30, 2024 at 6:31 am #16018642

duncanM-2

Hi Bobby, I've tested it using 'translate' and it looks like it did a trick!!! I didn't realize 'translate' is applicable for repeater like fields. Many thanks for your guidance 😉

duncanM-2 confirmed that the issue was resolved on 2024-07-30 06:33:23.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.