I noticed that the extractor picked up the permissions, without my using a t('...'), from hook_perms. However, it appeared to not get each "user_access('...')" use. Should I be using t('...') on my access permissions?

Comments

gábor hojtsy’s picture

Status: Active » Closed (works as designed)

The idea is that you either reuse a permission from core, which is already translated, or you use one of your defined permissions which is already picked up from the perm hook. If this is not good for you, please reopen.

nancydru’s picture

Status: Closed (works as designed) » Active

Apparently I didn't explain this well enough, so let me try to be a bit more precise.

Here's part of my code; I've shown the line numbers here for reference.

 33  function faq_ask_perm() {
 34    return array('ask question', 'answer question');
 35  }
...
 57  function faq_ask_menu($may_cache) {
 72     $items[] = array(
 73      'path' => 'faq_ask',
 74      'title' => t('Ask a question'),
 75      'callback' => 'faq_ask_page',
 76      'access' => user_access('ask question'),
 77      );

 80    $items[] = array(
 81      'path' => 'faq_ask/answer',
 82      'title' => t('Answer a question'),
 83      'callback' => 'faq_ask_answer',
 84      'access' => user_access('answer question'),
 85      'type' => MENU_CALLBACK,
 86      );

The "pot" file contains:

#: faq_ask.module:34
msgid "ask question"
msgstr ""
 
#: faq_ask.module:34
msgid "answer question"
msgstr ""

However, lines 76 and 84 that use these permissions are not listed in the "pot" file.

Would this not result in the menu items blocking users if the permissions in hook_perm are translated and the menu items are not? Is it suggested that all uses of access permissions be enclosed in "t()"? I have never seen another module that does this, although it would seem nice.

gábor hojtsy’s picture

Status: Active » Closed (works as designed)

Permissions are not translated *when used* with user_access(). They are only translated when displayed on the permissions configuration form, so the administrator understands the different permissions. Otherwise Drupal uses the original untranslated permissions internally. They are only translated when displayed.

nancydru’s picture

Thank you. That completely clears up my worry.