Some links beforehand:

I have two languages configured: 1) en 2) lt. And I have several categories inside the user profile (underneath Edit menu). I create categories with hook_user(). Eventually the category becomes a link title on the user page. So there is an error in the documentation, as the hook_user() and hook_menu() contradicts each other. One is saying put a localized title and and another says put an untranslated title.

A bigger problem is in how user.module treats user_categories. See user_menu() hook implementation at the line 1096, here it is:

$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') {
        $items['user/%user_category/edit/'. $category['name']] = array(
          'title callback' => 'check_plain',
          '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',
        );
      }
    }
  }

The 'title callback' in this code snippet is set to 'check_plain', this means that after rebuilding of menus the title will always stay the same.

A quick workaround is to have hook_menu_alter implemented in a separate module where the proper 'title callback' is assigned. E.g.:

function extended_profile_menu_alter(&$callbacks) {
  $callbacks['user/%user_category/edit/My personal information']['title callback'] = 'translate_category'; // Category created using Profile module
  $callbacks['user/%user_category/edit/visuals']['title callback'] = 'translate_category'; // Category created in my module
}

Comments

Mr P’s picture

Hi there. Could you please explain how to fix this problem in greater details.

OnkelTem’s picture

Version: 6.9 » 6.13
Status: Active » Closed (works as designed)

If you look at original user.module code, you may notice, that their own categories go with t():

http://api.drupal.org/api/function/user_user/6

which means, that this issue is 'by design'.