WP_Locale_Switcher::load_translations()privateWP 4.7.0

Load translations for a given locale.

When switching to a locale, translations for this locale must be loaded from scratch.

Method of the class: WP_Locale_Switcher{}

No Hooks.

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->load_translations( $locale );
$locale(string) (required)
The locale to load translations for.

Notes

  • Global. Mo[]. $l10n An array of all currently loaded text domains.

Changelog

Since 4.7.0 Introduced.

WP_Locale_Switcher::load_translations() code WP 6.5.2

private function load_translations( $locale ) {
	global $l10n;

	$domains = $l10n ? array_keys( $l10n ) : array();

	load_default_textdomain( $locale );

	foreach ( $domains as $domain ) {
		// The default text domain is handled by `load_default_textdomain()`.
		if ( 'default' === $domain ) {
			continue;
		}

		/*
		 * Unload current text domain but allow them to be reloaded
		 * after switching back or to another locale.
		 */
		unload_textdomain( $domain, true );
		get_translations_for_domain( $domain );
	}
}