Language CultureInfo

Language CultureInfo

Sitecore.Globalization.Language

  • language.CultureInfo.DateTimeFormat is not supported for neutral cultures
  • language.CultureInfo.NumberFormat is not supported for neutral cultures

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Database
  • System.Globalization.CultureInfo
  • Sitecore.Globalization.Language

Language CultureInfo C# Web Control Code

Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Globalization.Language language = Sitecore.Context.Language;
if (db == null || language == null) return;

System.Globalization.CultureInfo langCulture = language.CultureInfo;
if (langCulture == null) return;

System.Globalization.CultureInfo cultureInfo = Sitecore.Context.Culture;
if (cultureInfo == null) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
//using : for colon and ? for question mark and   for space
output.Write("{0}&#58;&#160;{1}", "Language CultureInfo Properties", "<b>" + langCulture.DisplayName + "</b>");
output.RenderEndTag(); //P

output.Write("{0}&#58;&#160;{1}", "Name", "<b>" + langCulture.Name + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Display Name", "<b>" +  langCulture.DisplayName + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "English Name", "<b>" +  langCulture.EnglishName + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Native Name", "<b>" + langCulture.NativeName + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Neutral  culture", "<b>" +  langCulture.IsNeutralCulture.ToString() + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Info Read Only", "<b>" +  langCulture.IsReadOnly + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Keyboard Layout ID", "<b>" +  langCulture.KeyboardLayoutId.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Identifier", "<b>" +  langCulture.LCID.ToString() + "</b><br/>");
output.Write("<hr/>");

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
output.Write("{0}&#58;&#160;{1}", "CultureInfo Properties", "<b>" + cultureInfo.DisplayName + "</b>");
output.RenderEndTag(); //P

output.Write("{0}&#58;&#160;{1}", "Name", "<b>" + cultureInfo.Name + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Display Name", "<b>" + cultureInfo.DisplayName + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "English Name", "<b>" + cultureInfo.EnglishName + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Native Name", "<b>" + cultureInfo.NativeName + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Neutral  culture", "<b>" + cultureInfo.IsNeutralCulture.ToString() + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Info Read Only", "<b>" + cultureInfo.IsReadOnly + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Keyboard Layout ID", "<b>" + cultureInfo.KeyboardLayoutId.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Identifier", "<b>" + cultureInfo.LCID.ToString() + "</b><br/>");
output.RenderEndTag(); //Div


Language CultureInfo C# Web Control Output

CultureInfo Properties: English

Name: en
Display Name: English
English Name: English
Native Name: English
Neutral culture? True
Info Read Only? False
Keyboard Layout ID: 9
Identifier: 9

CultureInfo Properties: English (United States)

Name: en-US
Display Name: English (United States)
English Name: English (United States)
Native Name: English (United States)
Neutral culture? False
Info Read Only? False
Keyboard Layout ID: 1033
Identifier: 1033