Skip Navigation

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

Problem:

Using wpml_object_id we get the correct menu id's for each language, however the actual menu and thus, menu items returned, are the same base language (English in our case) for all translations.

This happens in the wp-graphql "graphql_register_types" action.

Solution:
We adjust terms, and the menu is a taxonomy. Disable the option " Adjust IDs for multilingual functionality" from WPML->Languages->Make themes work multilingual.

Relevant Documentation:
- https://wpml.org/faq/how-to-optimize-mysql-queries/#auto-id-adjust

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 7 replies, has 2 voices.

Last updated by Dražen 1 year, 10 months ago.

Assisted by: Dražen.

Author Posts
April 21, 2023 at 1:06 pm #13518055

mikkelD

I am trying to:
Use translations for nav_menus and output it in GraphQL with translations. GraphQL menus() can accomplish this.

Using wpml_object_id we get the correct menu id's for each language, so that works fine. However the actual menu and thus, menu items returned, are the same base language (English in our case) for all translations.

This happens in the wp-graphql "graphql_register_types" action.

But! When we run the same code and output it in functions.php or such (outside of the specific graphql-action), we get the expected results of all translated menus and their corresponding menu items.

My guess, is that this has to do with when the code is executed? Is there a specific cause for this, perhaps an easy way to circumvent it?

It does seem like an odd issue as other translations with WPML seem to be working fine. We tested only using having WPML and WP GraphQL plugins activated, with the same result.

Thanks for the help!
Chris

April 24, 2023 at 8:23 am #13525203

Dražen
Supporter

Languages: English (English )

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

Hello Chris,

thanks for contacting us.

I am afraid WP GraphQL is not yet officially compatible with WPML, so some issues may happen.

Our compatibility developers are working on this feature and I think soon we might release an addon plugin that will provide compatibility with WP GraphQL.

For now, the best I can do is add your ticket to escalated dev ticket and update you when there is more news or release.

Regards,
Drazen

April 24, 2023 at 12:58 pm #13527259

mikkelD

Hi Drazen,

We are aware that it's not officially supported. However many third party solutions have us almost running it completely flawless. Reaching the Menu Navigation data is the only thing that's missing.

I do believe that there should be someone technical that can, if not outright solve it for us, at the very least point us in the right direction for how we can reach menu nav data in this instance, where we are only getting the "base language" instead of the actual translation.

Is it a firing sequence or a scope issue? Can we reach the specific scope somehow or trigger it?

April 27, 2023 at 12:02 pm #13549389

mikkelD

Hi Drazen,

Thanks for setting up a test environment. I've installed the WP GraphQL plugin, added two items to the main menu, translated the menu and added two Spanish items that are unique, and I believe I've managed to replicate the issue we are having with the navigation.

Here is the file with the relevant code, see the steps of logic below the link
hidden link

1. We get all languages in WPML (line 114
2. We select a menu (line 121)
3. Loop all languages (line 124)
4. Get the menu id for each language (line 126) << This actually seems to work, we get unique IDs
5. Get the menu items from the translated menu id (line 133) << This here is probably where it fails

Basically the menu items returned are the english ones, even for the Spanish menu id. We've made some debugging attempts in the formatMenuForGraphQL function, but I believe you can ignore it as I suppose line 133 should send back the Spanish menu items in the first place?

It could be that we have done the implementation in the wrong way, if that's the case feel free to point out how we can solve it!

You can see the actual debug output here: hidden link

I've attached the two menus for comparison. We translate the menu but as we create the navigation from scratch each time, running "apply_filters( 'wpml_object_id', $menu_item->ID, 'nav_menu_item', FALSE, $lang );" doesn't actually work at all and returns NULL.

Screenshot 2023-04-27 at 13-28-43 Menus ‹ Sandbox — WordPress.png
Screenshot 2023-04-27 at 13-29-00 Menus ‹ Sandbox — WordPress.png
April 27, 2023 at 1:01 pm #13550021

Dražen
Supporter

Languages: English (English )

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

Hello,

thanks for getting back and taking the time to reproduce.

I have shared your case and related info with our 2nd tier support.

I will update you have some news.

Regards,
Drazen

April 27, 2023 at 1:36 pm #13550409

Dražen
Supporter

Languages: English (English )

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

Hello,

seems we have and do adjust terms (and the menu was a taxonomy) and this was the case. If you disable the option " Adjust IDs for multilingual functionality" from WPML->Languages->Make themes work multilingual, seems to work fine.

Related docs:
- https://wpml.org/faq/how-to-optimize-mysql-queries/#auto-id-adjust

Hope that works for you also 🙂

Let us know, regards.
Drazen

April 28, 2023 at 9:19 am #13555979

mikkelD

Hi Drazen!

Thank you, that solved the issue!

As we are only using WPML through GraphQL I expect that there will be no issue for any theme or the like.

Thanks again and have a great weekend!
Chris

April 28, 2023 at 9:23 am #13555987

Dražen
Supporter

Languages: English (English )

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

Hello Chris,

thanks for getting back and glad to hear that it helped.

I will be closing this ticket now, feel free to open a new one if there is anything else we can help with.

Have a great weekend, too!

Regards,
Drazen