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.

This topic contains 9 replies, has 2 voices.

Last updated by Nigel 1 year, 5 months ago.

Assisted by: Nigel.

Author Posts
January 12, 2024 at 11:06 pm #15180815

raduV

Hello, I’ve modified my website (hidden link) to use /language instead of ?lang= and I’ve having some problems with the wordpress rest api. For the default language, when the _embed parameter is send, the response has the _embedded property is returned in the response. When the language is different from the default, the _embedded is missing from the response. What should I do to include the _embedded property for the rest of the languages? I've made a copy of the website where I actually modified and tested the /language: hidden link

January 13, 2024 at 8:29 am #15181129

raduV

Here's the API call, as requested by Bobby: hidden link

hidden link

January 15, 2024 at 11:02 am #15184410

Nigel
WPML Supporter since 02/2016

Timezone: Europe/Madrid (GMT+02:00)

Hi there

Let me take over here.

I understand that the issue is, when switching to use languages in directories instead of as parameters, the _embedded property that should be included in the REST API responses is missing with secondary languages. It is included in the response for the default language.

I can confirm that behaviour on your site based on the same requests you provided.

I need to look into this a little further, to see what is expected, so I'll work on my own test site and then come back to you when I've done that.

January 15, 2024 at 11:28 am #15184595

raduV

Hi Nigel,

Thank you, appreciate your help!

January 15, 2024 at 2:58 pm #15185900

Nigel
WPML Supporter since 02/2016

Timezone: Europe/Madrid (GMT+02:00)

Just to let you know I'm still working on this.

I see that the issue is easy to reproduce on a clean test site, it is not specific to your site.

I am working through the codebase to identify where exactly the issue is triggered so that the developers can address it, and to see if I can find a workaround in the meantime that will help you move forward.

I'll be back in touch.

January 16, 2024 at 10:21 am #15188937

Nigel
WPML Supporter since 02/2016

Timezone: Europe/Madrid (GMT+02:00)

I have found that using 'lang' as the parameter to specify language in the request (you are using 'wpml_language') appears to fix this problem.

You can see in the screenshot I used 'lang=fr' in the request and the response includes the expected '_embedded' property.

Could you please modify your requests so that they use 'lang' as the parameter to specify the language.

Screenshot 2024-01-16 at 09.56.26.png
January 16, 2024 at 1:05 pm #15189852

raduV

Swagger API extract WPML_language (attached a screenshot)

WhatsApp Image 2024-01-16 at 12.41.30_51600973.jpg
January 18, 2024 at 8:32 pm #15202161

Nigel
WPML Supporter since 02/2016

Timezone: Europe/Madrid (GMT+02:00)

OK, if it is not possible to modify the request parameter to use 'lang' instead of 'wpml_language' then I can propose a workaround, editing a WPML plugin file, which you can use in the meantime until the developers take a closer look at this and come up with a permanent solution.

Edit the file plugins/sitepress-multilingual-cms/classes/language/Detection/Backend.php

Locate the function get_requested_lang() defined from line 25.

Replace the first few lines with this:

	public function get_requested_lang() {
		$findFromSystemVars = Fns::until(
			Logic::isNotNull(),
			[
				$this->getForPage(),
				$this->getFromParam( [ 'get', 'lang' ], true ),
				$this->getFromParam( [ 'get', 'wpml_language' ], true ), // workaround
				$this->getFromParam( [ 'post', 'icl_post_language' ], false ),
				$this->getPostElementLanguage(),
			]
		);

Note that the only change is the line I added with a comment "workaround".

Try that and let me know if that helps.

January 21, 2024 at 11:26 am #15208149

raduV

I can make it utilize lang, I just want to let the you the language parameter was provided by swagger, that's why I've been using it until now.

Thanks for your help, appreciate it!

January 22, 2024 at 9:12 am #15209987

Nigel
WPML Supporter since 02/2016

Timezone: Europe/Madrid (GMT+02:00)

I guess we can close here, then.

I have raised the issue of the wpml_language parameter with the developers, and I expect at some point they will look to update the code so that both the lang and wpml_language parameters behave the same, but in the meantime if you are able to shift to use the lang parameter you should do so.

Thanks for clarifying.