i18nmenu.module in Internationalization 5.3
File
contrib/i18nmenu.module
View source
<?php
function i18nmenu_menu($may_cache) {
static $menu_translate;
if ($may_cache) {
$menu_translate = TRUE;
}
elseif ($menu_translate) {
i18nmenu_translate_all();
}
}
function i18nmenu_translate_all() {
global $_menu;
global $user;
global $locale;
$cid = "{$user->uid}:{$locale}";
cache_clear_all($cid, 'cache_menu');
foreach ($_menu['items'] as $mid => $item) {
if ($item['type'] & MENU_CREATED_BY_ADMIN) {
$_menu['items'][$mid]['title'] = tt("menu:item:{$mid}:title", $_menu['items'][$mid]['title']);
$_menu['items'][$mid]['description'] = tt("menu:item:{$mid}:description", $_menu['items'][$mid]['description']);
}
}
cache_set($cid, 'cache_menu', serialize($_menu), time() + 60 * 60 * 24);
}
function i18nmenu_help($section = 'admin/help#i18nmenu') {
switch ($section) {
case 'admin/help#i18nmenu':
return t('
<p>This module provides support for translatable custom menu items:</p>
<ul>
<li>Create menus as usual, with names in English. If the menu is already created, no changes are needeed</li>
<li>Show the menu in some block</li>
<li>Switch language to some non english one -while viewing the block-, so the <i>locales</i> table is populated with the new strings</li>
<li>Use the localization system to translate menu item strings</li>
</ul>');
}
}