Print

JCI and WPML

The WPML-Plugin gives a good way to have a multilanguage 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, some other info in headers.

JCI and WPML can work together in this way:

Licencing

If you set up a multisite-Wordpress and one network-site is DOMAIN/de and another network-site is DOMAIN/de you normally need two JCI-licences. But if WPML is in use you only need one JCI-licence.

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 the in the twig-content-template and the http-request (URL & header).

A 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 translation of each other by using the WPML-Hook wpml_set_element_language_details.
‘docheck=TRUE’ tells the JCI-Plugin to check if the pages are really connected.

Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.
On this page: