LANGCODE.CPP
//+----------------------------------------------------------------------- 
// 
//  Tabular Data Control Language Support 
//  Copyright (C) Microsoft Corporation, 1996, 1997 
// 
//  File:       LangCode.cpp 
// 
//  Contents:   Implementation of the LocalNameToLCID() function. 
// 
//------------------------------------------------------------------------ 
 
#include "stdafx.h" 
#include "LangCode.h" 
#include "wch.h" 
 
 
//=======================================================================// 
 
typedef struct 
{ 
    LCID    lcid;       // DWORD Locale 
    WCHAR   *pwchAbbrev;// ISO 369 abbreviated (no hyphen) language string 
    WCHAR   *pwchFull;  // ISO 369 standard accept language string 
}  
    LANGPROP; 
 
static LANGPROP langs[] = 
{    
    { 0x0436, L"af",    L"af"   }, //Afrikaans 
    { 0x041c, L"sq",    L"sq"   }, //Albanian 
    { 0x0401, L"ar-sa", L"arsa" }, // Arabic(Saudi Arabia) 
    { 0x0801, L"ar-iq", L"ariq" }, // Arabic(Iraq) 
    { 0x0C01, L"ar-eg", L"areg" }, // Arabic(Egypt) 
    { 0x1001, L"ar-ly", L"arly" }, // Arabic(Libya) 
    { 0x1401, L"ar-dz", L"ardz" }, // Arabic(Algeria) 
    { 0x1801, L"ar-ma", L"arma" }, // Arabic(Morocco) 
    { 0x1C01, L"ar-tn", L"artn" }, // Arabic(Tunisia) 
    { 0x2001, L"ar-om", L"arom" }, // Arabic(Oman) 
    { 0x2401, L"ar-ye", L"arye" }, // Arabic(Yemen) 
    { 0x2801, L"ar-sy", L"arsy" }, // Arabic(Syria) 
    { 0x2C01, L"ar-jo", L"arjo" }, // Arabic(Jordan) 
    { 0x3001, L"ar-lb", L"arlb" }, // Arabic(Lebanon) 
    { 0x3401, L"ar-kw", L"arkw" }, // Arabic(Kuwait) 
    { 0x3801, L"ar-ae", L"arae" }, // Arabic(U.A.E.) 
    { 0x3C01, L"ar-bh", L"arbh" }, // Arabic(Bahrain) 
    { 0x4001, L"ar-qa", L"arqa" }, // Arabic(Qatar) 
    { 0x042D, L"eu",    L"eu"   }, // Basque 
    { 0x0402, L"bg",    L"bg"   }, // Bulgarian 
    { 0x0423, L"be",    L"be"   }, // Belarusian 
    { 0x0403, L"ca",    L"ca"   }, // Catalan 
    { 0x0404, L"zh-tw", L"zhtw" }, // Chinese(Taiwan Region) 
    { 0x0804, L"zh-cn", L"zhcn" }, // Chinese(PRC) 
    { 0x0C04, L"zh-hk", L"zhhk" }, // Chinese(Hong Kong SAR, PRC) 
    { 0x1004, L"zh-sg", L"zhsg" }, // Chinese(Singapore) 
    { 0x041a, L"hr",    L"hr"   }, // Croatian 
    { 0x0405, L"cs",    L"cs"   }, // Czech 
    { 0x0406, L"da",    L"da"   }, // Danish 
    { 0x0413, L"nl",    L"nl"   }, // Dutch(Standard) 
    { 0x0813, L"nl-be", L"nlbe" }, // Dutch(Belgian) 
    { 0x0009, L"en",    L"en"   }, // English 
    { 0x0409, L"en-us", L"enus" }, // English(United States) 
    { 0x0809, L"en-gb", L"engb" }, // English(British) 
    { 0x0c09, L"en-au", L"enau" }, // English(Australian) 
    { 0x1009, L"en-ca", L"enca" }, // English(Canadian) 
    { 0x1409, L"en-nz", L"ennz" }, // English(New Zealand) 
    { 0x1809, L"en-ie", L"enie" }, // English(Ireland) 
    { 0x1c09, L"en-za", L"enza" }, // English(South Africa) 
    { 0x2009, L"en-jm", L"enjm" }, // English(Jamaica) 
    { 0x2409, L"en",    L"en"   }, // English(Caribbean) 
    { 0x2809, L"en-bz", L"enbz" }, // English(Belize) 
    { 0x2c09, L"en-tt", L"entt" }, // English(Trinidad) 
    { 0x0425, L"et",    L"et"   }, // Estonian 
    { 0x0438, L"fo",    L"fo"   }, // Faeroese 
    { 0x0429, L"fa",    L"fa"   }, // Farsi 
    { 0x040b, L"fi",    L"fi"   }, // Finnish 
    { 0x040c, L"fr",    L"fr"   }, // French(Standard) 
    { 0x080c, L"fr-be", L"frbe" }, // French(Belgian) 
    { 0x0c0c, L"fr-ca", L"frca" }, // French(Canadian) 
    { 0x100c, L"fr-ch", L"frch" }, // French(Swiss) 
    { 0x140c, L"fr-lu", L"frlu" }, // French(Luxembourg) 
    { 0x043c, L"gd",    L"gd"   }, // Gaelic(Scots) 
    { 0x083c, L"gd-ie", L"gdie" }, // Gaelic(Irish) 
    { 0x0407, L"de",    L"de"   }, // German(Standard) 
    { 0x0807, L"de-ch", L"dech" }, // German(Swiss) 
    { 0x0c07, L"de-at", L"deat" }, // German(Austrian) 
    { 0x1007, L"de-lu", L"delu" }, // German(Luxembourg) 
    { 0x1407, L"de-li", L"deli" }, // German(Liechtenstein) 
    { 0x0408, L"el",    L"el"   }, // Greek 
    { 0x040D, L"he",    L"he"   }, // Hebrew 
    { 0x0439, L"hi",    L"hi"   }, // Hindi 
    { 0x040e, L"hu",    L"hu"   }, // Hungarian 
    { 0x040F, L"is",    L"is"   }, // Icelandic 
    { 0x0421, L"in",    L"in"   }, // Indonesian 
    { 0x0410, L"it",    L"it"   }, // Italian(Standard) 
    { 0x0810, L"it-ch", L"itch" }, // Italian(Swiss) 
    { 0x0411, L"ja",    L"ja"   }, // Japanese 
    { 0x0412, L"ko",    L"ko"   }, // Korean 
    { 0x0812, L"ko",    L"ko"   }, // Korean(Johab) 
    { 0x0426, L"lv",    L"lv"   }, // Latvian 
    { 0x0427, L"lt",    L"lt"   }, // Lithuanian 
    { 0x042f, L"mk",    L"mk"   }, // Macedonian 
    { 0x043e, L"ms",    L"ms"   }, // Malaysian 
    { 0x043a, L"mt",    L"mt"   }, // Maltese 
    { 0x0414, L"no",    L"no"   }, // Norwegian(Bokmal) 
    { 0x0814, L"no",    L"no"   }, // Norwegian(Nynorsk) 
    { 0x0415, L"pl",    L"pl"   }, // Polish 
    { 0x0416, L"pt-br", L"ptbr" }, // Portuguese(Brazilian) 
    { 0x0816, L"pt",    L"pt"   }, // Portuguese(Standard) 
    { 0x0417, L"rm",    L"rm"   }, // Rhaeto-Romanic 
    { 0x0418, L"ro",    L"ro"   }, // Romanian 
    { 0x0818, L"ro-mo", L"romo" }, // Romanian(Moldavia) 
    { 0x0419, L"ru",    L"ru"   }, // Russian 
    { 0x0819, L"ru-mo", L"rumo" }, // Russian(Moldavia) 
    { 0x043b, L"sz",    L"sz"   }, // Sami(Lappish) 
    { 0x0c1a, L"sr",    L"sr"   }, // Serbian(Cyrillic) 
    { 0x081a, L"sr",    L"sr"   }, // Serbian(Latin) 
    { 0x041b, L"sk",    L"sk"   }, // Slovak 
    { 0x0424, L"sl",    L"sl"   }, // Slovenian 
    { 0x042e, L"sb",    L"sb"   }, // Sorbian 
    { 0x040a, L"es",    L"es"   }, // Spanish(Spain - Traditional Sort) 
    { 0x080a, L"es-mx", L"esmx" }, // Spanish(Mexican) 
    { 0x0c0a, L"es",    L"es"   }, // Spanish(Spain - Modern Sort) 
    { 0x100a, L"es-gt", L"esgt" }, // Spanish(Guatemala) 
    { 0x140a, L"es-cr", L"escr" }, // Spanish(Costa Rica) 
    { 0x180a, L"es-pa", L"espa" }, // Spanish(Panama) 
    { 0x1c0a, L"es-do", L"esdo" }, // Spanish(Dominican Republic) 
    { 0x200a, L"es-ve", L"esve" }, // Spanish(Venezuela) 
    { 0x240a, L"es-co", L"esco" }, // Spanish(Colombia) 
    { 0x280a, L"es-pe", L"espe" }, // Spanish(Peru) 
    { 0x2c0a, L"es-ar", L"esar" }, // Spanish(Argentina) 
    { 0x300a, L"es-ec", L"esec" }, // Spanish(Ecuador) 
    { 0x340a, L"es-cl", L"escl" }, // Spanish(Chile) 
    { 0x380a, L"es-uy", L"esuy" }, // Spanish(Uruguay) 
    { 0x3c0a, L"es-py", L"espy" }, // Spanish(Paraguay) 
    { 0x400a, L"es-bo", L"esbo" }, // Spanish(Bolivia) 
    { 0x440a, L"es-sv", L"essv" }, // Spanish(El Salvador) 
    { 0x480a, L"es-hn", L"eshn" }, // Spanish(Honduras) 
    { 0x4c0a, L"es-ni", L"esni" }, // Spanish(Nicaragua) 
    { 0x500a, L"es-pr", L"espr" }, // Spanish(Puerto Rico) 
    { 0x0430, L"sx",    L"sx"   }, // Sutu 
    { 0x041D, L"sv",    L"sv"   }, // Swedish 
    { 0x081d, L"sv-fi", L"svfi" }, // Swedish(Finland) 
    { 0x041E, L"th",    L"th"   }, // Thai 
    { 0x0431, L"ts",    L"ts"   }, // Tsonga 
    { 0x0432, L"tn",    L"tn"   }, // Tswana 
    { 0x041f, L"tr",    L"tr"   }, // Turkish 
    { 0x0422, L"uk",    L"uk"   }, // Ukrainian 
    { 0x0420, L"ur",    L"ur"   }, // Urdu 
    { 0x0433, L"ve",    L"ve"   }, // Venda 
    { 0x042a, L"vi",    L"vi"   }, // Vietnamese 
    { 0x0434, L"xh",    L"xh"   }, // Xhosa 
    { 0x043d, L"ji",    L"ji"   }, // Yiddish 
    { 0x0435, L"zu",    L"zu"   }, // Zulu 
}; 
 
 
//------------------------------------------------------------------------ 
// 
//  Function:   LocalNametoLCID() 
// 
//  Synopsis:   Searches for the locale ID corresponding to the given 
//              ISO 369 locale name. 
// 
//  Arguments:  pwchLocaleName    Name of locale to match. 
// 
//  Returns:    Locale ID if a match is found 
//              NULL Locale (0x0000) if no match is found 
// 
//------------------------------------------------------------------------ 
 
LCID LocalNameToLCID(LPWCH pwchLocaleName) 
{ 
    int i; 
    LCID    lcid    = 0x0000; 
 
    for (i = 0; i < sizeof(langs) / sizeof(langs[0]); i++) 
    { 
        LANGPROP    *pLang  = &langs[i]; 
 
        if (wch_icmp(pwchLocaleName, pLang->pwchAbbrev) == 0 || 
            wch_icmp(pwchLocaleName, pLang->pwchFull) == 0) 
        { 
            lcid = pLang->lcid; 
            break; 
        } 
    } 
    return lcid; 
}