wp_get_installed_translations( string $type ): array

In this article

Gets installed translations.

Description

Looks in the wp-content/languages directory for translations of plugins or themes.

Parameters

$typestringrequired
What to search for. Accepts 'plugins', 'themes', 'core'.

Return

array Array of language data.

Source


	$language_data = array();

	foreach ( $files as $file ) {
		if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?)\.(?:mo|l10n\.php)/', basename( $file ), $match ) ) {
			continue;
		}

		list( , $textdomain, $language ) = $match;
		if ( '' === $textdomain ) {
			$textdomain = 'default';
		}

		if ( str_ends_with( $file, '.mo' ) ) {
			$pofile = substr_replace( $file, '.po', - strlen( '.mo' ) );

			if ( ! file_exists( $pofile ) ) {
				continue;
			}

			$language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( $pofile );
		} else {
			$pofile = substr_replace( $file, '.po', - strlen( '.l10n.php' ) );

			// If both a PO and a PHP file exist, prefer the PO file.
			if ( file_exists( $pofile ) ) {
				continue;
			}

			$language_data[ $textdomain ][ $language ] = wp_get_l10n_php_file_data( $file );
		}
	}
	return $language_data;
}

/**
 * Extracts headers from a PO file.
 *
 * @since 3.7.0
 *
 * @param string $po_file Path to PO file.
 * @return string[] Array of PO file header values keyed by header name.
 */
function wp_get_pomo_file_data( $po_file ) {
	$headers = get_file_data(
		$po_file,
		array(
			'POT-Creation-Date'  => '"POT-Creation-Date',
			'PO-Revision-Date'   => '"PO-Revision-Date',
			'Project-Id-Version' => '"Project-Id-Version',
			'X-Generator'        => '"X-Generator',

Changelog

VersionDescription
3.7.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.