_menu_item_localize
Definition
_menu_item_localize(&$item, $map, $link_translate = FALSE)
includes/menu.inc, line 532
Description
Localize the router item title using t() or another callback.
Translate the title and description to allow storage of English title strings in the database, yet display of them in the language required by the current user.
Parameters
$item A menu router item or a menu link item.
$map The path as an array with objects already replaced. E.g., for path node/123 $map would be array('node', $node) where $node is the node object for node 123.
$link_translate TRUE if we are translating a menu link item; FALSE if we are translating a menu router item.
Return value
No return value. $item['title'] is localized according to $item['title_callback']. If an item's callback is check_plain(), $item['options']['html'] becomes TRUE. $item['description'] is translated using t(). When doing link translation and the $item['options']['attributes']['title'] (link title attribute) matches the description, it is translated as well.
Related topics
| Name | Description |
|---|---|
| Menu system | Define the navigation menus, and route page requests to code based on URLs. |
Code
<?php
function _menu_item_localize(&$item, $map, $link_translate = FALSE) {
$callback = $item['title_callback'];
$item['localized_options'] = $item['options'];
// If we are not doing link translation or if the title matches the
// link title of its router item, localize it.
if (!$link_translate || (!empty($item['title']) && ($item['title'] == $item['link_title']))) {
// t() is a special case. Since it is used very close to all the time,
// we handle it directly instead of using indirect, slower methods.
if ($callback == 't') {
if (empty($item['title_arguments'])) {
$item['title'] = t($item['title']);
}
else {
$item['title'] = t($item['title'], menu_unserialize($item['title_arguments'], $map));
}
}
elseif (drupal_function_exists($callback)) {
if (empty($item['title_arguments'])) {
$item['title'] = $callback($item['title']);
}
else {
$item['title'] = call_user_func_array($callback, menu_unserialize($item['title_arguments'], $map));
}
// Avoid calling check_plain again on l() function.
if ($callback == 'check_plain') {
$item['localized_options']['html'] = TRUE;
}
}
}
elseif ($link_translate) {
$item['title'] = $item['link_title'];
}
// Translate description, see the motivation above.
if (!empty($item['description'])) {
$original_description = $item['description'];
$item['description'] = t($item['description']);
if ($link_translate && isset($item['options']['attributes']['title']) && $item['options']['attributes']['title'] == $original_description) {
$item['localized_options']['attributes']['title'] = $item['description'];
}
}
}
?> 