I've searched the interwebs trying to find a solution, but without results. I'm trying to translate my own custom user role names. If you take a look at the dokumentation for user_roles(), it can be seen that only the standard user roles get translated:

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

I'm working on a system that is used in many languages. I need to be able to translate my role names. I'm having a hard time understanding why the default case doesn't wrap the role name in a t(). You would expect the role name to come from a trusted source. Or am I totally wrong here?

I've created a very simple patch that I'll be using myself, and I hope it will be committed if everything turns out to be okay...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lund.mikkel’s picture

I've added a context to avoid translation collisions...

sir_squall’s picture

Assigned: Unassigned » sir_squall
Status: Needs review » Patch (to be ported)
FileSize
807 bytes

I cleaned up the code and removed your context (I think it's useless: if you look at the two other role names, they are translated without context and I don't see the interest to add a context only for the new roles)

dcam’s picture

Status: Patch (to be ported) » Needs review

Setting status to test #2.

droplet’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Needs work
Issue tags: +D8MI

D8 first

lund.mikkel’s picture

I don't know why I didn't think about the shortening of the code :) Nice one.

I do though still think a context would make a lot of sense. There is a big difference between an editor for e.g. newsletters and blogs, compared to a text editor. Both would be "Editor" in English, but would translate to "Redaktør" and "Tekstredigeringsprogram" in Danish - I hope you see the subtle difference ;) The lacking use of context in Drupal is in my opinion a big problem, and something I have a lot of problems with on a daily basis working with a multilingual site.

sir_squall’s picture

Yes I see the difference (my boss is Danish), and I agree that there is a gap in the contexts of drupal, but I think it is not in this post we will be able to change something, we should try to launch an initiative to create contexts correctly in drupal.

jvieille’s picture

This work well even for D6!
Just need to save the module page to access the translatable string for new roles.

sir_squall’s picture

Drupal 8 does not need a patch, he have already the "$query->addTag('translatable');"

sir_squall’s picture

FileSize
1.06 KB

Fixed the filter, to use the title of the permission, not the key, (because the title can be translated)

Boobaa’s picture

I was looking for a solution, but using t() on user-entered text (like custom role names) is definitely unacceptable (it may even have security issues as well). I'm not against solving this issue, but this is not the way to do so, and I don't (yet) know how to do this properly.

achton’s picture

sir_squall’s picture

Assigned: sir_squall » Unassigned
Status: Needs work » Closed (duplicate)

thank you I had not seen

mas0h’s picture

Issue summary: View changes

I tried to apply the patch from this issue and also the other one here https://drupal.org/node/598862

But I couldn't get the patch to apply. What am I missing here?