Home›Support›English Support›[Resolved] The translated regions, countries and ports are still cannot be displayed
[Resolved] The translated regions, countries and ports are still cannot be displayed
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.
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
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.
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/
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.
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
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/