JCI and WPML
The WPML-Plugin gives an excellent way to have a multi-language WordPress-Website. It offers several ways to do this.
On the other hand, APIs can provide data and content in different languages. Some need a …?lang=en in the API-URL and additional info in headers.
JCI and WPML can work together in this way:
Licensing
If you set up a multisite-Wordpress, one network site is DOMAIN/de, and another is DOMAIN/en, you usually need two JCI licenses. But if WPML is in use, you only need one JCI license.
Asking the API
Depending on the language, you want to ask the API. For that, you need to know what language a page has. WPML “knows” that, and then JCI too.
The twig-function wp_get_page_properties gives us all info about a page.
You can use it in the twig-content-template and the HTTP-request (URL & header).
An example code snippet:
{# get all page properties #} {% set pprop = wp_get_page_properties() %} {# in case wpml is active #} wpml: {{pprop.wpml.lang}}<br> {% if pprop.wpml.lang=="de" %} DE {% else %} EN {% endif %}
Twig functions for handling WPML settings of a page
jci_wpml_element_language_details(pageid, cpt="post")
Get the WPML-Settings of the Page with PageID and (optional CustomPostType)
Return: JSONwith WPML-Info or errormessages
jci_wpml_set_element_language_details(pageid_original, page_id_translation, cpt="post", set_langcode_original="", set_langcode_translation="", docheck=FALSE, debug=FALSE)
When you create CustomPostPages out of JSON with a JCI-twig-Template, you get on multi-language sites one page for language A (pageid_original) and another page (page_id_translation) for language B.
jci_wpml_set_element_language_details(…) connects these two pages as the translation of each other using the WPML-Hook wpml_set_element_language_details.
‘docheck=TRUE’ tells the JCI-Plugin to check if the pages are connected.