Not sure how viable this is, but menu items can be put into translation context via title_arguments. If there is a 'context' key for title arguments, we can probably assume it is a string context (but of course not 100% sure, there can be custom callback arguments there). Not sure how to extend that support to menu_alter too, but should look into that too. Menu items are likely to use contexts, since they need to use short text.

Comments

Gábor Hojtsy’s picture

We could maybe find a 'context' => 'Something' key in title_arguments, but (a) we cannot ensure that is the syntax people will use. Also, we'd need to somehow pair up the titles with their arguments, although they can come in any order. To demonstrate what I mean:

$items['item1'] = array(
  'title' => 'Home',
  'title_arguments' => array(array(), array('context' => 'Example context')),
);
$items['item2'] = array(
  'title' => 'View',
  'title_arguments' => array(array(), array('context' => 'Another example context')),
);
$items['item3'] = array(
  'title_arguments' => array(array(), array('context' => 'Yet another example context')),
  'title' => 'View',
);
$items['item4'] = array(
  'title' => 'View',
);
$items['item4']['title_arguments'][1]['context'] = 'Some context';

For these to be identified properly, we'd need a much more sophisticated state machine, where we can tell if we are in an item array or not, so we could save the context appropriately. Then for more complex things like the context for a title being modified later like in (4) or maybe even those two things separated to hook_menu() and hook_menu_alter(), it becomes pretty impossible to track.

So for this to be reliably identified, I'd suggesting using title_callback for now instead of letting people rely on title_arguments. Then the custom title_callback can use t(), format_plural() and friends and specify the context as needed, such as:

$items['item5'] = array(
  'title_callback' => 'mymodule_item5_title_callback',
);

function mymodule_item5_title_callback() {
  return t('View', array(), array('context' => 'Our useful context'));
}
Gábor Hojtsy’s picture

Title: Support context extraction in hook_menu() via 'title_arguments' » String context not identified in hook_menu and hook_menu_alter title_arguments

Retitling to point out the status quo.