Introduction
This is a small tip that explains how to map SQL Server culture information with .NET Framework.
Here, I have created a class with all the key details of cultures available in SQL Server 2012 version.
class sqlculturemapping
{
public string FullName { get; set; }
public string Alias { get; set; }
public string LCID { get; set; }
public string specificulture { get; set; }
public List<sqlculturemapping> getSqlMappings()
{
List<sqlculturemapping> obj = new List<sqlculturemapping>()
{
new sqlculturemapping {FullName="us_english",
Alias="English", LCID="1033", specificulture="en-US"},
new sqlculturemapping {FullName="Deutsch",
Alias="German", LCID="1031", specificulture="de-DE"},
new sqlculturemapping {FullName="Français",
Alias="French", LCID="1036", specificulture="fr-FR"},
new sqlculturemapping {FullName="日本語",
Alias="Japanese", LCID="1041", specificulture="ja-JP"},
new sqlculturemapping {FullName="Dansk",
Alias="Danish", LCID="1030", specificulture="da-DK"},
new sqlculturemapping {FullName="Español",
Alias="Spanish", LCID="3082", specificulture="es-ES"},
new sqlculturemapping {FullName="Italiano",
Alias="Italian", LCID="1040", specificulture="it-IT"},
new sqlculturemapping {FullName="Nederlands",
Alias="Dutch", LCID="1043", specificulture="nl-NL"},
new sqlculturemapping {FullName="Norsk",
Alias="Norwegian", LCID="2068", specificulture="nn-NO"},
new sqlculturemapping {FullName="Português",
Alias="Portuguese", LCID="2070", specificulture="pt-PT"},
new sqlculturemapping {FullName="Suomi",
Alias="Finnish", LCID="1035", specificulture="fi"},
new sqlculturemapping {FullName="Svenska",
Alias="Swedish", LCID="1053", specificulture="sv-SE"},
new sqlculturemapping {FullName="čeština",
Alias="Czech", LCID="1029", specificulture="Cs-CZ"},
new sqlculturemapping {FullName="magyar",
Alias="Hungarian", LCID="1038", specificulture="Hu-HU"},
new sqlculturemapping {FullName="polski",
Alias="Polish", LCID="1045", specificulture="Pl-PL"},
new sqlculturemapping {FullName="română",
Alias="Romanian", LCID="1048", specificulture="Ro-RO"},
new sqlculturemapping {FullName="hrvatski",
Alias="Croatian", LCID="1050", specificulture="hr-HR"},
new sqlculturemapping {FullName="slovenčina",
Alias="Slovak", LCID="1051", specificulture="Sk-SK"},
new sqlculturemapping {FullName="slovenski",
Alias="Slovenian", LCID="1060", specificulture="Sl-SI"},
new sqlculturemapping {FullName="ελληνικά",
Alias="Greek", LCID="1032", specificulture="El-GR"},
new sqlculturemapping {FullName="български",
Alias="Bulgarian", LCID="1026", specificulture="bg-BG"},
new sqlculturemapping {FullName="русский",
Alias="Russian", LCID="1049", specificulture="Ru-RU"},
new sqlculturemapping {FullName="Türkçe",
Alias="Turkish", LCID="1055", specificulture="Tr-TR"},
new sqlculturemapping {FullName="British",
Alias="British English", LCID="2057", specificulture="en-GB"},
new sqlculturemapping {FullName="eesti",
Alias="Estonian", LCID="1061", specificulture="Et-EE"},
new sqlculturemapping {FullName="latviešu",
Alias="Latvian", LCID="1062", specificulture="lv-LV"},
new sqlculturemapping {FullName="lietuvių",
Alias="Lithuanian", LCID="1063", specificulture="lt-LT"},
new sqlculturemapping {FullName="Português (Brasil)",
Alias="Brazilian", LCID="1046", specificulture="pt-BR"},
new sqlculturemapping {FullName="繁體中文",
Alias="Traditional Chinese", LCID="1028", specificulture="zh-TW"},
new sqlculturemapping {FullName="한국어",
Alias="Korean", LCID="1042", specificulture="Ko-KR"},
new sqlculturemapping {FullName="简体中文",
Alias="Simplified Chinese", LCID="2052", specificulture="zh-CN"},
new sqlculturemapping {FullName="Arabic",
Alias="Arabic", LCID="1025", specificulture="ar-SA"},
new sqlculturemapping {FullName="ไทย",
Alias="Thai", LCID="1054", specificulture="Th-TH"}
};
return obj;
}
}
If you see the above definition, I have created a List<sqlculturemapping>
which has all the information added one by one. We can use the below code that will help to get the SQL server mapping by using the culture object's LCID
property.
CultureInfo culture = new CultureInfo(cultureCode);
sqlculturemapping obj = new sqlculturemapping().getSqlMappings().Where
(c => c.LCID == culture.LCID.ToString()).FirstOrDefault();
You might be interested in reading .NET Framework Cultures with Culture Specific Formats and Mapping with SQL Server Language. Don't forget to share your feedback and votes.
History
- 19th May, 2013: Initial version