加载主题的翻译字符串。
load_theme_textdomain( string $domain , string $path = false )
说明(Description)
如果当前区域设置作为.mo文件存在于主题的根目录中,则$domain会将其包含在翻译的字符串中。
.mo文件的命名必须完全基于区域设置。
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$domain | (string) | 必需 | 文本域。检索转换字符串的唯一标识符。 |
$path | (string) | 可选 | 包含.mo文件的目录的路径。 |
返回(Return)
(bool)成功加载textdomain时为True,否则为false。
源码(Source)
/**
* Load the theme's translated strings.
*
* If the current locale exists as a .mo file in the theme's root directory, it
* will be included in the translated strings by the $domain.
*
* The .mo files must be named based on the locale exactly.
*
* @since 1.5.0
*
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @param string $path Optional. Path to the directory containing the .mo file.
* Default false.
* @return bool True when textdomain is successfully loaded, false otherwise.
*/
function load_theme_textdomain( $domain, $path = false ) {
$locale = get_locale();
/**
* Filter a theme's locale.
*
* @since 3.0.0
*
* @param string $locale The theme's current locale.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
*/
$locale = apply_filters( 'theme_locale', $locale, $domain );
if ( ! $path )
$path = get_template_directory();
// Load the textdomain according to the theme
$mofile = untrailingslashit( $path ) . "/{$locale}.mo";
if ( $loaded = load_textdomain( $domain, $mofile ) )
return $loaded;
// Otherwise, load from the languages directory
$mofile = WP_LANG_DIR . "/themes/{$domain}-{$locale}.mo";
return load_textdomain( $domain, $mofile );
}
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
4.6.0 | wp-includes/l10n.php:870 | 2 | 5 |