Hi,

Just noticed in Drupal 6.15 that menu items for user categories, those that generate secondary tabs, cannot be translated. The problem is that these menu items use check_plain for the title callback, so t() is never involved.

Here's the code in user.module, user_menu() that build these items:

        $items['user/%user_category/edit/'. $category['name']] = array(
          'title callback' => 'check_plain',               // This is the problem !!!
          'title arguments' => array($category['title']),
          'page callback' => 'user_edit',
          'page arguments' => array(1, 3),
          'access callback' => isset($category['access callback']) ? $category['access callback'] : 'user_edit_access',
          'access arguments' => isset($category['access arguments']) ? $category['access arguments'] : array(1),
          'type' => MENU_LOCAL_TASK,
          'weight' => $category['weight'],
          'load arguments' => array('%map', '%index'),
          'tab_parent' => 'user/%/edit',
          'file' => 'user.pages.inc',
        );

Instead, I think it could be like this:

        $items['user/%user_category/edit/'. $category['name']] = array(
          'title callback' => '_user_sanitize_category',               // Use a different title callback !!!
          'title arguments' => array($category['title']),
          'page callback' => 'user_edit',
          'page arguments' => array(1, 3),
          'access callback' => isset($category['access callback']) ? $category['access callback'] : 'user_edit_access',
          'access arguments' => isset($category['access arguments']) ? $category['access arguments'] : array(1),
          'type' => MENU_LOCAL_TASK,
          'weight' => $category['weight'],
          'load arguments' => array('%map', '%index'),
          'tab_parent' => 'user/%/edit',
          'file' => 'user.pages.inc',
        );

And then, add the following function somewhere in user.module:

function _user_sanitize_category($title) {
  return check_plain(t($title));
}

Comments

markus_petrux’s picture

In the meantime, I'm using the following snippet on a custom module that also does the job:

/**
 * Implementation of hook_menu_alter().
 */
function mymodule_menu_alter(&$items) {
  $empty_account = new stdClass();
  if (($categories = _user_categories($empty_account)) && (count($categories) > 1)) {
    foreach ($categories as $key => $category) {
      // 'account' is already handled by the MENU_DEFAULT_LOCAL_TASK.
      if ($category['name'] != 'account') {
        if (isset($items['user/%user_category/edit/'. $category['name']])) {
          $items['user/%user_category/edit/'. $category['name']]['title callback'] = '_mymodule_user_sanitize_category';
        }
      }
    }
  }
}
function _mymodule_user_sanitize_category($title) {
  return check_plain(t($title));
}
japanitrat’s picture

Version: 6.15 » 6.16

Still an issue

japanitrat’s picture

Or not?

markus_petrux’s picture

StatusFileSize
new1.08 KB

This is still an issue. Here' a patch.

Status: Needs review » Needs work

The last submitted patch, user_sanitize_category-696924-4.patch, failed testing.

markus_petrux’s picture

Status: Needs work » Needs review
StatusFileSize
new1.04 KB

can't find file to patch at input line 8
Perhaps you used the wrong -p or --strip option?

Re-rolled without -p option.

Status: Needs review » Needs work

The last submitted patch, user_sanitize_category-696924-6.patch, failed testing.

markus_petrux’s picture

failed? Well, I give up, sorry.

tajabosc’s picture

Hello,

I'm also reporting this issue in drupal 6.16, with menu items generated by simplenews an content profile modules not translatable with "translate interface".

markus_petrux’s picture

Status: Needs work » Needs review
StatusFileSize
new1.04 KB

It seems last patch failed because "Ensure the patch applies to the lastest checkotu of the code-base.". AFAICT, this patch and the previous one are the same, so I do not know what else to do if the test fails. I'm unable to understand the log.

Here's an updated patch against a just checked out D6 code base.

Ian Ward’s picture

Version: 6.16 » 6.x-dev
Status: Needs review » Reviewed & tested by the community

I've hit this issue too. The patch seems ok. Why is it ignored by the test bot?

damien tournoud’s picture

Status: Reviewed & tested by the community » Closed (works as designed)

As any user-input, those category names cannot be translated in Drupal 6; this is by design.

markus_petrux’s picture

Status: Closed (works as designed) » Needs review

Sorry for the delay. :(

It seems to me this is as "user input" as a content type name.

Please, close the issue for a different reason, but not that one.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.