加载插件的翻译字符串。
原型
load_plugin_textdomain( string $domain, string $deprecated = false, string $plugin_rel_path = false )
描述
如果没有给出路径,那么它将是插件目录的根目录。
参数
$domain
(string)
(Required)
用于检索已翻译字符串的唯一标识符
$deprecated
(string)
(Optional)
请改用$ plugin_rel_path参数。
$plugin_rel_path
(string)
(Optional)
.mo文件所在的WP_PLUGIN_DIR的相对路径。
返回值
(bool)
成功加载textdomain时为true,否则为false。
源文件
路径:wp-includes/l10n.php
<?php
...
function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) {
/**
* Filters a plugin's locale.
*
* @since 3.0.0
*
* @param string $locale The plugin's current locale.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
*/
$locale = apply_filters( 'plugin_locale', determine_locale(), $domain );
$mofile = $domain . '-' . $locale . '.mo';
// Try to load from the languages directory first.
if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) {
return true;
}
if ( false !== $plugin_rel_path ) {
$path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );
} elseif ( false !== $deprecated ) {
_deprecated_argument( __FUNCTION__, '2.7.0' );
$path = ABSPATH . trim( $deprecated, '/' );
} else {
$path = WP_PLUGIN_DIR;
}
return load_textdomain( $domain, $path . '/' . $mofile );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/load_plugin_textdomain/