Globalized Web Applications & ASP.NET
by Max Poliashenko and Chip Andrews 

Listing One
(a)
<INPUT  type=text value= <%=GetString(unTranslatedString ) %>>

(b)
Response.Write("<SELECT>")
   For Each row In myRecordset
       Reponse.Write("<OPTION")
       If myRecordset!ID.value = oldSelection Then
           Response.Write(" SELECTED>")
       Else
           Response.Write(">")
       End If
       Response.Write(GetLocalizedString(myRecordset!MyField.value)&
               "</OPTION>")
   Next
   Response.Write("</SELECT>")


Listing Two
(a)
public class GlobalizedLabel : System.Web.UI.WebControls.Label
{
protected override void Render(HtmlTextWriter output)
    {
        output.Write(Translator.GetLocalizedString(Text));
    }
}

(b)
Translator.GetLocalizedString("The amount of ")) + price.ToString() +
   Translator.GetLocalizedString(" will be charged to your account."));

(c)
(new StringBuilder()).AppendFormat("The amount of {0:C} will be
                                   charged to your account.", price);

(d)
<%@ Page language="c#" %>
<%@ Register TagPrefix="glb" NameSpace="GlobalControls"
                                         Assembly="GlobalComponents"%>
<HTML>
<BODY>
<glb:GlobalizedLabel id=lblGlobal runat=server>Test Label
</glb:GlobalizedLabel>
</BODY>
</HTML>


Listing Three
/// <summary>
/// Validation messages are translated
/// </summary>
public class GlobalizedRequiredFieldValidator : RequiredFieldValidator
{
   protected override void Render(HtmlTextWriter output)
   {
    Text = Translator.GetLocalizedString(Text);
    ErrorMessage = Translator.GetLocalizedString(ErrorMessage);
    base.Render(output);
   }
}
 ... etc.
public class GlobalizedValidationSummary : ValidationSummary
{
   /// <summary>
   /// This header will be translated
   /// </summary>
   public new string HeaderText
   {
    get{return base.HeaderText;}
set{base.HeaderText = Translator.GetLocalizedString(value);}
   }
}


Listing Four
<%@ Page language="c#" %>
<%@ Register TagPrefix="glb" NameSpace="AspNetDemo.Components"
                                              Assembly="Components"%>
<HTML>
<HEAD>
    <meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
</HEAD>
<body bgColor="#e4e4e0">
  <h3 align="center">User Information</h3>
  <form id="Form2" method="post" runat="server">
    <glb:GlobalizedValidationSummary id="vSummary" runat="server"
    headertext="The following validation errors occurred:" />
    <hr>
    <table cellSpacing="0" cellPadding="0" width="100%" border="0">
      <tr>
        <td width="30%">Name</td>
        <td>
          <asp:textbox id="txName" runat="server"></asp:textbox>
          <glb:GlobalizedRequiredFieldValidator id="rfValidator1"
                                          runat="server" display="dynamic"
          controltovalidate="txName" ErrorMessage="Name is required."
                                                         Text="required" />
        </td>
      </tr>
      <tr>
        <td>Password</td>
        <td>
          <asp:textbox id="txPassword" TextMode="Password"
                            runat="server"></asp:textbox>
          <glb:GlobalizedRequiredFieldValidator id="rfValidator2"
                            controltovalidate="txPassword" runat="server"
          ErrorMessage="Password is required."
                            Text="minimum 5 characters" display="dynamic" />
       </td>
      </tr>
      <tr>
        <td>Confirm password</td>
        <td>
          <asp:textbox id="txPasswordConf"
                                  TextMode="Password" runat="server" />
          <glb:GlobalizedCompareValidator id="cmpValidator1"
                                  runat="server" display="Dynamic"
          controltovalidate="txPasswordConf"
                      ErrorMessage="Passwords don't match. Please, re-enter."
          ControlToCompare="txPassword" operator="Equal"
                      type="String" Text="doesn't match" />
        </td>
      </tr>
      <tr>
        <td>Email</td>
        <td>
          <asp:textbox id="txEmail" runat="server"></asp:textbox>
          <glb:GlobalizedRequiredFieldValidator id="rfValidator3"
                                    runat="server" display="dynamic"
          controltovalidate="txEmail" ErrorMessage="Email is required."
                                     Text="required" />
          <glb:GlobalizedRegularExpressionValidator id="EmailRegValidator"
          validationexpression="\w+@\w+\.\w+" runat="server"
          ErrorMessage="Email format is invalid.
                             " controltovalidate="txEmail" display="static">
          user@domain.ext</glb:GlobalizedRegularExpressionValidator>
        </td>
      </tr>
      <tr>
        <td>Age</td>
        <td>
          <asp:textbox id="txAge" runat="server"></asp:textbox>
          <glb:GlobalizedRangeValidator id="rngValidator1"
                                  runat="server" controltovalidate="txAge"
          MinimumValue="1" MaximumValue="199" Type="Integer"
                                  ErrorMessage="Age is invalid."
          display="static" Text="0 < age < 200" />
        </td>
      </tr>
      <tr><td>&nbsp;</td></tr>
      <tr>
        <td align="middle" colSpan="2">
          <glb:GlobalizedLinkButton id="btUpdate"
                                  runat="server" Text="Update" />
          &nbsp;
          <glb:GlobalizedLinkButton id="btCancel"
                                  runat="server" Text="Cancel">
          Cancel</glb:GlobalizedLinkButton>
        </td>
      </tr>
    </table>
  </form>
</body>
</HTML>


Listing Five
/// <summary>
/// Button that pops client-side dialog to confirm the action. It exposes
/// ConfirmMessage property to set its dialog message with "Are you sure?"
/// being a default. It relies on GlobalizedButton class to translate
/// its Text and ToolTip properties.
/// </summary>
public class GlobalizedConfirmButton : Button
{
private string m_ConfirmMsg = "Are you sure?";
    /// <summary>
    /// Message will be translated and displayed in confirmation dialog box.
    /// </summary>
    public string ConfirmMessage
    {
        set{m_ConfirmMsg = value;}
    }
    /// <summary>
    /// Renders HTML and client javascript for confirmation box
    /// </summary>
    /// <param name="output"></param>
    protected override void Render(HtmlTextWriter output)
    {
if (Page.Request.Browser.JavaScript == true)
{
  output.WriteLine(@"<script id='clientConfirmation'
language='javascript'><!--
            function RUSure()
{if (confirm('" + Translator.GetLocalizedString(m_ConfirmMsg)
 + @"')) return true;else return false;}
            //--></script>");
  Attributes.Add("onclick","return RUSure();");
        }
        Text = Translator.GetLocalizedString(Text);
        base.Render(output);
}
}


Listing Six
decimal d = 1234.556M;
d.ToString("C",new System.Globalization.CultureInfo("nl-NL"));


Listing Seven
<configuration>
    <system.web>
        <globalization
responseEncoding="utf-8"
requestEncoding="utf-8"
fileEncoding="utf-8"
culture="en-CA"
uiCulture="de-DE"
/>

    </system.web>
</configuration>


Listing Eight
<%@ Page language="c#" Culture="ru-RU" ResponseEncoding="utf-8" %>


Listing Nine
/// <summary>
/// Page sets its Culture according to the user profile
/// to affect all the formatting on this page
/// </summary>
public class LocalizedPage: Page
{
   public LocalizedPage()
   {
       this.Culture = Utility.GetUserContextCulture();
   }
}

Listing Ten
System.Threading.Thread.CurrentThread.CurrentUICulture =
new System.Globalization.CultureInfo("de-DE");


