PDA

View Full Version : Language selection within the header


MMCM
3rd of May 2007 (Thu), 07:52
Since I like to have a consistent way the change the language, I tried to move the language selector to header.php, so it will show on the spot on every page.
This was a little bit tricky, since a form can occur only once on a web page.
And using the standard EE code with "print $languagemenu_html" did not work, because any new div or form tag would break the header and move to a new line.
But I found a solution, this is what I did:
Get the $languagemenu_html code, extract the form tag, remove the original form tags, convert div to span tags and set the original $languagemenu_html variable to "", so that all other EE code will not show the language selector somewhere else.
Wrap the original form tag around the header, so there will be no more line breaks within the header.
I replaced the default div tags with a table, so the language selector can be shown right aligned.
Additionally, I replaced the default INDEX link with my site logo, and included the $ee_lang variable in that link, so clicking on that link won't revert to the default language (BUG FIX!)

This is my new header.php:


<style type="text/css" media="screen"> <!--
.photo_weiss {
color: #f0f0f0;
}
.photo_rot {
color: #ff0000;
}
.photo_grau {
color: #b0b0b0;
}
a:hover .photo_weiss {
color: #ffffff;
}
a:hover .photo_rot {
color: #b0b0b0;
}
a:hover .photo_grau {
color: #ff0000;
}

--> </style>
<?php
global $languagemenu_short;
global $languagemenu_form;
global $languagemenu_html;

if ($languagemenu_html != "") {
preg_match ("/<form[^<]*>/i", $languagemenu_html, $found_form);
$languagemenu_form = $found_form [0];

$languagemenu_short = eregi_replace("<form[^<]*>", "", $languagemenu_html);
$languagemenu_short = eregi_replace("</form[^<]*>", "", $languagemenu_short);

$languagemenu_short = eregi_replace("<div", "<span", $languagemenu_short);
$languagemenu_short = eregi_replace("</div", "</span", $languagemenu_short);
$languagemenu_html = "";
}

print $languagemenu_form . "\n";
?>
<table border="0" cellpadding="0" width="100%" class="navigationheaderholder navigationheader ee_css_header_small"><tr>
<td>
&nbsp;&nbsp;
<a href="index.php?ee_lang=<?php print $ee_lang; ?>"><span class="photo_weiss">www.<span class="photo_rot">photo</span>-<span class="photo_grau">photo</span>.at</span></a> |
<!--
<a href="./comments.php" class="ee_css_hyperlink"><?php print $translated["viewer_comments"]; ?></a> |
-->
<a href="./sitemap.php" class="ee_css_hyperlink"><?php print $translated["site_map"]; ?></a> |
<a href="./rss.php" class="ee_css_hyperlink">RSS</a>
</td>
<td style="text-align: right">
<?php
global $languagemenu_short;

print $languagemenu_short . "\n";
?>
</td>
</tr></table>
</form>


I'm curious, what jeronimo did to show direct links to change the language in his solution: http://photography-on-the.net/forum/showthread.php?t=259701

Currently, my official site still uses EE 1.5RC4, but that will hopefully change soon...

jeronimo
3rd of May 2007 (Thu), 16:30
See my post in the other thread