I found this code in the Craft documentation:

{% set localeData = craft.i18n.getLocaleData() %}
{% for month in localeData.getMonthNames() %}
    {{ month }}
{% endfor %}

What I need is the whole list of countries (from Ascension Island to Zimbabwe). I tried .getTerritories() but it doesn't exist:

{% set localeData = craft.i18n.getLocaleData() %}
{% for country in localeData.getTerritories() %}
    {{ country }}
{% endfor %}

Is there any solution?

1 Answer 1


Looks like Yii doesn't expose a way to grab all of the territories for a given locale by default.

I've just added it to Craft 2.2, though. So when that comes out, you'll be able to do this:

$localeData = craft()->i18n->getLocaleData('en_us');
$allTerritories = $localeData->getAllTerritories();
  • Not exactly. With your code I get a list of all locales but not of all territories (array) in craft/app/framework/i18n/data/en.php. Another question: Is there a page in the documentation where I can find an overview about all craft.i18n.* methods? Aug 11, 2014 at 6:57
  • Ahh, misunderstood the question. Do you want to list the territories array for each locale in craft/app/framework/i18n/data or just en.php? We don't have craft.i18n documented yet, but we should have something for you sooner than later.
    – Brad Bell
    Aug 11, 2014 at 15:34
  • I need the territories only from one locale (en.php). I use the list in a select in a contact form. Aug 11, 2014 at 16:55
  • 1
    With Craft 2.2 I can output the values but not the corresponding keys. I get "146, Italy" instead of "it, Italy". The keys are consecutive numbers not country codes like de, it, en... Sep 3, 2014 at 12:35
  • It doesn't look like territories is included in craft 3 i18n, right? Apr 24, 2020 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.