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

Last updated by ghledisC 1 week, 4 days ago.

Assigned support staff: Bigul.

Author Posts
September 30, 2019 at 8:34 am #4662973

ghledisC

I am trying to: Create a translated PDF programmatically.

I expected to see: A translated taxonomy in different languages

Instead, I got: A translated taxonomy only in Portuguese

I have a custom code attached to the save_post hook that uses tcpdf to generate a pdf from custom fields.

I was working on a staging site up to recently, and since other people have uploaded content to the live site, I wanted to simply copy my code over to the live site instead of publishing the staging site and loosing all the uploaded posts.

What happened is that after copying my custom code into functions.php onto the live site, the behavior changed, and the translated PDFs all came out in Portuguese.

On the staging site it worked perfectly.

I know that this doesn't give many details, but I don't think the problem is with my code, because I used the same exact code on the staging site.

I tried to change my code to use
global $sitepress;
$sitepress->switch_lang($lang);
and also switch_to_locale(');

$sitepress->switch_lang works for all custom fields except for taxonomies which stays in Portuguese, therefore I think that there is some setting that retrieves the Portuguese translation instead of the actual post language.

I checked settings in WPML, but couldn't find any difference between staging and live site.

I have 7 languages and no explanation as to why exactly Portuguese was chosen.

The English and the Portuguese PDFs are saved correctly. Only the other languages switch to Portuguese.

Of the top of your heads could you maybe point me in the right direction where I should look to correct this? I am not expecting a full solution, just some ideas where to look, because I am out of ideas.

September 30, 2019 at 6:28 pm #4667197

Bigul
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

Welcome to the WPML support forum. I will do my best to help you to resolve the issue.

Please try the following troubleshooting steps after a full site backup and make sure the issue is existing or not.

1) Upgrade to the latest version of WPML(4.2.9)

2) Go to WPML>>Support page

3) Click on Troubleshooting link (blue link in the middle of the page)

4) In Troubleshooting page, please click on the following options of the *Clean up* section. Wait for confirmation of processing after each one.

- Clear the cache in WPML
- Remove ghost entries from the translation tables
- Fix element_type collation
- Set language information
- Fix WPML tables collation
- Assign translation status to duplicated content
- Fix terms count
- Fix post type assignment

--
Thanks!

Bigul

October 1, 2019 at 9:46 am #4670543

ghledisC

I followed your instructions step by step. Unfortunately, the problem is unchanged.

It only happens with taxonomy terms if I use $sitepress->switch_lang($lang);

If I however don't use it, the custom field data is translated correctly. But template strings and taxonomy terms are in portuguese. So template strings are handled with this.

On my staging site everything works correctly if I use switch_lang($lang). If I don't, only strings written in the template stay in Portuguese.

October 1, 2019 at 10:14 am #4670915

ghledisC

How do I upgrade to 4.2.9? I have no notification that there is a newer plugin out than what I have (4.2.8).

October 1, 2019 at 2:26 pm #4672933

ghledisC

Additional information I found.
This is the code I use to retrieve the term name:

$manufacturer = get_the_terms($post_id, 'manufacturer')[0]->name;

I checked and the post_id is correctly retrieved for the language.

The term id however is always Portuguese.

Update:

I found that redeclaring variables on terms made WPML somehow return Portuguese. I simply went back to the point in the script where I knew it still had to had the correct translation, and thereby managed to handle the problem. Although I still don't know why this happened. If you know I would like to know, if not I will close this thread as closed.

October 1, 2019 at 5:32 pm #4674407

Bigul
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

Thank you for the feedback. You are not getting the latest version for the upgrade because of the installer caches. Please try the following steps to get the latest version.

1) Visit Plugins>>Add New page
2) Click on *Commercial* tab
3) Then press on *Check for updates*. It will help you to refresh the caches.

Please try once again with the latest version of WPML and make sure the issue is existing.

Also would like to confirm this custom code is calling whenever a user creates or update a Post, am I right? I will check about this with our developers.

--
Thanks!

Bigul

October 2, 2019 at 9:06 am #4678127

ghledisC

I updated now WPML to the newest version and tried again.

The issue persisted.

I have now rearranged some of the code to declare variables earlier and now I get the expected result if I change language with $sitepress->switch_lang($lang); to the post language with a switch structure.

If I don't do this, I still get some template strings in Portuguese, but for now I found my workaround.