Updated 2014-05-24 19:55:58 by AMG

Richard Suchenwirth 1999-07-22 - The following two procs allow querying language resp. country codes (as of ISO standards 639 for languages, 3166 for countries --see http://www.iana.org/cctld/cctld-whois.htm, for example) in both ways, e.g.
 i18n:language de ==> German
 i18n:language English ==> en
 i18n:country TK ==> Tokelau
 i18n:country India ==> IN

Called without arguments, they return a sorted list of the codes they know, so you can call them like
 foreach i [i18n:country] {puts "$i is for [i18n:country $i]"}

Not very fascinating algorithms, but the data (I pasted them from web pages and formatted them for Tcl) may be useful for people involved in I18N (that's Internationalization, because there's 18 letters between the I and the N ;-)

See also http://www.unicode.org/onlinedat/languages.html and http://www.unicode.org/onlinedat/countries.html
 proc i18n:language {{what ""}} {
    set list {
 aa Afar ab Abkhazian af Afrikaans am Amharic ar Arabic as Assamese
 ay Aymara az Azerbaijani ba Bashkir be Byelorussian bg Bulgarian
 bh Bihari bi Bislama bn Bengali bo Tibetan br Breton ca Catalan
 co Corsican cs Czech cy Welsh da Danish de German dz Bhutani
 el Greek en English eo Esperanto es Spanish et Estonian eu Basque
 fi Finnish fj Fiji fo Faroese fr French fy Frisian ga Irish
 gl Galician gn Guarani gu Gujarati ha Hausa hi Hindi hr Croatian
 hu Hungarian hy Armenian ia Interlingua ie Interlingue ik Inupiak
 in Indonesian is Icelandic it Italian iw Hebrew ja Japanese ji Yiddish
 jv Javanese ka Georgian kk Kazakh kl Greenlandic km Cambodian
 kn Kannada ko Korean ks Kashmiri ku Kurdish ky Kirghiz la Latin
 ln Lingala lo Laothian lt Lithuanian lv Latvian mg Malagasy mi Maori
 mk Macedonian ml Malayalam mn Mongolian mo Moldavian mr Marathi
 ms Malay mt Maltese my Burmese na Nauru ne Nepali nl Dutch no Norwegian
 oc Occitan om Afan(Oromo) or Oriya pa Punjabi pl Polish ps Pashto
 pt Portuguese qu Quechua rm Rhaeto-romance rn Kurundi ro Romanian
 ru Russian rw Kinyarwanda sa Sanskrit sd Sindhi sg Sangho
 sh Serbo-croatian si Singhalese sk Slovak sl Slovenian sm Samoan
 sn Shona so Somali sq Albanian sr Serbian ss Siswati st Sesotho
 su Sundanese sv Swedish sw Swahili ta Tamil te Telugu tg Tajik th Thai
 ti Tigrinya tk Turkmen tl Tagalog tn Setswana to Tonga tr Turkish
 ts Tsonga tt Tatar tw Twi uk Ukrainian ur Urdu uz Uzbek vi Vietnamese
 vo Volapuk wo Wolof xh Xhosa yo Yoruba zh Chinese zu Zulu
    }
    if {$what==""} {
        foreach {short long} $list {lappend res $short}
        return [lsort $res]
    }
    set i [lsearch -exact $list $what]
    if {$i==-1} {return "--"}
    if {$i%2} {return [lindex $list [expr $i-1]]}
    return [lindex $list [expr $i+1]]
 }

 proc i18n:country {{what ""}} {
    set list {
 AD Andorra AE {United Arab Emirates} AF Afghanistan AG {Antigua and Barbuda}
 AI Anguilla AL Albania AM Armenia AN {Netherlands Antilles} AO Angola
 AQ Antarctica AR Argentina AS {American Samoa} AT Austria AU Australia
 AW Aruba AZ Azerbaijan BA {Bosnia and Herzegowina} BB Barbados
 BD Bangladesh BE Belgium BF {Burkina Faso} BG Bulgaria BH Bahrain BI  Burundi
 BJ Benin BM Bermuda BN {Brunei Darussalam} BO Bolivia BR Brazil BS Bahamas
 BT Bhutan BV {Bouvet Island} BW Botswana BY Belarus BZ Belize CA Canada
 CC {Cocos (Keeling) Islands} CF {Central African Republic} CG Congo
 CH Switzerland CI {Cote d'Ivoire} CK {Cook Islands} CL Chile CM Cameroon
 CN China CO Colombia CR {Costa Rica} CU Cuba CV {Cape Verde}
 CX {Christmas Island} CY Cyprus CZ {Czech Republic} DE Germany DJ Djibouti
 DK Denmark DM Dominica DO {Dominican Republic} DZ Algeria EC Ecuador
 EE Estonia EG Egypt EH {Western Sahara} ER Eritrea ES Spain ET Ethiopia
 FI Finland FJ Fiji FK {Falkland Islands (Malvinas)}
 FM {Micronesia, Federated States Of} FO {Faroe Islands} FR France
 FX {France, Metropolitan} GA Gabon GB {United Kingdom} GD Grenada GE Georgia
 GF {French Guiana} GH Ghana GI Gibraltar GL Greenland GM Gambia GN  Guinea
 GP Guadeloupe GQ {Equatorial Guinea} GR Greece
 GS {South Georgia and The South Sandwich Islands} GT Guatemala GU Guam
 GW Guinea-Bissau GY Guyana HK {Hong Kong} HM {Heard and Mc Donald Islands}
 HN Honduras HR {Croatia} HT Haiti HU Hungary ID Indonesia IE Ireland
 IL Israel IN India IO {British Indian Ocean Territory} IQ Iraq
 IR {Iran} IS Iceland IT Italy JM Jamaica JO Jordan JP Japan KE Kenya
 KG Kyrgyzstan KH Cambodia KI Kiribati KM Comoros KN {Saint Kitts and  Nevis}
 KP {Korea, Democratic People's Republic Of} KR {Korea, Republic Of}
 KW Kuwait KY {Cayman Islands} KZ Kazakhstan
 LA {Lao People's Democratic Republic} LB Lebanon LC {Saint Lucia}
 LI Liechtenstein LK {Sri Lanka} LR Liberia LS Lesotho LT Lithuania
 LU Luxembourg LV Latvia LY {Libyan Arab Jamahiriya} MA Morocco MC Monaco
 MD {Moldova, Republic Of} MG Madagascar MH {Marshall Islands}
 MK {Macedonia, The Former Yugoslav Republic Of} ML Mali MM Myanmar
 MN Mongolia MO Macau MP {Northern Mariana Islands} MQ Martinique
 MR Mauritania MS Montserrat MT Malta MU Mauritius MV Maldives MW Malawi
 MX Mexico MY Malaysia MZ Mozambique NA Namibia NC {New Caledonia}
 NE Niger NF {Norfolk Island} NG Nigeria NI Nicaragua NL Netherlands
 NO Norway NP Nepal NR Nauru NU Niue NZ {New Zealand} OM Oman PA Panama
 PE Peru PF {French Polynesia} PG {Papua New Guinea} PH Philippines
 PK Pakistan PL Poland PM {St. Pierre and Miquelon} PN Pitcairn
 PR {Puerto Rico} PT Portugal PW Palau PY Paraguay QA Qatar RE Reunion
 RO Romania RU {Russian Federation} RW Rwanda SA {Saudi Arabia}
 SB {Solomon Islands} SC Seychelles SD Sudan SE Sweden SG Singapore
 SH {St. Helena} SI Slovenia SJ {Svalbard and Jan Mayen Islands}
 SK {Slovakia (Slovak Republic)} SL {Sierra Leone} SM {San Marino} SN Senegal
 SO Somalia SR Suriname ST {Sao Tome and Principe} SV {El Salvador}
 SY {Syrian Arab Republic} SZ Swaziland TC {Turks and Caicos Islands}
 TD Chad TF {French Southern Territories} TG Togo TH Thailand TJ Tajikistan
 TK Tokelau TM Turkmenistan TN Tunisia TO Tonga TP {East Timor} TR Turkey
 TT {Trinidad and Tobago} TV Tuvalu TW {Taiwan}
 TZ {Tanzania, United Republic Of} UA Ukraine UG Uganda
 UM {United States Minor Outlying Islands} US {United States}
 UY Uruguay UZ Uzbekistan
 VA {Vatican State} VC {Saint Vincent and The Grenadines} VE Venezuela
 VG {Virgin Islands (British)} VI {Virgin Islands (U.S.)} VN {Viet Nam}
 VU Vanuatu WF {Wallis and Futuna Islands} WS Samoa YE Yemen YT Mayotte
 YU Yugoslavia ZA {South Africa} ZM Zambia ZR Zaire ZW Zimbabwe
    }
    if {$what==""} {
        foreach {short long} $list {lappend res $short}
        return [lsort $res]
    }
    set i [lsearch -exact $list $what]
    if {$i==-1} {return "--"}
    if {$i%2} {return [lindex $list [expr $i-1]]}
    return [lindex $list [expr $i+1]]
 }
 # Test:
  catch {console show}
  foreach i [i18n:country] {puts "$i is for [i18n:country $i]"}

i18n - writing for the world | Arts and crafts of Tcl-Tk programming