返回介绍

translate_user_role()

发布于 2017-09-11 10:42:31 字数 2709 浏览 1060 评论 0 收藏 0

translate_user_role( string $name )

Translates role name.


description

Since the role names are in the database and not in the 源代码 there are dummy gettext calls to get them into the POT file and this function properly translates them back.

The before_last_bar() call is needed, because older installs keep the roles using the old context format: ‘Role name|User role’ and just skipping the content after the last bar is easier than fixing them in the DB. New installs won’t suffer from that problem.


参数

$name

(string) (Required) The role name.


返回值

(string) Translated role name on success, original name on failure.


源代码

File: wp-includes/l10n.php

function translate_user_role( $name ) {
	return translate_with_gettext_context( before_last_bar($name), 'User role' );
}

更新日志

Versiondescription
2.8.0Introduced.

相关函数

Uses

  • wp-includes/l10n.php: translate_with_gettext_context()
  • wp-includes/l10n.php: before_last_bar()

Used By

  • wp-admin/includes/class-wp-users-list-table.php: WP_Users_List_Table::get_role_list()
  • wp-admin/includes/template.php: wp_dropdown_roles()
  • wp-admin/includes/class-wp-users-list-table.php: WP_Users_List_Table::get_views()
  • wp-admin/includes/user.php: admin_created_user_email()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Jory Hogeveen

    Please note that `translate_user_role` doesn’t work in the front-end currently.

    Here is a workaround, you can place this in your theme:

    add_action( 'init', 'load_admin_textdomain_in_front' )
    function load_admin_textdomain_in_front() {
        if ( ! is_admin() ) {
            load_textdomain( 'default', WP_LANG_DIR . '/admin-' . get_locale() . '.mo' );
        }
    }

    @see: https://core.trac.wordpress.org/ticket/37539

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

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

发布评论

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