{# 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 #}
<a href="{{ localeEntry.getUrl() }}" class="nav-link{{ current ? ' current'}}">{{ craft.i18n.getLocaleById(locale).name }}</a>
{% else %}
{# Output a link to the hompage #}
<a href="{{ craft.config.siteUrl[locale] }}" class="nav-link{{ current ? ' current'}}">{{ craft.i18n.getLocaleById(locale).name }}</a>
{% endif %}
{# Not an entry page #}
{% else %}
{# Output the same path with the locale's base URL (`siteUrl`) #}
<a href="{{ craft.config.siteUrl[locale] ~ craft.request.getPath() }}" class="nav-link{{ current ? ' current'}}">{{ craft.i18n.getLocaleById(locale).name }}</a>
{% endif %}
{% endfor %}
init current var as false for each loop.