Skip to content

Instantly share code, notes, and snippets.

@JoshuaJones
Created August 13, 2013 19:02
Show Gist options
  • Save JoshuaJones/6224518 to your computer and use it in GitHub Desktop.
Save JoshuaJones/6224518 to your computer and use it in GitHub Desktop.
Javascript Switch Statement to provide a countries area code based off of Zend_Locale's output
var = countryCode = $('html').attr('lang'),
countryNum;
switch(countryCode) {
// Mexico
case 'es_MX':
countryNum = '52';
break;
// Venezuela
case 'es_VE':
countryNum = '58';
break;
// Colombia
case 'es_CO':
countryNum = '57';
break;
// Ecuador
case 'es_EC':
countryNum = '593';
break;
// Peru
case 'es_PE':
countryNum = '51';
break;
// Brazil
case 'pt_BR':
countryNum = '55';
break;
// Bolivia
case 'es_BO':
countryNum = '591';
break;
// Paraguay
case 'es_PY':
countryNum = '595';
break;
// Uruguay
case 'es_UY':
countryNum = '598';
break;
// Argentina
case 'es_AR':
countryNum = '54';
break;
// Chile
case 'es_CL':
countryNum = '56';
break;
// Greenland
case 'kl_GL':
countryNum = '299';
break;
// Iceland
case 'is_IS':
countryNum = '354';
break;
// Norway
case 'nb_NO':
case 'nn_NO':
case 'se_NO':
countryNum = '47';
break;
// Sweden
case 'sv_SE':
countryNum = '46';
break;
// Finland
case 'fi_FI':
case 'se_FI':
case 'sv_FI':
countryNum = '358'
break;
// UK Codes
case 'cy_GB':
case 'gv_GB':
case 'kw_GB':
case 'en_GB':
countryNum = '44';
break;
// Ireland
case 'ga_IE':
case 'en_IE':
countryNum = '353';
break;
// Denmark
case 'da_DK':
countryNum = '45';
break;
// Germany
case 'de_DE':
case 'nds_DE':
countryNum = '49';
break;
// Poland
case 'pl_PL':
countryNum = '48';
break;
// Austria
case 'de_AT':
countryNum = '43';
break;
// Italy
case 'fur_IT':
case 'it_IT':
countryNum = '39';
break;
// Belarus
case 'be_BY':
countryNum = '375';
break;
// Ukraine
case 'ru_UA':
case 'uk_UA':
countryNum = '380';
break;
// France
case 'oc_FR':
case 'fr_FR':
countryNum = '33';
break;
// Romania
case 'ro_RO':
countryNum = '40';
break;
// Greece
case 'el_GR':
countryNum = '30';
break;
// Turkey
case 'tr_TR':
countryNum = '90';
break;
// Spain
case 'ca_ES':
case 'es_ES':
case 'eu_ES':
case 'gl_ES':
countryNum = '34';
break;
// Portugal
case 'pt_PT':
countryNum = '351';
break;
// Syria
case 'ar_SY':
case 'syr_SY':
countryNum = '963';
break;
// Iraq
case 'ku_IQ':
case 'ar_IQ':
countryNum = '964';
break;
//Iran
case 'fa_IR':
countryNum = '98';
break;
// Saudi Arabia
case 'ar_SA':
countryNum = '966';
break;
// Yemen
case 'ar_YE':
countryNum = '967';
break;
// Oman
case 'ar_OM':
countryNum = '968';
break;
// Morocco
case 'ar_MA':
countryNum = '212';
break;
// Algeria
case 'ar_DZ':
countryNum = '213';
break;
// Tunisia
case 'ar_TN':
countryNum = '216';
break;
// Libya
case 'ar_LY':
countryNum = '218';
break;
// Egypt
case 'ar_EG':
countryNum = '20';
break;
// Niger
case 'ha_NE':
countryNum = '227';
break;
// Sudan
case 'ar_SD':
case 'ha_SD':
countryNum = '249';
break;
// Guinea
case 'kpe_GN':
countryNum = '224';
break;
// Ghana
case 'ak_GH':
case 'ee_GH':
case 'gaa_GH':
case 'ha_GH':
countryNum = '233';
break;
// Nigeria
case 'cch_NG':
case 'ha_NG':
case 'ig_NG':
case 'kaj_NG':
case 'kcg_NG':
case 'yo_NG':
countryNum = '234';
break;
// Ethiopia
case 'aa_ET':
case 'am_ET':
case 'gez_ET':
case 'om_ET':
case 'sid_ET':
case 'so_ET':
case 'ti_ET':
case 'wal_ET':
countryNum = '251';
break;
// Somalia
case 'so_SO':
countryNum = '252';
break;
// Kenya
case 'kam_KE':
case 'om_KE':
case 'so_KE':
case 'sw_KE':
countryNum = '254';
break;
// Tanzania
case 'sw_TZ':
countryNum = '255';
break;
// Congo
case 'ln_CD':
case 'ln_CG':
countryNum = '243';
break;
// Namibia
case 'af_NA':
case 'en_NA':
countryNum = '264';
break;
// Botswana
case 'en_BW':
countryNum = '267';
break;
// Zimbabwe
case 'en_ZW':
countryNum = '263';
break;
// South Africa
case 'af_ZA':
case 'nr_ZA':
case 'nso_ZA':
case 'ss_ZA':
case 'st_ZA':
case 'tn_ZA':
case 'ts_ZA':
case 've_ZA':
case 'xh_ZA':
case 'zu_ZA':
case 'en_ZA':
countryNum = '27';
break;
// Russia / Kazakhstan
case 'tt_RU':
case 'ru_RU':
case 'kk_KZ':
countryNum = '7';
break;
// Uzbekistan
case 'uz_UZ':
countryNum = '998';
break;
// Kyrgyzstan
case 'ky_KG':
countryNum = '996';
break;
// Mongolia
case 'mn_MN':
countryNum = '976';
break;
// China
case 'bo_CN':
case 'ii_CN':
case 'mn_CN':
case 'ug_CN':
case 'zh_CN':
countryNum = '86';
break;
// Hong Kong
case 'zh_HK':
case 'en_HK':
countryNum = '852';
break;
// South Korea
case 'ko_KR':
countryNum = '82';
break;
// Japan
case 'ja_JP':
countryNum = '81';
break;
// Nepal
case 'ne_NP':
countryNum = '977';
break;
// Myanmar
case 'my_MM':
countryNum = '95';
break;
// Thailand
case 'th_TH':
countryNum = '66';
break;
// Philippines
case 'en_PH':
case 'fil_PH':
countryNum = '63';
break;
// Vietnam
case 'vi_VN':
countryNum = '84';
break;
// Malaysia
case 'ms_MY':
countryNum = '60';
break;
// Indonesia
case 'id_ID':
countryNum = '62';
break;
// India
case 'as_IN':
case 'bn_IN':
case 'gu_IN':
case 'hi_IN':
case 'kn_IN':
case 'kok_IN':
case 'ml_IN':
case 'mr_IN':
case 'ne_IN':
case 'or_IN':
case 'pa_IN':
case 'sa_IN':
case 'ta_IN':
case 'te_IN':
case 'ur_IN':
case 'en_IN':
countryNum = '91';
break;
// Australia
case 'en_AU':
countryNum = '61';
break;
// New Zealand
case 'en_NZ':
countryNum = '64';
break;
default:
countryNum = '00';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment