translate_user_role() - WordPress 函数参考中文文档

返回介绍

translate_user_role()

发布于 2017-09-11 字数2714 浏览 908 评论 0

translate_user_role( string $name )

Translates role name.


描述

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' );
}

更新日志

Version 描述
2.8.0 Introduced.

相关函数

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!