Skip to content Skip to sidebar

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

Problem:
The client was experiencing issues with mapping a custom language code for Chinese Simplified (zh-CN) in WPML. Despite multiple attempts to save the settings, the language showed errors and was not mapping correctly, which prevented automatic translations.

Solution:
We recommended the following steps:
1. Ensure a full site backup is created.
2. Replace the function

get_languages_supported_by_automatic_translations()

in the file

\sitepress-multilingual-cms\classes\ATE\API\class-wpml-tm-ate-api.php

with a new function that includes a case mapping for 'zh-CN' to 'zh-cn'.
3. Save the changes and verify if the issue is resolved.

This solution might become outdated or may not directly address similar issues due to different configurations or WPML updates. If this solution does not resolve your issue, or if you encounter other problems, please visit our support forum and open a new ticket. We also 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.

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

Last updated by Carlos Rojas 7 months, 2 weeks ago.

Assisted by: Carlos Rojas.

Author Posts
November 29, 2024 at 9:34 am #16458390

Carlos Rojas
WPML Supporter since 03/2017

Languages: English (English ) Spanish (Español )

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

Good morning.

I would like to ask your authorization to create a copy of the site to send it to our 2nd tier of support.

November 29, 2024 at 10:48 am #16458927

sonT-3

I'm OK. Please proceed

November 29, 2024 at 1:56 pm #16459907

Carlos Rojas
WPML Supporter since 03/2017

Languages: English (English ) Spanish (Español )

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

Thank you for your authorization.

I have escalated this ticket to our 2nd tier of support so our specialists can reproduce the issue and isolate its cause. I will get back to you as soon as I get information from them.

December 3, 2024 at 10:55 am #16471101

Carlos Rojas
WPML Supporter since 03/2017

Languages: English (English ) Spanish (Español )

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

Hi there,

Please apply this workaround:
- Create a full site backup
- Replaced the get_languages_supported_by_automatic_translations() function in \sitepress-multilingual-cms\classes\ATE\API\class-wpml-tm-ate-api.php with:

			public function get_languages_supported_by_automatic_translations( $languageCodes, $sourceLanguage = null ) {
				$sourceLanguage = $sourceLanguage ?: Languages::getDefaultCode();
    
				$lang_case_mapping = [
			'zh-CN' => 'zh-cn',
];
				$languageCodes = array_map(function($code) use ($lang_case_mapping){
					return isset($lang_case_mapping[$code]) ? $lang_case_mapping[$code] : $code; 
				}, $languageCodes);
    
				$result = $this->requestWithLog(
					$this->endpoints->getLanguagesCheckPairs(),
					[
						'method' => 'POST',
						'body'   => [
							[
								'source_language'  => $sourceLanguage,
								'target_languages' => $languageCodes,
							]
						]
					]
				);
    
				$revert_lang_code = function($obj) use ($lang_case_mapping) {
					$lang_case_mapping = array_flip($lang_case_mapping);
					foreach ($obj as $key => $value) {
						if (isset($lang_case_mapping[$key])) {
							$obj->{$lang_case_mapping[$key]} = $value;
							unset($obj->$key);
						}
					}
    
					return $obj;
				};
    
				return Maybe::of( $result )
				            ->reject( 'is_wp_error' )
				            ->map( Obj::prop( 'results' ) )
				            ->map( Lst::find( Relation::propEq( 'source_language', $sourceLanguage ) ) )
				            ->map( Obj::prop( 'target_languages' ) )
				            ->map( $revert_lang_code );
			}

- Save the changes and double-check if the issue disappeared

Could you tell me the results of the steps described above?

December 4, 2024 at 4:20 am #16474279

sonT-3

Finally, I can confirm that this fix works! It took me to remove the old custom Chinese Simplified, then after I create the new custom Chinese Simplified, it works normally.

But what will happen when I update WPML in next release. Will the fix got replaced?

chrome_P8bDrkNjgt.png
chrome_q47656klX8.png
December 4, 2024 at 8:48 am #16475075

Carlos Rojas
WPML Supporter since 03/2017

Languages: English (English ) Spanish (Español )

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

Great!

This fix should be added to the next release of WPML. However, it is always recommended to create a copy of the site before updating the WPML plugins so you can check if the fix is applied 🙂