Back again with a new question.
I'm still working on that projects website, and i'm kind of stuck with a simple option.
Im trying to show a language flag at the menu with the current language. Just the flag, no text (maybe we'll want that later though).
Right now, the menu works like this:
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'); ?>
As you can see it just shows a single image. And i can't seem to figure out how to change this to adjust to the language.
I usually end up with these results:
In the language file the menu options are showed, and you can change these. So i changed them using a sprite with a flag.
Sprite language menu option (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}
`
Now i have tried multiple things. But I can not seem to get the right code. Basically what I want is to change the icon (dutch flag in the images) to change to the correct language flag. It would be favoured to do this by using that sprite, but if that would be too much, I could just make seperate images. I just need some help figuring out this code to make it work.