load_plugin_textdomain()
load_plugin_textdomain( string $domain, string|false $d…
load_plugin_textdomain( string $domain, string|false $deprecated = false, string|false $plugin_rel_path = false )
加载插件的翻译字符串。
Loads a plugin’s translated strings.
加载插件的翻译字符串。
Loads a plugin’s translated strings.
目录锚点:#说明#参数#返回#源码#笔记
说明(Description)
如果没有给出路径,那么它将是插件目录的根目录。
.mo文件的命名应该基于带破折号的文本域,然后是准确的区域设置。
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| $domain | (string) | 必需 | 检索转换字符串的唯一标识符 |
| $deprecated | (string | false) | 可选 | 已弃用。改用$plugin_rel_path参数。 |
| $plugin_rel_path | (string | false) | 可选 | 指向.mo文件所在的WP_PLUGIN_DIR的相对路径。 |
返回(Return)
(bool)成功加载textdomain时为True,否则为false。
源码(Source)
/**
* Load a plugin's translated strings.
*
* If the path is not given then it will be the root of the plugin directory.
*
* The .mo file should be named based on the text domain with a dash, and then the locale exactly.
*
* @since 1.5.0
*
* @param string $domain Unique identifier for retrieving translated strings
* @param string $deprecated Use the $plugin_rel_path parameter instead.
* @param string $plugin_rel_path Optional. Relative path to WP_PLUGIN_DIR where the .mo file resides.
* Default false.
* @return bool True when textdomain is successfully loaded, false otherwise.
*/
function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) {
$locale = get_locale();
/**
* Filter 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', $locale, $domain );
if ( false !== $plugin_rel_path ) {
$path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );
} elseif ( false !== $deprecated ) {
_deprecated_argument( __FUNCTION__, '2.7' );
$path = ABSPATH . trim( $deprecated, '/' );
} else {
$path = WP_PLUGIN_DIR;
}
// Load the textdomain according to the plugin first
$mofile = $domain . '-' . $locale . '.mo';
if ( $loaded = load_textdomain( $domain, $path . '/'. $mofile ) )
return $loaded;
// Otherwise, load from the languages directory
$mofile = WP_LANG_DIR . '/plugins/' . $mofile;
return load_textdomain( $domain, $mofile );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 4.6.0 | wp-includes/l10n.php:797 | 1 function | 5 |
笔记(Notes)
加载插件翻译不应该在plugins_loaded操作期间完成,因为这太早了,并且会阻止其他与语言相关的插件正确地连接到load_textdomain()函数并执行它们想执行的任何操作。
只是个便条,
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!