WordPress函数:load_plugin_textdomain(插件本地化)

描述

加载翻译后的插件字符串。

如果未给出路径,默认路径为插件根目录。.mo文件路径基于带有破折号的域名命名,域名后应跟有一个破折号,破折号后为本地语言简码。 这里的本地语言简码是指你在wp-config.php中填写的 WPLANG 的值,比如你填写的是 zh_CN ,那么就该使用 zh_CN,如果你的插件的 text domain 为 “my-plugin”,那么语言包的名字应该为 “my-plugin-zh_CN.mo”和 “my-plugin-zh_CN.po”。

用法

&lt;?php <a href="https://www.wpdaxue.com/tag/load_plugin_textdomain" title="查看与【load_plugin_textdomain】相关的文章" target="_blank" rel="noopener">load_plugin_textdomain</a>( $domain, $abs_rel_path, $plugin_rel_path ) ?&gt;

参数

$domain

(字符串)(必需)用以检索被翻译字符串的唯一标识符

默认值:None

$abs_rel_path

(字符串)(可选).mo文件所在文件夹的ABSPATH的相对路径。该参数已弃用,但在WP 2.7前仍然有效。

默认值:false

$plugin_rel_path

(字符串)(可选)WP_PLUGIN_DIR的相对路径。推荐使用该参数,其优先级高于$abs_rel_path。

默认值:false

返回的值

(空)

该函数不返回任何值

例子

function myplugin_init() {
  <a href="https://www.wpdaxue.com/tag/load_plugin_textdomain" title="查看与【load_plugin_textdomain】相关的文章" target="_blank" rel="noopener">load_plugin_textdomain</a>( 'my-plugin', false, dirname( plugin_basename( __FILE__ ) ) ); 
}
add_action('plugins_loaded', 'myplugin_init');

或者你打算将语言包放在一个子文件夹 languages :

load_plugin_textdomain( 'my-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );

注释

l10n是localization的缩写形式

函数历史

始见于1.5.0版本

2.7.0 版本以后,$abs_rel_path 参数被弃用!

源文件

load_plugin_textdomain() 位于 wp-includes/110n.php中。

来源:

https://www.wpdaxue.com/load_plugin_textdomain.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32297.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?