I needed a language switcher so i searched the forum and docs, found very useful stuff, but as im new in processwire (came from joomla) all this is still a bit confusing for me, need time to get use to it i guess. There's probably other people like me get confused in all the power of pw, and need language switcher on the site, so i decided to share what i came up with.
Actually its very simple, a lot easier then i thought. There is very nice example in docs using select box (there i found out about $languages array, and its clicked), but you need additional script if you wanna style it, so i came up with something simple:
TADAAAAA
<?php foreach($languages as $language) : ?>
<a href="<?=$page->localUrl($language)?>"><?=$language->title?></a>
<?php endforeach;?>
Here's another example, but now active language is just a span with active class. (Style used on most websites).
<?php foreach($languages as $language) : ?>
<?php if($user->language->id == $language->id) :?>
<span class="active"><?=$language->title?></span>
<?php else : ?>
<a href="<?=$page->localUrl($language)?>"><?=$language->title?></a>
<?php endif;?>
<?php endforeach;?>
Here is UIkit dropdown example, same can do with bootstrap, just a bit different markup.
<div class="uk-button-dropdown" data-uk-dropdown>
<button class="uk-button"><?=$user->language->name?></button>
<div class="uk-dropdown uk-dropdown-bottom">
<ul class="uk-nav uk-nav-dropdown">
<?php foreach($languages as $language) : ?>
<?php if($user->language->id != $language->id) :?>
<li><a href="<?=$page->localUrl($language)?>"><?=$language->title?></a></li>
<?php endif;?>
<?php endforeach;?>
</ul>
</div>
</div>