Skip Navigation

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 3.50 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 15:00 7:00 – 15:00 7:00 – 15:00 7:00 – 15:00 7:00 – 15:00 -
- - - - - - -

Supporter timezone: Pacific/Easter (GMT-05:00)

Tagged: 

This topic contains 9 replies, has 2 voices.

Last updated by Ilyes 4 days, 9 hours ago.

Assisted by: Ilyes.

Author Posts
August 5, 2024 at 3:08 pm #16040882

daveR-5

Background of the issue:
I am trying to resolve an issue with ACF Extended Dynamic Preview not working on WPML non-primary language with the Advanced Custom Field Multilingual plugin.

This is a follow-up on this issue (which I can't reopen): https://wpml.org/forums/topic/acf-extended-dynamic-preview-not-working-on-wpml-non-primary-language-with-the-advanced-custom-field/.

Here is a repeat of the workaround you provided, for convenience.

function wpml_translate_acf_post_id_compsupp_7448($preload, $post_id) {
// If the post ID is already set by previous filters, return it
if ($preload !== null) {
return $preload;
}

// Check if WPML is active and the post ID is set
if ( function_exists('wpml_object_id') && $post_id ) {
// Get the post type for the given post ID
$post_type = get_post_type($post_id);

// If a post type is found, apply the WPML filter to get the translated ID
if ( $post_type ) {
return apply_filters('wpml_object_id', $post_id, $post_type, true);
}
}

// Return the original post ID if no translation is needed or possible
return $post_id;
}
add_filter('acf/pre_load_post_id', 'wpml_translate_acf_post_id_compsupp_7448', 100, 2);

Symptoms:
The workaround provided has a few issues.
1. Dynamic previews often use acf to load to site-wide options, using get_field('[field-name]', 'option')... this no longer works inside a dynamic preview.
2. Translated texts loaded with __(...) do not render in the correct language inside the dynamic preview.

I can reproduce these problems on a new sandbox at your request (since the old sandbox is expired).

Questions:
Why are calls to get_field('[field-name]', 'option') not working inside the dynamic preview?
Why do translated texts loaded with __(...) not render in the correct language inside the dynamic preview?

August 5, 2024 at 3:26 pm #16040914

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Hello again,

Could you please reply back once you replicate the issue and if the issue replication steps are different than the initial ticket, please explain how to replicate it.

Best,

August 5, 2024 at 6:11 pm #16041385

daveR-5

Hi. I've updated the new sandbox to reproduce the issues noted above.

Let me know if you have any questions.

August 6, 2024 at 4:23 pm #16044851

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Hello again,

So our team would like to test this further,

To avoid further complications, could you please provide a step-by-step guide on how to reproduce the issue?

I understand that you already did that on the past ticket, however, since it has been a while since the last time we worked on this. It would be helpful to reopen this on a constant and clear description on how to reproduce this,

No need to re-explain the issue, I just need a step-by-step guide on how you reproduce this,

Thank you for your help,

August 7, 2024 at 3:21 pm #16048936

daveR-5

Hi. Here are the steps to reproduce the issue :

1. open the sandbox wp, and go in the Pages menu
2. switch the language to French (in the wordpress top bar)
3. open the page "Test page FR"

4. in Page Content, look at the Paragraph content block (it is a flexible content acf type, and uses ACF-extended Dynamic Render feature). The area with a dashed green border is the dynamic render preview, and shows a table with 3 rows :
- row 1 shows the value of a simple acf field, and works
- row 2 tries to show the value from an acf option field, and fails (problem #1)
- row 3 tries to show the value of a __() wp translated string, and show the english version of that string instead of the french version (it should show "FRENCH string"). (problem #2)

Interestingly, if you switch mode on the layout (by clicking on Paragraph content) and switch back to preview mode (by clicking it again), the row 3 then shows the correct translated string.

August 8, 2024 at 3:57 pm #16053704

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Thank you for the detailed and thorough explanation,

I was able to replicate it as you described and I have resent this to our developers,

I will let you know once I get any updates,

August 15, 2024 at 9:37 pm #16076314

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Hello again,

Just to confirm the first problem, I have disabled WPML and WPML ST on the sandbox, and yet, the option field is not working in English : hidden link

Could you please double check that? see if you could make it work on the default language first and then we could add it as a WPML issue,

In the meantime, our team are checking your second issue :

"Row 3 tries to show the value of a __() wp translated string, and show the english version of that string instead of the french version (it should show "FRENCH string"). (problem #2)"

Let me know if you find a way to make the option field work,

Best,

August 16, 2024 at 12:37 pm #16078291

daveR-5

Hi.

I've added a fix for row 2, it should now always work in english.
The fix was, I changed the code : get_field('option_1', 'option')
to : get_field('option_1', 'options')
(added an s to option)

Doing that, I've noticed 2 more problems, probably related in some way :

1. The value of row 2 is always in english.
If i disable the code fix wpml_translate_acf_post_id_compsupp_7448 (in functions.php), the value of row 2 work properly, and shows in the correct language.

2. The translation of the acf option pages (hidden link) doesnt work (always shows field values in english).
If i disable the code fix wpml_translate_acf_post_id_compsupp_7448 (in functions.php), the values of every field show (and saves) in the correct language.

I've disabled the wpml_translate_acf_post_id_compsupp_7448 fix for now, since it causes more problems than it solves.
I've noticed that with the fix disabled, everything works except row 3. Was an update pushed to WPML ?

August 19, 2024 at 1:47 pm #16084033

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Hello again,

Thank you for the follow-up,

As of the updates, We actually contacted ACF Extended authors about this and I suppose they implemented a fix from their side, the last detail I could find is that they confirmed that they found the issue from their side and that they will be working on it.

We are yet to receive a confirmation if the fix was implemented yet, I will keep you updated,

In the meantime, I have shared your new findings with our compatibility team to get a proper workaround,

Best,

October 2, 2024 at 11:35 am #16245266

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Hello,

This turned out to be an expected behavior as the admin language is different than the current language (secondary language). Then:

- WPML always load strings in the admin language.
- When you enable/disable the preview, the plugin does an ajax request to get the preview rendered, and this time the string gets translated.
- This is done by ACF Extended.

Solution: Go to the user profile and select the Set admin language as editing language option. With this option enabled, the strings get translated correctly.

Best,