Skip to content

Commit

Permalink
Apply translation to user role names
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Jul 23, 2023
1 parent e92cb5e commit 84a4304
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
13 changes: 12 additions & 1 deletion classes/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,18 @@ public static function get_user_roles() {
if ( empty( $wp_roles ) ) {
$wp_roles = new WP_Roles();
}
return $wp_roles->get_names();

$roles = $wp_roles->get_names();
$translated_roles = array();

foreach ( $roles as $name => $display_name ) {
$translated_roles[] = array(
'label' => translate_user_role( $display_name ),
'value' => $name,
);
}

return $translated_roles;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/admin/options/components/permission-user-role/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { AdminContext } from '../../../index';
export default function PermissionUserRole() {
const { options, setOptions } = useContext( AdminContext );

const allUserRoles = window.chbeObj.userRoles || {};
const userRoles = window.chbeObj.userRoles || {};

const onChange = ( role ) => {
const newPermissionRoles = options.permissionRoles.includes( role )
Expand All @@ -32,12 +32,12 @@ export default function PermissionUserRole() {
<PanelBody
title={ __( 'User roles allowed to use this extension', 'custom-html-block-extension' ) }
>
{ Object.keys( allUserRoles ).map( ( key ) => (
{ userRoles.map( ( role, index ) => (
<ToggleControl
key={ key }
label={ allUserRoles[ key ] }
checked={ options.permissionRoles.includes( key ) }
onChange={ () => onChange( key ) }
key={ index }
label={ role.label }
checked={ options.permissionRoles.includes( role.value ) }
onChange={ () => onChange( role.value ) }
/>
) ) }
</PanelBody>
Expand Down

0 comments on commit 84a4304

Please sign in to comment.