Polylang > Support > Developers > How to translate emails?

How to translate emails?

Polylang Pro

Polylang

Polylang for WooCommerce

Since the version 4.7, WordPress introduced the function switch_to_locale(). This function unloads all translations in the previous locale and loads the translations of WordPress in the new locale passed as argument. WordPress uses this function to send emails in the user language, for example, the new user notification email. Once the email is sent, the previous locale is restored with restore_previous_locale().

It’s however important to know that these functions don’t load the theme or plugins translations. This is why the plugins and themes need to load their own translations with load_plugin_textdomain() or load_theme_textdomain(). This should be done just after the call to switch_to_locale(). Alternatively, it’s possible to hook to the action change_locale fired each time switch_to_locale() and restore_previous_locale().

See also the post about locale switching on Make WordPress Core.