I18N: How to retrieve territories from the CLDR


I’d like to retrieve the country names, i.e. territories of the CLDR, in multiple locales.

Under the I18N section of the definitive guide, it’s written :

And in every data file under i18n/data in the framework, a comment says:

I didn’t find this cldr command, is it still possible to retrieve this information automatically?

How do you manage translated country names in your projects?


ok, following my previous post, it seems I forgot to look for the build directory of yii framework.

I guess I need to extendthe CldrCommand by adding some processing methods to extract country names information. Did any one already did that?


Even if this thread is a bit old… since it’s the first googleresult and is still valid:

To extract territories and languages from cldr i did the following:

1.downloaded core.zip from one of this:http://cldr.unicode.org/index/downloads

2.applied this patch:

diff --git a/build/commands/CldrCommand.php b/build/commands/CldrCommand.php

index a10a99c..1578455 100644

--- a/build/commands/CldrCommand.php

+++ b/build/commands/CldrCommand.php

@@ -120,6 +119,9 @@ EOD;




+       $this->parseLanguages($xml,$data);

+       $this->parseTerritories($xml,$data);





@@ -190,6 +192,26 @@ EOD;




+   protected function parseLanguages($xml,&$data)

+   {

+       $languages=$xml->xpath('/ldml/localeDisplayNames/languages/language');

+       foreach($languages as $language)

+       {

+           if((string)$language!='')

+               $data['languages'][(string)$language['type']]=(string)$language;

+       }

+   }


+   protected function parseTerritories($xml,&$data)

+   {

+       $territories=$xml->xpath('/ldml/localeDisplayNames/territories/territory');

+       foreach($territories as $territory)

+       {

+           if((string)$territory!='')

+               $data['territories'][(string)$territory['type']]=(string)$territory;

+       }

+   }


    protected function parseMonthNames($xml,&$data)



  1. copied the CldrCommand to framework/cli/commands

  2. cd framework; mkdir data; cp -r Extracted_Core_zip_folder/main/* data

  3. php yiic.php cldr data

Hi Balrok

Thanks for your answer, I’ll try your patch.


That is very useful data. Has this patch been submitted for inclusion to a future release?