#18954-28: "anonymous user" and "authenticated user" are not translateable implies it should be possible to translate role names with i18n, however from looking at http://api.drupal.org/api/function/user_edit_form/6 and http://api.drupal.org/api/function/user_roles/6 it looks as though core actually gives no opportunity for their translation? Also the comment in user_roles() "We only translate the built in role names" is a bit ominous...

(This is in response to #301541-11: Contact form and Roles names are not translatable !)

Seems to be the same in 7.x also.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mairav’s picture

Subscribing. I hope there can be a solution to this in i18n or in core.

Jose Reyero’s picture

Status: Active » Closed (won't fix)

"it looks as though core actually gives no opportunity for their translation?"

Right

gpk’s picture

Title: Is is possible to translate user role names? » User role names cannot be translated
Project: Internationalization » Drupal core
Version: 6.x-1.x-dev » 7.x-dev
Component: Code » language system
Category: support » bug
Status: Closed (won't fix) » Active

Thanks, let's file this as a bug against core then!

In #18954-28: "anonymous user" and "authenticated user" are not translateable Gabor seems to think that it would be possible for i18n to pick up user role names and translate them. But they are never run through t(), either in http://api.drupal.org/api/function/user_roles/7 or http://api.drupal.org/api/function/user_account_form/7 hence there is no way of modifying them via the language system.

plach’s picture

Version: 7.x-dev » 8.x-dev
Category: bug » feature

There is a lot of discussion related to this in other issues. The most promising solution currently is #593746: Prepare Drupal core for dynamic data translation.

I am afraid this cannot be considered a bug report but a feature request, and as such it should be addressed in D8.

blueblade’s picture

do you guys think that this feature will be available for Drupal6 also, and soon?

plach’s picture

I'm sorry but I don't think this will be addressed in D6, you'll have to rely on the i18n project.

gpk’s picture

Version: 8.x-dev » 7.x-dev
Category: feature » bug

@7, @5: unless I'm mistaken (which is not unheard of) it is still not possible to translate custom user role names by any means whatsoever (including i18n) because they are not run through t(). As such this would be a bug.

plach’s picture

User-entered strings are not supposed to pass through t() so we must find another way. You can keep considering it a bug, but this is an ability that Drupal currently does not have and not some component that is misbehaving.

gpk’s picture

@9: Ah, I see the problem, thanks. I'm not familiar enough with the translation internals to take a view on whether this omission should be filed against core or i18n (I guess it's one of those details that has fallen between 2 stools), or what sort of solutions might be appropriate. At least people can find it here and see that it is a current problem for 7.x and earlier.

plach’s picture

Category: bug » feature

As I was saying this cannot be considered a bug.

plach’s picture

Category: feature » bug

Actually it seems user roles cannot be translated neither through DDT, give a look to http://api.drupal.org/api/function/user_roles/7.

andypost’s picture

Maybe just add "translatable" tag to query and schema definition?

andypost’s picture

Status: Active » Needs review
FileSize
1.88 KB

Let's try this one

andypost’s picture

FileSize
1.73 KB

A bit simplified patch

This could lead to double translation with DDT but I see no other way

plach’s picture

@andypost:

This could lead to double translation with DDT

The patch looks good to me: could you please explain why?

andypost’s picture

@plach because rolenames for RID 1 and 2 are passed through t() in http://api.drupal.org/api/function/user_roles/7

EDIT sorry, I mean RID 1 (DRUPAL_ANONYMOUS_RID) and 2 (DRUPAL_AUTHENTICATED_RID)

plach’s picture

@andypost: We could easily leave DRUPAL_ANONYMOUS_RID and DRUPAL_AUTHENTICATED_RID untranslated in DDT so that t() gets the built-in english values.

IMO this is RTBC, but I'd like sun to confirm.

sun’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, looks good.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

mairav’s picture

Is there a way to backport this to Drupal 6? So we can have this working until Drupal 7 can be used on production sites?

andypost’s picture

This approach could not be ported to D6, so proceed with #301541: Contact form and Roles names are not translatable !

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

EugeneChechel’s picture

create hook_form_alter then add there something similar to

foreach ($form['account']['roles']['#options'] as $key => $value) {
$form['account']['roles']['#options'][$key] = t($value);
}

depends on your form. Then translate it

yuseferi’s picture

good job, Thank you

fraweg’s picture

Hello,

I use this patch but it seems not to work. Am I right that after this patch user rolls should be translatable as a string translation?

Many thanks for any Help!

Best regards
Frank

tierso’s picture

Has this yet been worked into drupal, or does it still have to be applied as a patch? (I am unable to find a way to translate roles).

fraweg’s picture

So when I am not alone with this issue this thread should be set to active..am I right?

Best regards
Frank

fraweg’s picture

Status: Closed (fixed) » Active
sun’s picture

Status: Active » Closed (fixed)

For D7, the committed patch is all we can do.

For D8, we hope to be able to have user roles in configuration, and we also hope to have translatable string support for configuration (in general).

fraweg’s picture

But the question why the patch seems to work for some and not others remains open...Too bad I thought it would be a possibility to.

Best regrads

patkai’s picture

The reason might be a simple misunderstanding. As the code comment in modules/user/user.modules shows only built in role names are translatable. So it works for those who try to translate those and does not for those who have custom role names :)

function user_roles($membersonly = FALSE, $permission = NULL) {
  $query = db_select('role', 'r');
  $query->addTag('translatable');
  $query->fields('r', array('rid', 'name'));
  $query->orderBy('weight');
  $query->orderBy('name');
  if (!empty($permission)) {
    $query->innerJoin('role_permission', 'p', 'r.rid = p.rid');
    $query->condition('p.permission', $permission);
  }
  $result = $query->execute();

  $roles = array();
  foreach ($result as $role) {
    switch ($role->rid) {
      // We only translate the built in role names
      case DRUPAL_ANONYMOUS_RID:
        if (!$membersonly) {
          $roles[$role->rid] = t($role->name);
        }
        break;
      case DRUPAL_AUTHENTICATED_RID:
        $roles[$role->rid] = t($role->name);
        break;
      default:
        $roles[$role->rid] = $role->name;
    }
  }

  return $roles;
}
fraweg’s picture

Hello,

and is there a solution for that ?

Best regards
Frank

patkai’s picture

As the code comment suggests this is intentional, but I'm not yet sure why. I'm looking for a way to do the translation without a core hack... Will get back to you when I understand this fully.

tierso’s picture

As the code comment suggests this is intentional, but I'm not yet sure why. I'm looking for a way to do the translation without a core hack... Will get back to you when I understand this fully.

It would be interesting to find out from the original coder what the intention was (if anything else but lack of time/effort; it's seemingly a very minor issue). An oddly multilingual-unfriendly decision, and even stranger that this is issued is being put into the forget-bin considering the increased efforts to make drupal fully "internationalized".

deadbox’s picture

Has anybody found a way to translate custom user roles yet? I am creating a bilingual site where users are added to a custom role with extra permissions after they take out a paid subscription. When they've paid it seems very unprofessional not to show them their role in their own language.

mas0h’s picture

Issue summary: View changes

Any update on this? I can't translate user roles.

wangjiaqi’s picture

I create a simple module to translate the role name without any core hack. Hope it will help you. https://drupal.org/sandbox/wangjiaqi/2222171

mas0h’s picture

Thank you wangjiaqi, I will test and give you feedback.

mas0h’s picture

Doesn't work, after installing and going to translation page I only get the built-in roles

anonymous user	en	translate
authenticated user	en	translate
wangjiaqi’s picture

hi mas0h
1. I don't allowed user translate anonymous user/authenticated user in this module. It's translated by system po file.
2. if you set 'en' as your default language and this list page is 'en' in the same time, role name won't be translated.

How it works:
eg.
1. Create a new role name 'mas0h test'
2. Set 'en' as your default language and 'fr'(or any language you want to translate) as your admin language
3. Go back to the config page, now the 'translate' after 'mas0h test' will be a link, edit that.

mas0h’s picture

Greetings wangjiaqi,

When I view the translation page for roles in the other language, now I see all my roles with translation links not active, just text.

libruce’s picture

make sure you are going to translate the custom roles, except the built-in roles (anonymous user/authenticated user)

wangjiaqi’s picture

Hi mas0h, thks for your reply. I will fix this bug a.s.a.p

kopeboy’s picture

Status: Closed (fixed) » Needs work

Drupal core permits us to create custom user roles.
Those are not translatable.
Looks to me this issue isn't fixed.

kopeboy’s picture

Title: User role names cannot be translated » Custom user roles are not translatable
Priority: Normal » Major
Status: Needs work » Active

Can we have some attention on this?

This is hilarious.. come on!

David_Rothstein’s picture

Status: Active » Postponed (maintainer needs more info)

What is the remaining issue that needs to be fixed here?

As I understand it:

  1. The patch from #15 (which was committed before Drupal 7 was released) follows the guidelines in https://www.drupal.org/node/304002 to make role names translatable by a contrib module.
  2. At least one such contrib module exists (though still a sandbox module): https://www.drupal.org/sandbox/wangjiaqi/2222171

So is there anything that still needs to be changed in core to allow this to work properly in contrib?

paucku’s picture

My solution: I have passed the user role names trough t() function for translation. Works for now. I will write here if something breaks caused of that. It is very easy to do, so in the next upgrade of Drupal Core I will do it again (or will try to merge the new Core using Git).

In function user_roles($membersonly = FALSE, $permission = NULL) which is in file user.module I changed that:

        $roles[$role->rid] = $role->name;

into that:

        $roles[$role->rid] = t($role->name);

  • Dries committed e68cb68 on 8.3.x
    - Patch #598862 by andypost: user role names cannot be translated.
    
    

  • Dries committed e68cb68 on 8.3.x
    - Patch #598862 by andypost: user role names cannot be translated.
    
    
LeDucDuBleuet’s picture

Can somebody please explain why the working solution in comment #48 is not a good solution?

Thank you

geek-merlin’s picture

  • Dries committed e68cb68 on 8.4.x
    - Patch #598862 by andypost: user role names cannot be translated.
    
    

  • Dries committed e68cb68 on 8.4.x
    - Patch #598862 by andypost: user role names cannot be translated.
    
    
LeDucDuBleuet’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
424 bytes

Thanks @axel.rutz but let me explain myself a little better.

What I do not understand is why do we translate only built-in roles in core for D7? I cannot find a clear answer to this simple question?
This is forcing us to use a sandbox module which seems overcomplicated for nothing in my opinion. Especially when the solution like in #48 would be very simple to apply in core so we could translate custom roles using the standard admin interface at "admin/config/regional/translate/translate". All roles would be translatable the same way, no need to use a separate page for custom roles.

Please review the patch attached so we can understand better.

Thank you.

luismagr’s picture

I have reviewed the patch and it works fine for me. Thanks.

geek-merlin’s picture

Status: Needs review » Needs work

Long story short: I18n must be used so that a user-change of the source string won't break translation.

RoslinMary’s picture

Using I18n will provide "String translation" to change the provided string in mentioned language.

David_Rothstein’s picture

I think another problem with the patch is that t() assumes the input string is in English. But if someone has a site where (for example) Spanish is the primary language for the admin UI, they're going to create their role names in Spanish. Passing those through t() would mean that the Spanish role names show up in the translate UI as "English" strings that need to be translated to Spanish...

David_Rothstein’s picture

Title: Custom user roles are not translatable » Custom user roles are not translatable in core alone (requires a contributed module)

I am going to retitle this issue slightly to clarify why it is still open, although I do think closing it may still be the best course of action here; as noted previously, a patch was committed to Drupal 7 a very long time ago to enable role translation via contrib modules, and there is no indication that that process does not work.

If someone can figure out a way to improve this further in core, it could be considered, but I am not sure how without running into the problems discussed above? I do see how something like the patch in #55 can be useful as a site-specific solution, but in its current form it doesn't look like something which could be committed, due to the more general problems mentioned above.

marksmith’s picture

Custom role names did not show up for me among user defined strings in i18n. As per #55, this solution works, but if you need the field translated in Views as well, you have to modify views_handler_field_user_roles.inc.

somewhere around line 46:

change

$this->items[$role->uid][$role->rid]['role'] = check_plain($role->name);

into:

$this->items[$role->uid][$role->rid]['role'] = check_plain(t($role->name));

  • Dries committed e68cb68 on 9.1.x
    - Patch #598862 by andypost: user role names cannot be translated.