When you install WPML, you get over 60 pre-configured languages, ready to use. You can edit this table via WPML’s GUI and add your own custom languages.
Adding your own languages using WPML’s GUI
See the instructions in the following video, or read the details underneath it.
Go to WPML->Languages and click on the ‘Edit languages’ link.
You will see a list of the languages in your site. It will look like the following screenshot, but with your site’s languages.
Click on the ‘Add languages’ button to add your custom language. A new row will appear, looking like this one:
The language you add needs the following pieces of information:
- Language name – the name you want to see in WPML’s GUI
- Code – the name for this language in the database. Once you set this value and add content, you should never change it, or content language will be lost. This value will be used for the language URLs. For example,
http://wpml.org/es-mx/, http://wpml.org/?lang=es-mx, http://es-mx.wpml.org.
- Translation (language) – The way this language will display when the site displays another language
- Flag – an image file with the country flag. WPML will use it in language switchers.
- Default locale – the locale that will be active for this language, for loading GetText translations.
- Encode URLs – yes/no, determines if URLs in this language are encoded or use ASCII characters (leave ‘no’ if you are not sure).
- Language tag – the code Google expects for this language. The language tag should contain the same information as the locale name, but in a slightly different format. If the locale for Canadian French is fr_CA, the corresponding language tag would be fr-ca. Instead of an underscore, use a dash and all letters should be lowercase.
When you save a language, some validation messages may display. Make sure you see a confirmation message and no error messages. For example, you cannot add a new language with a code of an existing language in WPML’s table.
Editing languages directly in the database
WPML’s language information is kept in two tables:
- wp_icl_languages – lists languages
- wp_icl_languages_translations – lists language name translations
If you are manipulating the languages information, make sure that the code of the language you are adding to the database is not already used in these tables.
the columns are pretty much self-explanatory:
- code – will be the language key (used in the URLs and everything else)
- major – means that the language will be displayed at the top in the language selection panel
- active – means that the language is selected as an active language or not
- default_locale – locale name to be used in case the user doesn’t specify one explicitly
Each row represents a language.
This table includes language name translations, so that WPML can display the language name, in the language switcher, in the correct language.
- language_code – the language we’re referencing
- display_language_code – language that the name of the ‘language_code’ is in
- name – name for ‘language_code’ in the ‘display_language_code’ language
There should be a row for each combination of language_code / display_language_code for the active languages (including translations of every language to itself).
For every new language added translations of the respective language into the active languages, translations of the active languages into the newly added language and a translation of the new language into the new language need to be added to wp_icl_languages_translations.
Indicates which image to return for the language flag.
- lang_code – language for which the flag is
- flag – name of the flag image file
- from_template – set to 1 means that the file will be loaded from the images/flags folder in the theme folder (otherwise loaded from the plugin flags folder).
There should be one entry per language.
Note 1: after adding records in these tables saving the languages list would be recommended.
Note 2: clearing the WPML’s internal cache for languages is also recommended. To do this you need to delete the record from wp_options corresponding to option_name=’_icl_cache’ .
To keep these customizations upon upgrading the plugin add the following piece of code to either wp-config.php or to your functions.php file in the theme folder: