wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_get_installed_translations › WordPress Function

Seit3.7.0
Veraltetn/v
wp_get_installed_translations ( $type )
Parameter:
  • (string) $type What to search for. Accepts 'plugins', 'themes', 'core'.
    Erforderlich: Ja
Gibt zurück:
  • (array) Array of language data.
Definiert in:
Codex:

Gets installed translations.

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


Quellcode

function wp_get_installed_translations( $type ) {
	global $wp_textdomain_registry;

	if ( 'themes' !== $type && 'plugins' !== $type && 'core' !== $type ) {
		return array();
	}

	$dir = 'core' === $type ? WP_LANG_DIR : WP_LANG_DIR . "/$type";

	if ( ! is_dir( $dir ) ) {
		return array();
	}

	$files = $wp_textdomain_registry->get_language_files_from_path( $dir );
	if ( ! $files ) {
		return array();
	}

	$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;
}