Switcher - Logaty

Language SwitcherLast updated: 26/12/2021

use builtin method or create your owen language switcher .

How to use

Learn How you can using languages switcher.
LOGATY Allow visitors to select his own language in easy.

Logaty included 2 different switching types.

  1. <ul> element
  2. <select> element
// <ul> element
echo logaty()->switcher->ul();
// <select> element
echo logaty()->switcher->select();


examples with output!

<?php
    echo logaty()->switcher->ul(); #output 1
    echo logaty()->switcher->select(); #output 2
<!-- output 1 -->
<ul class='logaty-switcher'>
    <li class='logaty-switcher__li' data-value='ar'>
         <img src='https://example.test/flags/ar.png' />
         <a href='http://example.test?lang=ar'> عربي </a>
    </li>
    <li class='logaty-switcher__li' data-value='en'>
         <img src='https://example.test/flags/en.png' />
         <a href='http://example.test?lang=en'> English </a>
    </li>
</ul>
<!-- output 2 -->
<select id='auto-generated' class='logaty-switcher'>
    <option class='logaty-switcher__option' value='http://example.test?lang=ar'> عربي</option>
    <option class='logaty-switcher__option' value='http://example.test?lang=en'>English</option>
</select>
<script>
var select_element = document.getElementById('auto-generated');
select_element.onchange = function() {
    var elem = (typeof this.selectedIndex === "undefined" ? window.event.srcElement : this);
    var value = elem.value || elem.options[elem.selectedIndex].value;
    window.location.href = value;
}
</script>

Create Custom Switch

Create your own language switcher.
LOGATY Allow you to create your own language switcher.

foreach ( logaty()->enabled() as $lang )
{
    // Natural Language Name
    echo  "Name: " . logaty()->naturalName($lang) . "  - link: " . logaty()->link->create('', $lang);
    echo "<br>";
    // English Language Name
    echo  "Name: " . logaty()->name($lang) . "  - link: " . logaty()->link->create('', $lang);

    echo "<hr>";
}

Learn more about Helpers

  • logaty()->enabled()
  • logaty()->naturalNAme($lang)
  • logaty()->name($lang)
  • and more helpers !