_get_path_to_translation_from_lang_dir

函式
_get_path_to_translation_from_lang_dir ( $domain )
Access
Private
引數
  • (string) $domain Text domain. Unique identifier for retrieving translated strings.
    Required:
返回值
  • (string|false) The path to the translation file or false if no translation file was found.
相關
  • _get_path_to_translation()
定義位置
相關方法
_get_path_to_translationget_translations_for_domainwp_load_translations_earlywp_get_translation_updateswp_set_script_translations
引入
4.7.0
棄用
6.1.0

_get_path_to_translation_from_lang_dir是一個WordPress函式,它返回特定文字域和語言目錄的翻譯檔案的路徑: 這個函式需要三個引數:文字域、語言目錄和翻譯檔案的副檔名。它在指定的語言目錄中搜尋翻譯檔案,如果檔案存在,則返回該檔案的路徑。

獲取當前地區語言目錄中的翻譯檔案的路徑。

儲存一個可用的.mo檔案的快取列表以提高效能。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _get_path_to_translation_from_lang_dir( $domain ) {
_deprecated_function( __FUNCTION__, '6.1.0', 'WP_Textdomain_Registry' );
static $cached_mofiles = null;
if ( null === $cached_mofiles ) {
$cached_mofiles = array();
$locations = array(
WP_LANG_DIR . '/plugins',
WP_LANG_DIR . '/themes',
);
foreach ( $locations as $location ) {
$mofiles = glob( $location . '/*.mo' );
if ( $mofiles ) {
$cached_mofiles = array_merge( $cached_mofiles, $mofiles );
}
}
}
$locale = determine_locale();
$mofile = "{$domain}-{$locale}.mo";
$path = WP_LANG_DIR . '/plugins/' . $mofile;
if ( in_array( $path, $cached_mofiles, true ) ) {
return $path;
}
$path = WP_LANG_DIR . '/themes/' . $mofile;
if ( in_array( $path, $cached_mofiles, true ) ) {
return $path;
}
return false;
}
function _get_path_to_translation_from_lang_dir( $domain ) { _deprecated_function( __FUNCTION__, '6.1.0', 'WP_Textdomain_Registry' ); static $cached_mofiles = null; if ( null === $cached_mofiles ) { $cached_mofiles = array(); $locations = array( WP_LANG_DIR . '/plugins', WP_LANG_DIR . '/themes', ); foreach ( $locations as $location ) { $mofiles = glob( $location . '/*.mo' ); if ( $mofiles ) { $cached_mofiles = array_merge( $cached_mofiles, $mofiles ); } } } $locale = determine_locale(); $mofile = "{$domain}-{$locale}.mo"; $path = WP_LANG_DIR . '/plugins/' . $mofile; if ( in_array( $path, $cached_mofiles, true ) ) { return $path; } $path = WP_LANG_DIR . '/themes/' . $mofile; if ( in_array( $path, $cached_mofiles, true ) ) { return $path; } return false; }
function _get_path_to_translation_from_lang_dir( $domain ) {
	_deprecated_function( __FUNCTION__, '6.1.0', 'WP_Textdomain_Registry' );

	static $cached_mofiles = null;

	if ( null === $cached_mofiles ) {
		$cached_mofiles = array();

		$locations = array(
			WP_LANG_DIR . '/plugins',
			WP_LANG_DIR . '/themes',
		);

		foreach ( $locations as $location ) {
			$mofiles = glob( $location . '/*.mo' );
			if ( $mofiles ) {
				$cached_mofiles = array_merge( $cached_mofiles, $mofiles );
			}
		}
	}

	$locale = determine_locale();
	$mofile = "{$domain}-{$locale}.mo";

	$path = WP_LANG_DIR . '/plugins/' . $mofile;
	if ( in_array( $path, $cached_mofiles, true ) ) {
		return $path;
	}

	$path = WP_LANG_DIR . '/themes/' . $mofile;
	if ( in_array( $path, $cached_mofiles, true ) ) {
		return $path;
	}

	return false;
}

常見問題

FAQs
檢視更多 >