How do I create a locale dropdown to switch between languages? I’m trying to create a dropdown menu to switch between language’s on my site. I am currently doing this with this snippet found on the google plus community:

{% block locale__switch %}

{# Loop through all of the site locales, except the current one #}
{% set otherLocales = craft.i18n.getSiteLocaleIds()|without(craft.locale) %}
{% for locale in otherLocales %}

    {# Find the current entry in the other locale #}
    {% set localeEntry = craft.entries.id(entry.id).locale(locale).first %}

    {# Make sure that it's actually localized to this locale #}
    {% if localeEntry.locale == locale %}

        {# Output a link to it #}
        &lt;a href="{{ localeEntry.getUrl() }}" style="text-transform:uppercase;"&gt;{{ locale }}&lt;/a&gt;
    {% else %}

        {# Output a link to the hompage #}
        &lt;a href="{{ craft.config.siteUrl[locale] }}" style="text-transform:uppercase;"&gt;{{ locale }}&lt;/a&gt;
    {% endif %}

    {% endfor %}
{% endblock %} 


But this simply shows a single link to the opposite locale than the current. Basically I want to have something like this: 

 &lt;div id="lang-form"&gt;
    &lt;div id="language-selected" class="dropdownbox"&gt;EN &amp;#9662;&lt;/div&gt;

    &lt;div id="dropdown-wrapper"&gt;
      &lt;ul name="lang" id="select-language-menu" class="menu"&gt;
          &lt;li class="selected"&gt;
               English
               &lt;div class="lang-code" style="display: none;"&gt;en &amp;#9662;&lt;/div&gt;
          &lt;/li&gt;
          &lt;li&gt;
               Hungarian
               &lt;div class="lang-code" style="display: none;"&gt;hu &amp;#9662;&lt;/div&gt;
          &lt;/li&gt;
       &lt;/ul&gt;
     &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;


This probably seems trivial and simple, but I’m having a tough time figuring out how craft works at this level. Any ideas?
This is because you loop through all but the current locales. Remove the without filter to loop them all.


  {% set otherLocales = craft.i18n.getSiteLocaleIds()|without(craft.locale) %}


.

Add "current" class:

To assign the current locale's link a class of "current", compare the looped locale to the current locale and set a variable that you can later test for. (In the example code I use the ternary operator for short output syntax.)

.

Example Code:

With my example code below you first create an array of all the locales you want the language switch to include, and then loop through it. With this technique you can define the order of the output manually or exclude locales from the loop.

{# Configure and loop through selected site locales #}
{% set locales = ['en', 'hu'] %}
{% for locale in locales %}

    {# Check if locale equals the requested page locale #}
    {% set current = false %}
    {% if locale == craft.locale %}
        {% set current = true %}
    {% endif %}

    {# Is this an entry page? #}
    {% if entry is defined %}

        {# Find the current entry in the other locale #}
        {% set localeEntry = craft.entries.id(entry.id).locale(locale).first() %}

        {# Make sure that it's actually localized to this locale #}
        {% if localeEntry and localeEntry.locale == locale %}

            {# Output a link to it #}
            &lt;a href="{{ localeEntry.getUrl() }}" class="nav-link{{ current ? ' current'}}"&gt;{{ craft.i18n.getLocaleById(locale).name }}&lt;/a&gt;

        {% else %}

            {# Output a link to the hompage #}
            &lt;a href="{{ craft.config.siteUrl[locale] }}" class="nav-link{{ current ? ' current'}}"&gt;{{ craft.i18n.getLocaleById(locale).name }}&lt;/a&gt;

        {% endif %}

    {# Not an entry page #}
    {% else %}

        {# Output the same path with the locale's base URL (`siteUrl`) #}
        &lt;a href="{{ craft.config.siteUrl[locale] ~ craft.request.getPath() }}" class="nav-link{{ current ? ' current'}}"&gt;{{ craft.i18n.getLocaleById(locale).name }}&lt;/a&gt;

    {% endif %}

{% endfor %}


Code edits done to implement a lookup of the (translated) locale name as described here by Brandon Kelly

.

Notes:


The easiest (and recommended) way to use this language switch is to exclusively use    entry pages (channel entries, structure entries, or singles) on your site.
All non entry pages have to have the same URL path / slug for each locale (eg. http://craft.dev/de/meineindexseite/ and http://craft.dev/en/meineindexseite/), translated URL parts won't work for non entry pages with this code.
If you only use entry pages or if you are using localized template folders you should be save to remove the entry is defined conditional (incl. the else part) altogether.
craft.config.siteUrl[localeId] only works if siteUrl is configured to take care of localized URLs