WP Manifestindependent plugin directory
manifest / i18n / cl-wpml-original-language

CL WPML Original Language

Companion plugin for WPML. Lists translatable content grouped by translation group (trid), shows the original language with its flag, and allows swapping which language is the original. Cancels pending translation jobs, keeps an audit log and creates a downloadable backup before every change.

by Carlos Longarela · github.com/carloslongarela/cl-wpml-original-language · website

0stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/carloslongarela/cl-wpml-original-language/archive/refs/heads/main.zip

Readme

CL WPML Original Language

Companion plugin for WPML that adds an Original Language page under the WPML admin menu (fallback: Tools) to inspect and change which language is the original of each translation group.

Features

  • Post type selector listing every translatable post type that has rows in icl_translations.
  • Table grouped by trid: original content (title, status, IDs), original language with its flag, and all its translations with status.
  • Change the original language of a group: per-row dropdown + button, or bulk action on selected rows.
  • Per-document translation editor selector: WPML default / WPML Translation Editor (ATE) / native WordPress editor.
  • Downloadable JSON backup of every affected row before each change.
  • Audit log tab (custom table {prefix}cl_wpml_ol_log): date, user, action, language change, details and backup download.
  • Search by title, filter by original language, pagination.

How the swap works (critical part)

For the selected trid in {prefix}icl_translations, inside a transaction:

  1. The row of the new original language gets source_language_code = NULL.
  2. Every other row of the group gets source_language_code = <new original code>.
  3. Pending Translation Management jobs of the group are cancelled by deleting the related rows from icl_translation_status, icl_translate_job and icl_translate (each table is checked for existence first). WPML will create fresh jobs on demand in the new direction.

If any query fails, everything is rolled back and nothing is logged as changed.

Backup and restore

Before touching the database, the plugin serializes the affected rows from icl_translations and the three TM tables into a JSON document stored in the audit log (downloadable from the Audit log tab). To restore manually, re-insert/update those rows from the JSON with your favorite tool (WP-CLI db query, Adminer, etc.). Always keep a full database backup as well.

Cache clearing

After every change the plugin:

  • Runs clean_post_cache() for every affected post.
  • Deletes icl_* / wpml_* transients.
  • Calls icl_cache_clear() when available.
  • Flushes the object cache (wp_cache_flush() — covers Redis/Memcached).
  • Fires do_action( 'cl_wpml_ol_caches_cleared', $post_ids ) so you can hook page-cache purges (Nginx FastCGI, LiteSpeed, Cloudflare...). Example:
add_action( 'cl_wpml_ol_caches_cleared', function ( $post_ids ) {
    if ( function_exists( 'do_action' ) && has_action( 'litespeed_purge_all' ) ) {
        do_action( 'litespeed_purge_all' );
    }
} );

Translation editor selector

The per-document editor uses the WPML post meta _wpml_post_translation_editor_native (yes = native WordPress editor, no = WPML Translation Editor, absent = WPML default). The meta is applied to all posts of the group. This key is what WPML Translation Management uses internally, but it is not part of the public API and may change between WPML versions — verify against your installed version.

Important warnings

  • Test on staging first. The swap writes directly to WPML tables; this is intentional (WPML has no public API to reverse translation direction) but it is a critical change.
  • Cancelling jobs removes their history in Translation Management for the affected groups. Existing content is never touched — only WPML metadata and TM job rows.
  • The Advanced Translation Editor memory for the affected documents restarts in the new direction.
  • Requires WPML active (ICL_SITEPRESS_VERSION); TM tables are optional and detected at runtime.
  • Capability required: manage_options.

Requirements

  • WordPress 6.0+
  • PHP 7.4+
  • WPML (sitepress-multilingual-cms)

Translations

All strings use the cl-wpml-original-language text domain and are loaded from /languages. Included: es_ES (Spanish). The .pot template is at languages/cl-wpml-original-language.pot; add new .po/.mo files there for other locales.

Read the full README on GitHub →