Culture Information

Culture Information

Controls featured in this example:

  • Sitecore Sublayout (Web User Control)

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Database
  • System.EventArgs
  • Sitecore.Globalization.Language
  • System.Globalization.CultureInfo
  • System.Text.StringBuilder
  • System.Web.UI.WebControls.ListItem

ASCX File Markup


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CultureInformation.ascx.cs" Inherits="Website.layouts.TIC.Sublayouts.CultureInformation" %> <%@ register TagPrefix="sc" Namespace="Sitecore.Web.UI.WebControls" Assembly="Sitecore.Kernel" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<div style="font-weight:bold; width:100%; clear:both">     <asp:Label ID="lblHeading" runat="server" Text="C# Web Control Real-time Output" /> </div>

<div style="font-size:x-small; width:100%; clear:both">  <div style="font-weight:bold">     <asp:Literal ID="litItem" runat="server"></asp:Literal> </div> <div>     <p><asp:Label ID="lblItem" runat="server" Text="Select a Culture" Font-Bold="True" /></p> </div> <div> <asp:DropDownList ID="ddlCultures" runat="server" AutoPostBack="True"     Height="20px" onselectedindexchanged="ddlCultures_SelectedIndexChanged"     Width="214px"> </asp:DropDownList>  </div> <div>     <asp:Literal ID="Literal1" runat="server" />     </div> </div>

Add using System.Linq to the using declarations

C# Web Control Code

protected void Page_Load(object sender, System.EventArgs e)
        {
Sitecore.Data.Items.Item item = Sitecore.Context.Item;
if (item == null) return;

if (!IsPostBack)
{
    System.Globalization.CultureInfo[] cultures = System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.SpecificCultures);
    if (cultures == null) return;

    var sortedList = (from entry in cultures orderby entry.DisplayName ascending select entry);
    foreach (System.Globalization.CultureInfo culture in sortedList)
    {
        ddlCultures.Items.Add(new System.Web.UI.WebControls.ListItem(culture.DisplayName, culture.Name)); 
    }
    System.Globalization.CultureInfo initialCulture = Sitecore.Context.Culture;
    ddlCultures.SelectedValue = initialCulture.Name;
    ddlCultures_SelectedIndexChanged(this, System.EventArgs.Empty);
}
        }

        
protected void ddlCultures_SelectedIndexChanged(object sender, System.EventArgs e)
        {
System.Globalization.CultureInfo culture = null;
string selectedCulture = ddlCultures.SelectedValue; 
if (selectedCulture != System.String.Empty)
{
    culture = Sitecore.Globalization.Language.GetCultureInfo(selectedCulture);
}
else
    culture = Sitecore.Globalization.Language.GetCultureInfo("en-US");

if (culture == null) return;
System.Text.StringBuilder builder = new System.Text.StringBuilder();
builder.Append( "Name: " + "<b>" + culture.Name + "</b><br/>");
builder.Append( "Display Name: " + "<b>" + culture.DisplayName + "</b><br/>");
builder.Append( "Native Name: " + "<b>" + culture.NativeName + "</b><br/>");
builder.Append( "English Name: " + "<b>" + culture.EnglishName + "</b><br/>");
builder.Append( "Culture Name: " + "<b>" + culture.TextInfo.CultureName + "</b><br/>");
builder.Append( "ISO Language Name (2 Letter): " + "<b>" + culture.TwoLetterISOLanguageName + "</b><br/>");
builder.Append( "ISO Language Name (3 Letter): " + "<b>" + culture.ThreeLetterISOLanguageName + "</b><br/>");
builder.Append( "Windows Language Name (3 Letter): " + "<b>" + culture.ThreeLetterWindowsLanguageName + "</b><br/>");
builder.Append( "Use User Selected Culture Settings?: " + "<b>" + culture.UseUserOverride.ToString() + "</b><br/>");
builder.Append( "ANSI Code Page: " + "<b>" + culture.TextInfo.ANSICodePage.ToString() + "</b><br/>");
builder.Append( "EBCDIC Code Page: " + "<b>" + culture.TextInfo.EBCDICCodePage.ToString() + "</b><br/>");
builder.Append( "Macintosh Code Page: " + "<b>" + culture.TextInfo.MacCodePage.ToString() + "</b><br/>");
builder.Append( "OEM Code Page: " + "<b>" + culture.TextInfo.OEMCodePage.ToString() + "</b><br/>");
builder.Append( "TextInfo Is Read Only?: " + "<b>" + culture.TextInfo.IsReadOnly.ToString() + "</b><br/>");
builder.Append( "Is Right To Left?: " + "<b>" + culture.TextInfo.IsRightToLeft.ToString() + "</b><br/>");
builder.Append( "Culture Identifier: " + "<b>" + culture.TextInfo.LCID.ToString() + "</b><br/>");
builder.Append( "Keyboard Layout ID: " + "<b>" + culture.KeyboardLayoutId.ToString() + "</b><br/>");
builder.Append( "List Separator: " + "<b>" + culture.TextInfo.ListSeparator + "</b><br/>");
builder.Append( "Calendar Algorithm Type: " + "<b>" + culture.Calendar.AlgorithmType.ToString() + "</b><br/>");
builder.Append( "Calendar Is Read Only?: " + "<b>" + culture.Calendar.IsReadOnly.ToString() + "</b><br/>");
builder.Append( "LCID Identifier: " + "<b>" + culture.LCID.ToString() + "</b><br/>");
builder.Append( "Compare  Info LCID: " + "<b>" + culture.CompareInfo.LCID.ToString() + "</b><br/>");
builder.Append( "Compare Info Culture Name: " + "<b>" + culture.CompareInfo.Name + "</b><br/>");
builder.Append( "Culture Types: " + "<b>" + culture.CultureTypes.ToString() + "</b><br/>");
builder.Append( "Is Neutral Culture?: " + "<b>" + culture.IsNeutralCulture.ToString() + "</b><br/>");
builder.Append( "Is Read Only?: " + "<b>" + culture.IsReadOnly + "</b><br/>");

builder.Append("<br/>DateTime Format:<br/><br/>");

builder.Append( "Min Supported DateTime: " + "<b>" + culture.DateTimeFormat.Calendar.MinSupportedDateTime.ToShortDateString() + "</b><br/>");
builder.Append( "Two Digit Year Max: " + "<b>" + culture.DateTimeFormat.Calendar.TwoDigitYearMax.ToString() + "</b><br/>");
builder.Append( "Calendar Week Rule: " + "<b>" + culture.DateTimeFormat.CalendarWeekRule.ToString() + "</b><br/>");
builder.Append( "Date Separator: " + "<b>" + culture.DateTimeFormat.DateSeparator + "</b><br/>");
builder.Append( "First Day Of Week: " + "<b>" + culture.DateTimeFormat.FirstDayOfWeek.ToString() + "</b><br/>");
builder.Append( "Full DateTime Pattern: " + "<b>" + culture.DateTimeFormat.FullDateTimePattern + "</b><br/>");
builder.Append( "DateTime Format Is Read Only?: " + "<b>" + culture.DateTimeFormat.IsReadOnly + "</b><br/>");
builder.Append( "Long Date Pattern: " + "<b>" + culture.DateTimeFormat.LongDatePattern + "</b><br/>");
builder.Append( "Long Time Pattern: " + "<b>" + culture.DateTimeFormat.LongTimePattern + "</b><br/>");
builder.Append( "Month Day Pattern: " + "<b>" + culture.DateTimeFormat.MonthDayPattern + "</b><br/>");
builder.Append( "Native Calendar Name: " + "<b>" + culture.DateTimeFormat.NativeCalendarName + "</b><br/>");
builder.Append( "PM Designator: " + "<b>" + culture.DateTimeFormat.PMDesignator + "</b><br/>");
builder.Append( "Time Format: " + "<b>" + culture.DateTimeFormat.RFC1123Pattern + "</b><br/>");
builder.Append( "Short Date Pattern: " + "<b>" + culture.DateTimeFormat.ShortDatePattern + "</b><br/>");
builder.Append( "Short Time Pattern: " + "<b>" + culture.DateTimeFormat.ShortTimePattern + "</b><br/>");
builder.Append( "Sortable DateTime Pattern: " + "<b>" + culture.DateTimeFormat.SortableDateTimePattern + "</b><br/>");
builder.Append( "Time Separator: " + "<b>" + culture.DateTimeFormat.TimeSeparator + "</b><br/>");
builder.Append( "Universal Sortable Pattern: " + "<b>" + culture.DateTimeFormat.UniversalSortableDateTimePattern + "</b><br/>");
builder.Append( "Year Month Pattern: " + "<b>" + culture.DateTimeFormat.YearMonthPattern + "</b><br/>");

builder.Append("<br/>Number Format:<br/><br/>");

builder.Append( "Currency Decimal Places: " + "<b>" + culture.NumberFormat.CurrencyDecimalDigits.ToString() + "</b><br/>");
builder.Append( "Currency Decimal Separator: " + "<b>" + culture.NumberFormat.CurrencyDecimalSeparator.ToString() + "</b><br/>");
builder.Append( "Currency Group Separator: " + "<b>" + culture.NumberFormat.CurrencyGroupSeparator.ToString() + "</b><br/>");
builder.Append( "Currency Negative Pattern: " + "<b>" + culture.NumberFormat.CurrencyNegativePattern.ToString() + "</b><br/>");
builder.Append( "Currency Positive Pattern: " + "<b>" + culture.NumberFormat.CurrencyPositivePattern.ToString() + "</b><br/>");
builder.Append( "Currency Symbol: " + "<b>" + culture.NumberFormat.CurrencySymbol + "</b><br/>");
builder.Append( "Digit Substitution: " + "<b>" + culture.NumberFormat.DigitSubstitution.ToString() + "</b><br/>");
builder.Append( "Number Format Read Only?: " + "<b>" + culture.NumberFormat.IsReadOnly.ToString() + "</b><br/>");
builder.Append( "Not A Number Symbol: " + "<b>" + culture.NumberFormat.NaNSymbol + "</b><br/>");
builder.Append( "Negative Infinity Symbol: " + "<b>" + culture.NumberFormat.NegativeInfinitySymbol + "</b><br/>");
builder.Append( "Negative Sign: " + "<b>" + culture.NumberFormat.NegativeSign + "</b><br/>");
builder.Append( "Number Decimal Places: " + "<b>" + culture.NumberFormat.NumberDecimalDigits.ToString() + "</b><br/>");
builder.Append( "Number Decimal Separator: " + "<b>" + culture.NumberFormat.NumberDecimalSeparator + "</b><br/>");
builder.Append( "Number Group Separator: " + "<b>" + culture.NumberFormat.NumberGroupSeparator + "</b><br/>");
builder.Append( "Number Negative Pattern: " + "<b>" + culture.NumberFormat.NumberNegativePattern + "</b><br/>");
builder.Append( "Percent Decimal Digits: " + "<b>" + culture.NumberFormat.PercentDecimalDigits.ToString() + "</b><br/>");
builder.Append( "Percent Decimal Separator: " + "<b>" + culture.NumberFormat.PercentDecimalSeparator + "</b><br/>");
builder.Append( "Percent Group Separator: " + "<b>" + culture.NumberFormat.PercentGroupSeparator + "</b><br/>");
builder.Append( "Percent Negative Pattern: " + "<b>" + culture.NumberFormat.PercentNegativePattern.ToString() + "</b><br/>");
builder.Append( "Percent Positive Pattern: " + "<b>" + culture.NumberFormat.PercentPositivePattern.ToString() + "</b><br/>");
builder.Append( "Percent Symbol: " + "<b>" + culture.NumberFormat.PercentSymbol + "</b><br/>");
builder.Append( "Per Mile Symbol: " + "<b>" + culture.NumberFormat.PerMilleSymbol + "</b><br/>");
builder.Append( "Postive Infinity Symbol: " + "<b>" + culture.NumberFormat.PositiveInfinitySymbol + "</b><br/>");
builder.Append( "Positive Sign: " + "<b>" + culture.NumberFormat.PositiveSign + "</b>");
Literal1.Text = builder.ToString();

Sources