再回来一个新问题。
我还在那个项目网站上工作,而且我还有一个简单的选择。
我试图用当前语言在菜单上显示语言标记。只是国旗,没有文字(可能我们稍后会想要)。
现在,菜单的工作原理如下:
user_box.php
<?php trace(__FILE__,'begin'); ?>
<div id="userbox">
<ul id="account_more_menu">
<?php if(isset($_userbox_projects) && is_array($_userbox_projects) && count($_userbox_projects)) { ?>
<li><a href="<?php echo get_url('dashboard', 'my_projects') ?>"><?php echo lang('my projects') ?></a>
<ul>
<?php if (logged_user()->canManageProjects()) { ?>
<li><a href="<?php echo get_url('project', 'add') ?>"><?php echo lang('add project') ?></a></li>
<li><a href="<?php echo get_url('project', 'copy') ?>"><?php echo lang('copy project') ?></a></li>
<?php } // if ?>
<li><span><?php echo lang('projects') ?>:</span></li>
<?php if(100 > count($_userbox_projects)) { ?>
<?php foreach($_userbox_projects as $_userbox_project) { ?>
<li><a href="<?php echo $_userbox_project->getOverviewUrl() ?>"><?php echo clean($_userbox_project->getName()) ?></a></li>
<?php } // foreach ?>
<?php } else { ?>
<?php foreach($_userbox_projects as $_userbox_project) { ?>
<?php $name = clean($_userbox_project->getName()) ?>
<?php $url = clean($_userbox_project->getOverviewUrl()) ?>
<?php $first = strtoupper(substr($name,0,1)); ?>
<?php if (!array_key_exists($index, $first)) $index[$first]=array(); ?>
<?php $index[$first][] = array($name, $url); ?>
<?php } // foreach ?>
<?php foreach($index as $first => $items) { ?>
<li><a href=#><?php echo $first ?></a><ul>
<?php foreach($items as $item) { ?>
<li><a href="<?php echo $item[1] ?>"><?php echo $item[0] ?></a></li>
<?php } // foreach ?>
</ul></li>
<?php } // foreach ?>
<?php } // if ?>
<?php
// PLUGIN HOOK
plugin_manager()->do_action('my_projects_dropdown');
// PLUGIN HOOK
?>
</ul>
</li>
<?php } // if ?>
<?php if (!is_null(active_project())) { ?>
<?php if (use_permitted(logged_user(), active_project(), 'tasks')) { ?>
<?php if (isset($_userbox_projects) && is_array($_userbox_projects) && count($_userbox_projects)) { ?>
<li><a href="<?php echo get_url('dashboard', 'my_tasks') ?>"><?php echo lang('my tasks') ?></a>
<ul>
<li><span><?php echo clean(active_project()->getName()) ?>:</span></li>
<li><a href="<?php echo get_url('project', 'overview') ?>"><?php echo lang('overview') ?></a></li>
<li class="header"><a href="<?php echo get_url('message', 'index') ?>"><?php echo lang('messages') ?></a></li>
<?php if (ProjectMessage::canAdd(logged_user(), active_project())) { ?>
<li><a href="<?php echo get_url('message', 'add') ?>"><?php echo lang('add message') ?></a></li>
<?php } // if ?>
<li class="header"><a href="<?php echo get_url('milestone', 'index') ?>"><?php echo lang('milestones') ?></a></li>
<li><a href="<?php echo get_url('milestone', 'calendar') ?>"><?php echo lang('view calendar') ?></a></li>
<?php if (ProjectMilestone::canAdd(logged_user(), active_project())) { ?>
<li><a href="<?php echo get_url('milestone', 'add') ?>"><?php echo lang('add milestone') ?></a></li>
<?php } // if ?>
<?php
// PLUGIN HOOK
plugin_manager()->do_action('my_tasks_dropdown');
// PLUGIN HOOK
?>
</ul>
</li>
<?php } // if ?>
<?php } // if ?>
<?php } // if ?>
<?php if(logged_user()->isAdministrator()) { ?>
<li><a href="<?php echo get_url('administration') ?>"><?php echo lang('administration') ?></a>
<ul>
<li class="header"><a href="<?php echo get_url('administration', 'company') ?>"><?php echo lang('company') ?></a></li>
<li><a href="<?php echo get_url('company', 'edit') ?>"><?php echo lang('edit company') ?></a></li>
<li><a href="<?php echo owner_company()->getAddContactUrl() ?>"><?php echo lang('add contact') ?></a></li>
<li class="header"><a href="<?php echo get_url('administration', 'clients') ?>"><?php echo lang('clients') ?></a></li>
<li><a href="<?php echo get_url('company', 'add_client') ?>"><?php echo lang('add client') ?></a></li>
<li class="header"><a href="<?php echo get_url('administration', 'projects') ?>"><?php echo lang('projects') ?></a></li>
<li class="header"><a href="<?php echo get_url('administration', 'configuration') ?>"><?php echo lang('configuration') ?></a></li>
<li class="header"><a href="<?php echo get_url('administration', 'plugins') ?>"><?php echo lang('plugins') ?></a></li>
<li class="header"><a href="<?php echo get_url('administration', 'tools') ?>"><?php echo lang('administration tools') ?></a></li>
<li><a href="<?php echo get_url('administration', 'tool_mass_mailer') ?>"><?php echo lang('administration tool name mass_mailer' ) ?></a></li>
<li class="header"><a href="<?php echo get_url('administration', 'upgrade') ?>"><?php echo lang('upgrade') ?></a></li>
<?php
// PLUGIN HOOK
plugin_manager()->do_action('administration_dropdown');
// PLUGIN HOOK
?>
</ul>
</li>
<?php } // if ?>
<li class="user"><a href="<?php echo logged_user()->getAccountUrl() ?>"><?php echo lang('view') . ' ' . clean($_userbox_user->getDisplayName()) ?></a>
<ul>
<li><span><?php echo lang('account') ?>:</span></li>
<?php if (logged_user()->canUpdateProfile(logged_user())) { ?>
<li><a href="<?php echo logged_user()->getEditProfileUrl() ?>"><?php echo lang('update profile') ?></a></li>
<li><a href="<?php echo logged_user()->getEditPasswordUrl() ?>"><?php echo lang('change password') ?></a></li>
<?php } // if ?>
<?php if (logged_user()->canUpdatePermissions(logged_user())) { ?>
<li><a href="<?php echo logged_user()->getUpdatePermissionsUrl() ?>"><?php echo lang('update permissions') ?></a></li>
<?php } // if ?>
<?php
// PLUGIN HOOK
plugin_manager()->do_action('my_account_dropdown');
// PLUGIN HOOK
?>
</ul>
</li>
<li><a href=#><img src="<?php echo image_url('icons/language.gif') ?>" /></a><ul>
<li><span><?php echo lang('select language') ?>:</span></li>
<?php
$base_language = config_option('installation_base_language', 'en_us');
$languages = array( $base_language => $base_language );
include(ROOT . '/language/locales.php');
if ($handle = opendir(ROOT . '/language')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (array_key_exists( $file, $locales)) {
$languages[$file] = $locales[$file];
}
}
}
closedir($handle);
}
foreach( $languages as $locale => $desc ) {
echo '<li><a href="' . get_url('dashboard', 'index', array('language' => $locale) ) . '" >' . $desc . '</a></li>';
}
?>
</ul>
</li>
<li><a id="logout" class="js-confirm" href="<?php echo get_url('access', 'logout') ?>" title="<?php echo lang('confirm logout') ?>"><?php echo lang('logout') ?></a></li>
</ul>
</div>
<?php trace(__FILE__,'end'); ?>
如您所见,它只显示单个图像。我似乎无法弄清楚如何改变它以适应语言。
我通常会得到这些结果:
在语言文件中显示菜单选项,您可以更改这些选项。所以我用带有标志的精灵来改变它们。
精灵语言菜单选项(locales.php):
<?php
$locales = array(
'bg_bg' => 'Bulgarian (Bulgaria)',
'cz_cz' => 'Czech',
'da_dk' => '<img src="images/blank.gif" class="flag flag-dk" alt="Danish" /> Danish',
'de_de' => '<img src="images/blank.gif" class="flag flag-de" alt="German" /> German',
'el_gr' => 'Greek',
'en_us' => '<img src="images/blank.gif" class="flag flag-gb" alt="English" /> English',
'es_ar' => 'Spanish (Argentina)',
'es_es' => '<img src="images/blank.gif" class="flag flag-es" alt="Spanish" /> Spanish',
'es_mx' => 'Spanish (Mexico)',
'fi_fi' => '<img src="images/blank.gif" class="flag flag-fi" alt="Finnish" /> Finnish',
'fr_fr' => '<img src="images/blank.gif" class="flag flag-fi" alt="Finnish" /> Finnish',
'hu_hu' => 'Hungarian (Hungary)',
'hu_if' => 'Hungarian (informal)',
'is_is' => '<img src="images/blank.gif" class="flag flag-is" alt="Icelandic" /> Icelandic',
'it_it' => '<img src="images/blank.gif" class="flag flag-it" alt="Italian" /> Italian',
'lt_lt' => 'Lithuanian (Lithuania)',
'nl_nl' => '<img src="images/blank.gif" class="flag flag-nl" alt="Dutch (Nederlands)" /> Dutch',
'no_nb' => '<img src="images/blank.gif" class="flag flag-no" alt="Norwegian" /> Norwegian',
'pl_pl' => 'Polish (Poland)',
'pt_br' => 'Portuguese (Brazil)',
'pt_pt' => 'Portuguese (Portugal)',
'ru_ru' => '<img src="images/blank.gif" class="flag flag-ru" alt="Russian" /> Russian',
'sl_si' => 'Slovenian (Slovenia)',
'sv_se' => 'Swedish (sv_se)',
'tr_tr' => 'Turkish (Turkey)',
'vn_vn' => 'Vietnamese',
'zh_cn' => '<img src="images/blank.gif" class="flag flag-cn" alt="Chinese" /> Simplified Chinese',
);
?>
CSS:
.flag {
width: 16px;
height: 11px;
background:url(/images/flags.png) no-repeat
}
.flag.flag-cn {background-position: -16px 0}
.flag.flag-de {background-position: -32px 0}
.flag.flag-dk {background-position: -48px 0}
.flag.flag-es {background-position: 0 -11px}
.flag.flag-fi {background-position: -16px -11px}
.flag.flag-gb {background-position: -32px -11px}
.flag.flag-is {background-position: -48px -11px}
.flag.flag-it {background-position: 0 -22px}
.flag.flag-nl {background-position: -16px -22px}
.flag.flag-no {background-position: -32px -22px}
.flag.flag-ru {background-position: -48px -22px}
`
现在我尝试了很多东西。但我似乎无法获得正确的代码。基本上我想要的是更改图标(图像中的荷兰标志)以更改为正确的语言标志。使用那个精灵来做这个会很受欢迎,但是如果那个太多了,我可以制作单独的图像。我只是需要帮助找出这段代码才能使它工作。