WPML
Required plugins for our base:
- WPML Multilingual CMS
- ACFML
- String Translation (required for page builders)
Optional:
- Gravity Forms Multilingual
- WPML SEO
ACF
To declare on an ACF field its translation status, use the field wpml_cf_preferences, values below:
0— Don’t translate. WPML ignores the field entirely.1— Copy. The field value is copied to all languages and stays in sync.2— Translate. The field value is made available for translation.3— Copy once. The field value is copied to all languages once, after which it can be edited in each language independently.
On groups and repeaters, use 1. Link fields can use 1 without also translating the URL.
General WPML Knowledge:
- There is a custom filter in the base theme for custom block string validation. This was done as the current WPML implementation struggles with deep group/repeaters and can make mistakes if fields have the same name (which occurs with our component based setup).
- Global Block works as expected, and should be encouraged over patterns for “global” information. Patterns can still be used for templating, but if its storing actual words, and needs to switch with the language, use Global Blocks.
- General workflow would be to have dev finished and have the translation preferences all set. You might run into a case where you’ve changed a preference but the Advanced Translation Editor doesn’t pick up on it. Update the post, this will signal for WPML to re-run the string validation.
- When working with REST API, ensure the base URL requested has the language folder attached to it i.e. French -> /fr/
- When working with Ajax, the WPML language cookie doesn’t work with cookie banners, and is generally unreliable. Suggested solution is to have the current language set via a localised script, and pass that through to the ajax request. Then use the global $sitepress to programatically switch language in the ajax request.
- When fetching a post ID (relationship/post object fields/shortcodes) in blocks, the post ID needs to be wrapped in the below filter to correctly get the translated post (ticket with more info)
-
apply_filters('wpml_object_id', $postId, $postType, true)
-