Get the territory / country belonging to a locale? I'm asking, because I was trying to find out the whole afternoon. Found some posts, but they were related to getting all territories.

Example:

I have locales like English, French, Chinese and I'd like to add country to each related locale from territories, because each locale.php in /data folder has the values.

So it would looks like: Territory(United Kingdom) locale(English)

Code I'm working on:

{% set locale = craft.i18n.getCurrentLocale() %}
    {# Configure site locales #}
    {% set locales = ['en', 'en_gb', 'sk'] %}
    {# Check if locale equals the requested page locale #}
    {% if locale == craft.locale %}
        {% set current = true %}
    {% else %}
        {% set current = false %}
    {% endif %}

&lt;ul&gt;
  {% for locale in locales %}
    &lt;li&gt;
      &lt;a href="{{ craft.config.siteUrl[locale] ~ craft.request.getPath() }}"&gt;
         ({{ craft.i18n.getLocaleById(locale).nativeName }})
      &lt;/a&gt;
    &lt;/li&gt;
  {% endfor %} 
&lt;/ul&gt;


The output is a list of locales with native name:


(English)
(British English)
(Slovak)


If there would be a way to relate it's country to each locale from territories, that we wouldn't have to touch app folder to customize the lang files, like I read in other posts.
By doing so, We could achieve this:


World (English)
United Kingdom (British English)
Slovakia (Slovak)


Update

I think it moved on a little bit. With the code @carlcs provided, Craft was able to get a territory. There must to be some bug in it, because from 3 locales, It got assigned to only one territory (United Kingdom - British English).

Here is updated code.

 &lt;ul class="uk-nav"&gt;
 {% set locales = ['en', 'en_gb', 'sk'] %}
   {% for locale in locales %}
      {% set subTags = locale|split('_') %}
         {% set territory = subTags|length &gt; 1 ? craft.i18n.getLocaleData(craft.locale).getTerritory(subTags|last) : '' %}  
             &lt;li&gt;
                 &lt;a href="{{ craft.config.siteUrl[locale] ~ craft.request.getPath() }}" class="{{ current ? 'uk-active'}}"&gt;
                 {% if territory %}{{ territory }}{% endif %} ({{craft.i18n.getLocaleById(locale).nativeName }})
                 &lt;/a&gt;
             &lt;/li&gt;
  {% endfor %} 
  &lt;/ul&gt;
You can't get a territory name directly from a locale tag (e.g. 'en' or 'en_gb'). But what you could do is to
take the territory part of the tag (two letter country code; keep in mind, it's optional) and get the territory
name via getTerritory:

{% set locales = ['en_gb', 'fr_fr', 'zh_cn'] %}

{% for locale in locales %}

    {% set subTags = locale|split('_') %}

    {% set territory = subTags|length &gt; 1 ? craft.i18n.getLocaleData(craft.locale).getTerritory(subTags|last) : '' %}

    {% set language = craft.i18n.getLocaleById(locale).name %}
    {% set language = language ?: craft.i18n.getLocaleById(subTags|first).name %}
    {% set language = language|replace("/- #{territory}$/", '') %}

    {% if territory and language %}
        &lt;li&gt;Territory: {{ territory }}, Language: {{ language }}&lt;/li&gt;
    {% endif %}

{% endfor %}