返回介绍

load_child_theme_textdomain()

发布于 2017-09-11 01:40:17 字数 3725 浏览 836 评论 0 收藏 0

load_child_theme_textdomain( string $domain,  string $path = false )

Load the child themes translated strings.


description

If the current locale exists as a .mo file in the child themes root directory, it will be included in the translated strings by the $domain.

The .mo files must be named based on the locale exactly.


参数

$domain

(string) (Required) Text domain. Unique identifier for retrieving translated strings.

$path

(string) (Optional) Path to the directory containing the .mo file.

Default value: false


返回值

(bool) True when the theme textdomain is successfully loaded, false otherwise.


源代码

File: wp-includes/l10n.php

function load_child_theme_textdomain( $domain, $path = false ) {
	if ( ! $path )
		$path = get_stylesheet_directory();
	return load_theme_textdomain( $domain, $path );
}

更新日志

Versiondescription
2.9.0Introduced.

More Information

Internationalization and localization (other common spellings are internationalisation and localisation) are means of adapting computer software to different languages.

  • l10n is an abbreviation for localization.
  • i18n 18 stands for the number of letters between the first i and last n in internationalization.

相关函数

Uses

  • wp-includes/theme.php: get_stylesheet_directory()
  • wp-includes/l10n.php: load_theme_textdomain()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 5You must log in to vote on the helpfulness of this note Contributed by Drew Jaynes

    The load_child_theme_textdomain() function should generally be called from within the after_setup_theme action hook, just the same as with its 相关函数 load_theme_textdomain() function.

    
    /**
     * Loads the child theme textdomain.
     */
    function wpdocs_child_theme_setup() {
        load_child_theme_textdomain( 'my_parent_theme', get_stylesheet_directory() . '/languages' );
    }
    add_action( 'after_setup_theme', 'wpdocs_child_theme_setup' );
    

    ‘my_parent_theme’ = The name of the Main theme

    The .mo files must use language-only filenames, like languages/de_DE.mo in your child theme directory.

    Unlike plugin language files, a name like my_child_theme-de_DE.mo will NOT work. Although plugin language files allow you to specify the text-domain in the filename, this will NOT work with themes and child themes. Language files for themes should include the language shortcut ONLY.

  2. Might be useful for beginners to also know that in the note above
    ‘wpdocs_child_theme_setup’ = The name of your child theme,
    hence that needs to be changed in line 4 and line 7 in the code snippet shown above.
    And in that same example the .mo and .po files are not uploaded to the child-theme root, but to a folder named languages inside the child-folder.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文