wp_get_installed_translations

函数
wp_get_installed_translations ( $type )
参数
  • (string) $type What to search for. Accepts 'plugins', 'themes', 'core'.
    Required:
返回值
  • (array) Array of language data.
定义位置
相关方法
wp_get_available_translationswp_set_script_translationswp_get_translation_updates_get_path_to_translationwp_get_all_sessions
引入
3.7.0
弃用
-

wp_get_installed_translations: 这个函数返回一个当前安装在WordPress中的翻译数组。翻译以MO文件数组的形式返回,这些文件位于wp-content/languages目录中。

获取已安装的翻译。

在wp-content/languages目录中查找插件或主题的翻译。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_get_installed_translations( $type ) {
if ( 'themes' !== $type && 'plugins' !== $type && 'core' !== $type ) {
return array();
}
$dir = 'core' === $type ? '' : "/$type";
if ( ! is_dir( WP_LANG_DIR ) ) {
return array();
}
if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) ) {
return array();
}
$files = scandir( WP_LANG_DIR . $dir );
if ( ! $files ) {
return array();
}
$language_data = array();
foreach ( $files as $file ) {
if ( '.' === $file[0] || is_dir( WP_LANG_DIR . "$dir/$file" ) ) {
continue;
}
if ( substr( $file, -3 ) !== '.po' ) {
continue;
}
if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match ) ) {
continue;
}
if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files, true ) ) {
continue;
}
list( , $textdomain, $language ) = $match;
if ( '' === $textdomain ) {
$textdomain = 'default';
}
$language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( WP_LANG_DIR . "$dir/$file" );
}
return $language_data;
}
function wp_get_installed_translations( $type ) { if ( 'themes' !== $type && 'plugins' !== $type && 'core' !== $type ) { return array(); } $dir = 'core' === $type ? '' : "/$type"; if ( ! is_dir( WP_LANG_DIR ) ) { return array(); } if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) ) { return array(); } $files = scandir( WP_LANG_DIR . $dir ); if ( ! $files ) { return array(); } $language_data = array(); foreach ( $files as $file ) { if ( '.' === $file[0] || is_dir( WP_LANG_DIR . "$dir/$file" ) ) { continue; } if ( substr( $file, -3 ) !== '.po' ) { continue; } if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match ) ) { continue; } if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files, true ) ) { continue; } list( , $textdomain, $language ) = $match; if ( '' === $textdomain ) { $textdomain = 'default'; } $language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( WP_LANG_DIR . "$dir/$file" ); } return $language_data; }
function wp_get_installed_translations( $type ) {
	if ( 'themes' !== $type && 'plugins' !== $type && 'core' !== $type ) {
		return array();
	}

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

	if ( ! is_dir( WP_LANG_DIR ) ) {
		return array();
	}

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

	$files = scandir( WP_LANG_DIR . $dir );
	if ( ! $files ) {
		return array();
	}

	$language_data = array();

	foreach ( $files as $file ) {
		if ( '.' === $file[0] || is_dir( WP_LANG_DIR . "$dir/$file" ) ) {
			continue;
		}
		if ( substr( $file, -3 ) !== '.po' ) {
			continue;
		}
		if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match ) ) {
			continue;
		}
		if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files, true ) ) {
			continue;
		}

		list( , $textdomain, $language ) = $match;
		if ( '' === $textdomain ) {
			$textdomain = 'default';
		}
		$language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( WP_LANG_DIR . "$dir/$file" );
	}
	return $language_data;
}

常见问题

FAQs
查看更多 >