1

I created a custom menu that uses menu_load_links() and menu_link_load() to get permission, path, and title info to output a menu. It currently outputs a very simple HTML list of links without any theme or translation function wrappers, and I'm trying to apply the correct wrappers to make it theme- and module-compatible.

This site is currently single-language but in the future it will be in multiple languages. Which translation functions wrappers do I need for my links? There's t(), st(), and get_t() (that I am aware of).

Are there other translate functions that I should be using that I am not aware of?

And is it sufficient to apply t() to the displayed link title only, or does it need to be applied to, say, the path or alias or anything?

Here's the code:

$foreshadow_menu_items = menu_load_links('menu-program-menu');
print('<ul class="menu">');
foreach ($foreshadow_menu_items as $foreshadow_menu_item) {
    $foreshadow_menu_item_info = menu_link_load($foreshadow_menu_item['mlid']);
    $foreshadow_menu_item_access = $foreshadow_menu_item_info['access'];
    $foreshadow_menu_path = $foreshadow_menu_item['link_path'];
    print ('<li class="leaf">');
    if ($foreshadow_menu_item_access == 1){ 
        print("<a href=\"/$foreshadow_menu_path\" class=\"access-granted\">");
    }
    else{ 
        print("<div class=\"access-denied\">");
    }
    echo "$foreshadow_menu_item[link_title]\n";
    if ($foreshadow_menu_item_access == 1){ 
        print('</a>');
    }
    else{
        print("</div>");
    }
    print ('</li>');
}
print("</ul>");

I especially don't understand the instruction on t(),

You should never use t() to translate variables, such as calling t($text); unless the text that the variable holds has been passed through t() elsewhere (e.g., $text is one of several translated literal strings in an array).

How is this not a catch-22?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.