Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Email Languages

Jonathan Moore edited this page Jun 29, 2020 · 3 revisions

Emails and translation is a more complex than it looks: both to determine the right language and to ensure that everything in the email is translated.

This article considers historic deficiencies and intrinsic limitations in the plugin and includes important notes to developers looking for maximum translation compatibility.

Multiple current languages - which language should the email be sent in?

3 Translation Mechanisms - how to translate everything?

As per Translation Overview there are three different types of translations:

  1. WordPress translation mechanism: this uses language files for WordPress and each plugin, each language containing dictionaries of texts used for each plugin. The core framework takes care of downloading the files for each language, and additionally the translations can be customised by adding custom language files, typically using Loco Translate. However to switch languages fully (to send emails in a different language) it is necessary to unload previously loaded language files and re-load new language version of the files. This plugin will only unload language files for WooCommerce so if additional plugins are adding text to emails, for compatibility they should hook the language switching actions provided by this plugin as per the illustration below for woo-advanced-shipment-tracking:
/*
 * when switching language for order email, unload these additional text domains
 */
function my_unload_email_textdomains() {
	unload_textdomain( 'woo-advanced-shipment-tracking' );
}

add_action( 'woo-poly.Emails.switchLanguage', 'my_unload_email_textdomains' );
/*
 * when switching language for order email, reload these additional text domains
 */
function my_load_email_textdomains() {
	global $WC_advanced_Shipment_Tracking;
	if ( $WC_advanced_Shipment_Tracking ) {
		$WC_advanced_Shipment_Tracking->wst_load_textdomain();
	}
}

add_action( 'woo-poly.Emails.afterSwitchLanguage', 'my_load_email_textdomains' );
Clone this wiki locally