
开发者测试调试工具Xdebug安装及集成使用教程
load_theme_textdomain ( $domain, $path = false )
load_theme_textdomain: 这是WordPress中的一个函数,用于加载一个主题的翻译文件。你可以使用这个函数来翻译你的主题的模板文件和其他PHP代码中的字符串。
加载主题的翻译字符串。
如果当前的locale在主题的根目录下以.mo文件的形式存在,它将被$domain包含在翻译后的字符串中。
.mo文件必须完全根据locale来命名。
function load_theme_textdomain( $domain, $path = false ) { /** @var WP_Textdomain_Registry $wp_textdomain_registry */ global $wp_textdomain_registry; /** * Filters 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', determine_locale(), $domain ); $mofile = $domain . '-' . $locale . '.mo'; // Try to load from the languages directory first. if ( load_textdomain( $domain, WP_LANG_DIR . '/themes/' . $mofile, $locale ) ) { return true; } if ( ! $path ) { $path = get_template_directory(); } $wp_textdomain_registry->set_custom_path( $domain, $path ); return load_textdomain( $domain, $path . '/' . $locale . '.mo', $locale ); }