获取当前语言环境的languages目录中的转换文件的路径。
原型
_get_path_to_translation_from_lang_dir( string $domain )
描述
保存可用.mo文件的缓存列表以提高性能。
参考:
- _get_path_to_translation()
参数
$domain
(string)
(Required)
文字域名。用于检索已翻译字符串的唯一标识符
返回值
(string|false)
转换文件的路径,如果未找到转换文件,则为false。
源文件
路径:wp-includes/l10n.php
<?php
...
function _get_path_to_translation_from_lang_dir( $domain ) {
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 ) ) {
return $path;
}
$path = WP_LANG_DIR . '/themes/' . $mofile;
if ( in_array( $path, $cached_mofiles ) ) {
return $path;
}
return false;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/_get_path_to_translation_from_lang_dir/