Skip Navigation

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

Problem:
You are trying to change the language code of Portuguese (Portugal) from "pt-pt" to "pt" and use it in your site's URL. You encountered issues because the default locale "pt_PT" already exists in WPML's database, preventing you from using "pt" as a custom language code.
Solution:
To achieve your goal, you need to create a new custom language in WPML. However, you cannot directly change the language code for active languages or use a default locale that already exists in WPML's database. Here are the steps you should follow:
1. Access WPML > Languages > Edit Languages to attempt adding a new custom language. Learn more about editing languages
2. Since "pt_PT" already exists, you will need to connect to your database and rename the default locale "pt_PT" in the wp_icl_languages table to something else. This action will allow you to use "pt_PT" as the default locale for your new custom language with the code "pt".
3. Be cautious with direct database modifications as they can affect the connection between original contents and their translations.

Please note that this solution might be outdated or not applicable to your specific case. If this solution does not resolve your issue, we highly recommend checking related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If needed, do not hesitate to 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 4 replies, has 2 voices.

Last updated by luisT-15 2 years, 4 months ago.

Assisted by: Andreas W..

Author Posts
January 31, 2023 at 8:03 pm #12933235

luisT-15

Tell us what you are trying to do?
I'm trying to change the code of the Portuguese (Portugal) from "pt-pt" to "pt".

Is there any documentation that you are following?
I've found the ticket below, but I don't know where to put the code:
https://wpml.org/forums/topic/change-language-code-3/#post-2620877
I'm using the menu language switcher. I also tried to create a custom language to use the "pt" code but don't allow me to use the "pt_PT" because already exists.

Can someone please help me?
I'm a new customer, I installed the plugin today 🙂

Thank you in advance.

January 31, 2023 at 8:10 pm #12933247

Andreas W.
WPML Supporter since 12/2018

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

Timezone: America/Lima (GMT-05:00)

Hello,

First, you will in fact need to create a custom language for a custom language code and you should never change this code inside the DB for existing languages, as it would destroy the connection between original contents and their translations.

Further, you can not use language settings (Default locale, hreflang) for custom language if those values already exist on the table wp_icl_languages, and although I can not suggest that you edit this table directly inside the DB; I have to admin, that altering the table might be the only way to achieve your goal.

This means if you alter the default value "pt_PT" on the table wp_icl_languages into something else, then you technically could use it for your custom language.

WPML Tables:
https://wpml.org/documentation/support/wpml-tables/

Best regards
Andreas

January 31, 2023 at 8:23 pm #12933271

luisT-15

Hello Andreas,

Thank you for your fast response.
My English is not perfect, let me try to explain to confirm if I understood.

you said that I should never change the code inside the DB for existing languages.
But at the same time, you're suggesting changing the default value "pt_PT" to something else so I can create a custom language code using the default locale "pt_PT" in this new custom language? Is it safe to change it? So I can use the domain.com/pt for Portuguese language?

Thank you 🙂

February 1, 2023 at 2:50 pm #12939305

Andreas W.
WPML Supporter since 12/2018

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

Timezone: America/Lima (GMT-05:00)

Hello,

Languages have:

name: English
language code: en
default locale: en_GB
hreflang: en-gb

Language code means in this case what appears inside the URL of the site like here "en".

As you can see on WPML > Languages > Edit languages you are not able to change this code for active languages.

The only thing you can do, in order to use for example "pt" in your site URL, is create a new custom language.

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

Now, apart from this language code, you can change any further values, like hreflang or default locale, but you can not use a value that already exists in WPML by default.

https://wpml.org/documentation/getting-started-guide/language-setup/pre-configured-languages/

This means, that WPML has a table on the database called wp_icl_languages and this table already includes the value default locale "pt_PT" for language code "pt-pt".

The only way to use the default locale "pt_PT" with language code "pt" would be to connect to the database, and rename the default locale "pt_PT" inside wp_icl_languages to something else.

If the value will not longer already exists on the table, you will be able to use it for your new custom language.

Best regards
Andreas

February 1, 2023 at 6:59 pm #12941655

luisT-15

Hey Andreas, my issue is resolved now. Thank you very much for the detailed explanation!