Skip Navigation

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

Problem:
The client is unable to change the language code for Chinese from "zh-hans" to "cn" to match the URLs of pages translated manually before installing WPML. Additionally, the client wants to know how to add a custom link to the language switcher.
Solution:
We explained that the language code cannot be changed once it's set. However, we suggested creating a custom language with the desired code "cn" during its creation. For detailed instructions on adding a custom language, we referred the client to our documentation: Editing WPML's Languages Table.

To add a custom link to the language switcher, we advised creating a custom Language Switcher and provided a guide for this process: Custom Language Switcher. Specifically, for adding the custom link with PHP, we directed the client to a section of the guide: The PHP Part.

We also mentioned that if translations already exist under "zh-hans", they can be copied to the new custom language "cn". After copying, the "zh-hans" language can be deleted. For copying translations, we referred to our manual translation guide: Using Different Translation Editors for Different Pages.

Important note!
If there is a subfolder in the WordPress installation with the same name as the custom language code, it will cause issues. We warned against having a subfolder named the same as any of WPML's language codes, as detailed in our guide: Language URL options - Common Mistakes.

If this solution doesn't look relevant, 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.

This topic contains 3 replies, has 2 voices.

Last updated by Itamar 1 year, 4 months ago.

Assisted by: Itamar.

Author Posts
January 28, 2024 at 4:08 pm #15234470

boz-3

I try to change the default directory name through the below steps:
open WPML/Languages/Edit Languages

but the code cant be changed.

3332.png
January 28, 2024 at 4:29 pm #15234493

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

The language's code cannot be changed. There is a good reason for this.

May I ask why you want to change the language's code?

In any case, you can create a custom language and set its code in its creation. You can read about it here.

https://wpml.org/documentation/getting-started-guide/language-setup/editing-wpmls-languages-table/

If you need further help with this issue please share your site's Debug information. You can read about it here.

http://wpml.org/faq/provide-debug-information-faster-support/

Regards,
Itamar.

January 29, 2024 at 2:29 am #15235142

boz-3

Our website's main language is English.
I translated pages to Chinese manually with the language directory name "cn" a week ago, and then I installed the WPML plugin and translated pages to Russia, Korea, and Japan. then I encountered a big problem: I couldn't add Chinese to the Language switcher.

so, In order to add Chinese to the language switcher, I have to retranslate pages to Chinese with WPML. I want to replace the Chinese pages translated manually before. but I don't want to change the URL ( the Chinese language's directory is "zh-hans", but I need it to be "cn"). That's why I want to change the language's code.

The problem is :
how do change the Chinese language's Code to generate pages that have the same URL as pages manually before)?

or

How to add the custom link to the language switcher?

January 29, 2024 at 9:11 am #15236727

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

Let me please start with your last question. You asked, "How do you add the custom link to the language switcher?"

For this, you will need to create a custom Language Switcher. Please read our following guide on creating a custom Language Switcher.

https://wpml.org/documentation/getting-started-guide/language-setup/language-switcher-options/custom-language-switcher/

You will need to add the custom link with PHP. Specifically, please check this part of the guide.

https://wpml.org/documentation/getting-started-guide/language-setup/language-switcher-options/custom-language-switcher/#the-php-part

Please note that you need to develop a PHP solution to add the link because custom coding is out of the scope of our support forum.

You asked: "how do change the Chinese language's Code to generate pages that have the same URL as pages manually before)?"

As I already explained, you need to create a custom language and add "cn" as its language code. The explanations about adding a custom language can be found here.

https://wpml.org/documentation/getting-started-guide/language-setup/editing-wpmls-languages-table/#adding-your-own-languages-using-wpmls-gui

If you already have the translation under the Chinese language with the language code "zh-hans", you will be able to copy them from the "zh-hans" language to the "cn" language. Afterward, you will be able to delete the "zh-hans" language. To copy the translations, please see our manual translation guide.

https://wpml.org/documentation/translating-your-contents/using-different-translation-editors-for-different-pages/


Important note!

If you are creating a custom language with the language code "cn" and also in your WordPress installation, you have a subfolder named "cn," things will not work. You must not have a subfolder named the same as the language code of one of your WPML's languages. We mention this in our guide here.

https://wpml.org/documentation/getting-started-guide/language-setup/language-url-options/#common-mistakes

Regards,
Itamar.