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

Last updated by Radu 6 months, 3 weeks ago.

Assigned support staff: Radu.

Author Posts
February 15, 2021 at 3:48 pm #8089595

desireeM

>Tell us what you are trying to do?

In string translation, when I manually write text in the translation field and then click outside of it, it saves it.
When I instead put the text with .js (e.g. I click button which pastes the text in the translation field), it won't save.
Since you are using a compiled js for this, it's impossible to find out what trigger you are using.

How can I put my translated text with .js?

February 15, 2021 at 3:53 pm #8089829

desireeM

e.g. to manually target it (via console, as a simple test example)
document.querySelector("body > div:nth-child(12) > div > div > div > div.ant-popover-inner > div > div > div > div:nth-child(2) > div.ant-col.ant-col-sm-12 > textarea").value='abc';

It puts the "abc" there, but when clicking on the side it's not saving it.

My code is run from tampermonkey, as this is a tool to help personnel with special needs to use string translation.

Fyi my WPML things:
WPML Multilingual CMS Installed Yes 4.4.8
WPML CMS Nav Not installed No n/a
WPML String Translation Installed Yes 3.1.6
WPML Sticky Links Not installed No n/a
WPML Translation Management Installed Yes 2.10.4
WPML Media Installed Yes 2.6.2
WooCommerce Multilingual Installed No 4.10.4
Gravity Forms Multilingual Not installed No n/a
Yoast SEO Multilingual Installed No 1.2.4

February 16, 2021 at 2:18 pm #8098167

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hey Desiree,

It looks that you're using a previous version of the WPML plugins on your website. Can you update them (you can find the latest versions here: https://wpml.org/account/downloads/) and tell me if you still have this issue, please?

I'm using the latest version of the plugins on my website and when I go to WPML → String Translation area, press the + icon to add a translation, paste the translation (not typing it, just pasting from a different page), then click outside that box, the changes are saved.

Please tell me if things are working fine for you too once you update the WPML plugins.

Thanks,
Radu

February 18, 2021 at 8:12 pm #8122215

desireeM

Dear Radu,

Pasting works perfectly fine for me too.
The problem is with JS. I need to put the translated text with JS.

Same in latest version.

February 19, 2021 at 2:49 pm #8129275

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hey Desiree,

In this case, you need to create some custom code and localize the string by using this:
https://developer.wordpress.org/reference/functions/wp_localize_script/

You need to localize the script through PHP, use it in JavaScript, then scan the theme/plugin where you added the PHP code to make the strings available for translation in the WPML → String Translation area. Once you add the translation here, everything should be fine on the front-end.

Thanks,
Radu

February 21, 2021 at 11:16 am #8138433

desireeM

I know that. My js works fine. Can you please read what I write?

The problem is that when inserting text into the string translation with js (instead of typing it), it won't save/trigger a save for it. I need to know how I can get the string translation js to save the data input by js (instead of by typing with keyboard).
Since you use some compiled js in string translation it's impossible for others to find out how exactly your code works there, so I am asking here how to make it save things we insert into the string translation translation field with js

February 22, 2021 at 9:28 am #8142647

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hey Desiree,

Sorry about the confusion from my previous reply. I was handling a different ticket at the same time, with some questions about translating string inside a JavaScript file.

Please have a look at the short video that I created here:
hidden link

and tell me if this is the change that you're making too. Basically, I just paste a text as translation, without typing it, and click outside the text field. As you can see, the message that the translation was saved appears on the right corner. Can you tell me if this is the change that you're making too, please?

Thanks,
Radu

February 22, 2021 at 9:34 am #8142685

desireeM

That's exactly what I want to do. But instead of "Right click" => "Paste", I want to do it with js.
I have the js and it's working (I can see the text it pasted by js)

The problem is that when I do it WPML is not saving the text I put with js when I click outside of the field.

February 23, 2021 at 10:03 am #8152433

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hey Desiree,

I understand now what's the setup that you're using. As you may know, helping with custom code is outside of our support scope so I'm afraid that there's nothing I can do in this case.

However, I asked my colleagues to have a look at this and see if there's anything that might help you with the change you're looking for. This doesn't mean that I'll find a hook, but I can ask to see if there's something I'm not aware of. I'll keep you posted about this.

Thanks,
Radu

February 23, 2021 at 10:13 am #8152493

desireeM

Thank you.
There wont be a hook, but some triggering that does trigger the save which I need to know when/what triggers this, so I can artifically trigger it without actually writing into the field.

If you cant find something, please provide the uncompiled js for this, I would figure it out myself then.

February 23, 2021 at 10:37 am #8152789

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hey Desiree,

I'm not sure that I can provide you the uncompiled JavaScript code, but I'll keep you posted about this once one of my colleagues is checking this out and replies back to me.

Thanks,
Radu

February 26, 2021 at 6:34 am #8178405

desireeM

@support robot: not this is not done yet, currently waiting for a reply, do not close this please.

February 26, 2021 at 2:07 pm #8181565

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hey Desiree,

I got a message back from one of my colleagues and it seems that this part is created with React. The save event is bound to key events, but I'm afraid that there's no chance I can help you with in order to achieve what you're looking for.
You can try to simulate the Enter key on the textarea. Unfortunately, this requires custom coding and I can't help you with that (since it's outside of our support scope).

Regards,
Radu

February 26, 2021 at 2:58 pm #8182221

desireeM

Yes I was aware of that, which is why I asked for the uncomplied react code.
We already tried key events, however we dont know the exact trigger.

Would it be possible to just get this 1 function of uncompiled react that contains the eventlistener/trigger for saving? bc based on that I would be able to create it for our users with special needs.

March 1, 2021 at 6:05 am #8193217

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hey Desiree,

I'm sorry but I can't provide you this piece of code. Also, my colleague told me that this is not a public function so it can't be called from outside. I'm afraid that I can't help you with this.

Regards,
Radu