Skip Navigation

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

Problem:
The client was unable to display translated regions, countries, and ports on their website using the Elementor Custom HTML widget.
Solution:
We recommended using the wpml_object_id filter hook to fetch translated post IDs in the current language. Detailed guidance on this hook is available at WPML documentation.
For Ajax-loaded data, we advised passing the current language to the callback function. Instructions for handling Ajax requests can be found at WPML documentation.
Additionally, we provided custom code examples to localize scripts and modify Ajax requests to ensure the correct language is used:


// Get the current WPML language
$current_language = apply_filters( 'wpml_current_language', null );
 
// Localize the script with the current language
wp_localize_script( 'common-js', 'wpmlData', array(
    'currentLanguage' => $current_language,
));

lang: wpmlData.currentLanguage

These changes were implemented on the client's staging site. If further customization is needed, we recommended contacting a certified WPML contractor from this list.

Please note that the solution provided might be outdated or not applicable to your specific case. We highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the issue persists, please open a new support ticket.

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 0 replies, has 1 voice.

Last updated by Long Nguyen 3 weeks, 2 days ago.

Assisted by: Long Nguyen.

Author Posts
November 18, 2024 at 1:20 am #16412390

nicholasC-18

Hi Nguyen,

Thanks for your suggestions.

Yes, the page can now be translated but the translated regions, countries and ports are still cannot be displayed.

Looking forward to your reply.

November 18, 2024 at 1:34 am #16412395

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi Nicholas,

Here is the new ticket. I see that you are using the Elementor Custom HTML widget to show the countries (posts) in the accordion section.
Do you use a custom query with a custom shortcode to show the posts (countries) in the frontend? If yes, I suggest you use the filter hook "wpml_object_id" to get the translation post ID in the current language and get post information based on the ID.
Please read more about the hook in the documentation https://wpml.org/documentation/support/achieving-wpml-compatibility-for-your-themes-and-plugins/#fetch-ids-from-different-languages

Looking forward to your reply.
Thanks

November 25, 2024 at 7:28 am #16437981

nicholasC-18

Hi Nguyen,

Sorry for the late reply, just came back and tried the "wpml_object_id" filter. Unfortunately it still doesn't work properly.

Could you please go into our WordPress CMS and check?

Thank you

November 25, 2024 at 7:44 am #16438015

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

I would like to request temporary access (wp-admin and FTP) to your site so I can take a better look at the issue. It would be better to have a testing site where the issue is replicated. Your next reply is set to private to share the info.

❌ IMPORTANT: Please backup your database and website before proceeding ❌
You can use this plugin to create the backup: https://wordpress.org/plugins/duplicator/
✙ I would need your permission to de-activate and re-activate Plugins and the Theme to change configurations on the site if needed. This is also a reason the backup is critical.

Looking forward to your reply.
Thanks

November 26, 2024 at 1:34 am #16442334

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Can you please share the server protection account? Your next reply is set to private to share the info.

Also, if you are using Ajax to load the data, I suggest you follow the documentation to pass the current language to the callback function and switch the language there to get the correct translation post.
https://wpml.org/documentation/support/achieving-wpml-compatibility-for-your-themes-and-plugins/#ajax-requests

Looking forward to your reply.
Thanks

Sign in 2024-11-26 08-14-22.jpg
November 27, 2024 at 1:41 am #16447210

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Now I see the countries, ports ... are displayed on the translation page, so I think this issue is resolved, see the attached screenshot.

Also note that, this is completely a custom code. I would like to inform you that helping you with custom code, is out of the scope of WPML, but I helped you by pointing you to the source of the problem you are having.
If you cannot accomplish this, I recommend you contact one of our certified partners who will be more than happy to help you with this. In this link, you will find a list of our certified partners: https://wpml.org/contractors/

Thanks.

查找当地办事处 | PIL - Pacific International Lines 2024-11-27 08-21-22.png
November 27, 2024 at 9:20 am #16448228

nicholasC-18

Hi Nguyen,

I think there is a misunderstanding between us, let me describe the problem again.

On the Chinese page, the regions and countries can be displayed, but it is still displayed in English. So my question is why the translated regions and countries cannot be displayed in Chinese.

Please refer to the attached screenshots.

Thank you.

Screenshot 2024-11-27 171700.png
Screenshot 2024-11-27 171420.png
Screenshot 2024-11-27 171256.png
November 28, 2024 at 3:38 am #16452221

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

I can show the tranlsation countries on the translation page, here are some steps that I've done on your staging site:

1. Edit the snippet "Enqueue Styles & Scripts", add the following code to localize the current language:

	// Get the current WPML language
    $current_language = apply_filters( 'wpml_current_language', null );

    // Localize the script with the current language
    wp_localize_script( 'common-js', 'wpmlData', array(
        'currentLanguage' => $current_language,
    ));

2. Edit the file /wp-content/themes/hello-theme-child-master/theme/default/js/pil-ajax.js,
around the line 3810, replace the code

lang: typeof ICL_LANGUAGE_CODE !== 'undefined' ? ICL_LANGUAGE_CODE : 'en'

with this one to pass the current language code to the callback function:

lang: wpmlData.currentLanguage

3. Edit the snippet "LOCAL OFFICES - Map & Accordion", move the query that fetches countries inside the function wp_locations_json() and use the post ID instead of the translation post ID because you have already switched the language to the Chinese language.

Please notice that, this is the custom code and beyond our scope of support. The steps above are just the sample code to show how it works. If you cannot accomplish this, I recommend you contact one of our certified partners who will be more than happy to help you with this. In this link, you will find a list of our certified partners: https://wpml.org/contractors/

Thanks for your understanding and patience.