A slimmed-down version of the original language menu.
This code insert to /cmsimple/userfuncs.php
These with a simple title: iso code,
Code: Select all
<?php
/**
* Returns the language menu.
*
* A slimmed-down version of the original language menu.
*
* @return string HTML
*/
function simple_languagemenu() {
global $pth, $cf, $sl;
$r = XH_secondLanguages();
array_unshift($r, $cf['language']['default']);
$t = '<div class="simple_languagemenu">' . "\n";
foreach ($r as $lang) {
if($sl == $lang) {
$t .= '<span>' . $sl . '</span>';
} else {
$url = $pth['folder']['base']
. ($lang == $cf['language']['default'] ? '' : $lang . '/');
$t .= '<a title="' . $lang . '" href="' . $url . '">' . $lang . '</a>';
}
}
$t .= '</div>' . "\n";
return $t;
}
Code: Select all
<?php
/**
* Returns the language menu.
*
* A slimmed-down version of the original language menu.
* With title from the config.php ($cf['language']['2nd_lang_names']).
*
* @return string HTML
*/
function simple_languagemenu() {
global $pth, $cf, $sl;
$r = XH_secondLanguages();
array_unshift($r, $cf['language']['default']);
$langName = [];
$langNames = explode(';', $cf['language']['2nd_lang_names']);
foreach ($langNames as $value) {
$langName[substr($value, 0, 2)] = substr($value, 3);
}
$t = '<div class="simple_languagemenu">' . "\n";
foreach ($r as $lang) {
if($sl == $lang) {
$t .= '<span>' . $sl . '</span>';
} else {
$url = $pth['folder']['base']
. ($lang == $cf['language']['default'] ? '' : $lang . '/');
$title = isset($langName[$lang])
? $langName[$lang]
: $lang;
$t .= '<a title="' . $title . '" href="' . $url . '">' . $lang . '</a>';
}
}
$t .= '</div>' . "\n";
return $t;
}
Code: Select all
<?=languagemenu();?>
Code: Select all
<?=simple_languagemenu();?>
Changes to the template will no longer be necessary.
This menu can be visually customized with the .simple_languagemenu class.
i.e.
Code: Select all
.simple_languagemenu {
display: flex;
}
.simple_languagemenu * {
margin: 0;
padding: 0;
}
.simple_languagemenu a {
text-decoration: none !important;
}
.simple_languagemenu a:hover {
background: rgba(0,0,0,.1);
}
.simple_languagemenu span {
opacity: 0.33;
}
.simple_languagemenu span,
.simple_languagemenu a {
font-size: 1.2em;
line-height: normal;
margin: 3px;
padding: 0;
border: 1px solid;
border-radius: 2px;
width: 1.75em;
display: inline-block;
text-align: center;
text-transform: uppercase;
color: inherit !important;
}