home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / aspplus / doc / localizingapps.aspx < prev    next >
Encoding:
Text File  |  2000-06-07  |  5.1 KB  |  176 lines

  1. <%@ Register TagPrefix="Acme" TagName="SourceRef" Src="/quickstart/util/SrcRef.aspx"%>
  2.  
  3. <!-- #include virtual="/quickstart/aspplus/include/header.inc" -->
  4.  
  5. <h4>Localizing ASP+ Applications</h4>
  6.  
  7. <div class="indent" style="font-family:Verdana; font-size:8pt;">
  8.     <b> <img align="middle" src="/quickstart/images/bullet.gif">  </b>
  9.     <a class="toc2" target="content" href="#copy">Copy and Translate</a><br>
  10.     <b> <img align="middle" src="/quickstart/images/bullet.gif">  </b>
  11.     <a class="toc2" target="content" href="#embed">Common Components</a><br>
  12. </div>
  13.  
  14. <p>
  15. <hr>
  16.  
  17.  
  18. <!--BEGIN SECTION-->
  19. <a name="copy">
  20. <span class="subhead">Copy and Translate</span>
  21. <p>
  22.  
  23. The easiest way to localize web pages is usually
  24. to create a copy and translate it to the target language. 
  25. This works fine for static content, which does not require
  26. a lot of maintenance. To support this model for ASP+ pages 
  27. the <b>Culture</b> attribute can be set on the
  28. Page directive. All locale-dependent methods will pick
  29. up the value of the Culture attribute.
  30. <p>
  31. The following sample shows this in three independent, 
  32. localized versions of a page. 
  33. On each page the Culture property is set, which determines 
  34. the format of the date:
  35.  
  36. <div class="code"><pre>
  37. <%@Page Culture="de" Language="C#" %>
  38. ...
  39. <%=DateTime.Now.Format("f", null)%>
  40. </pre></div>
  41. <p>
  42.  
  43. <table>
  44. <tr>
  45. <td>
  46. <Acme:SourceRef 
  47.   RunSample="/quickstart/aspplus/samples/localize/localize1/news-en-us.aspx" 
  48.   ViewSource="/quickstart/aspplus/samples/localize/localize1/news-en-us.src"
  49.   Icon="/quickstart/aspplus/samples/localize/flags/en-us.jpg"
  50.   Caption="news-en-us.aspx"
  51.   runat="server" />
  52.  
  53. </td>
  54. <td>
  55. <Acme:SourceRef
  56.   RunSample="/quickstart/aspplus/samples/localize/localize1/news-de.aspx" 
  57.   ViewSource="/quickstart/aspplus/samples/localize/localize1/news-de.src" 
  58.   Icon="/quickstart/aspplus/samples/localize/flags/de.jpg"
  59.   Caption="news-de.aspx" 
  60.   runat="server" />
  61. </td>
  62. <td>
  63. <Acme:SourceRef
  64.   RunSample="/quickstart/aspplus/samples/localize/localize1/news-ja.aspx" 
  65.   ViewSource="/quickstart/aspplus/samples/localize/localize1/news-ja.src" 
  66.   Icon="/quickstart/aspplus/samples/localize/flags/ja.jpg"
  67.   Caption="news-ja.aspx" 
  68.   runat="server" />
  69. </td>
  70. </tr>
  71. </table>
  72.  
  73.  
  74.  
  75.  
  76. <!--BEGIN SECTION-->
  77. <br>
  78. <a name="embed">
  79. <br>
  80. <span class="subhead">Localizing and Embedded Controls</span>
  81. <p>
  82.  
  83. An improvement over the simple copy and translate approach is to
  84. use controls, which pick up the culture of the main page. In this sample
  85. the image of the flag and the search bar are controls. Depending
  86. on the culture of the hosting page they render different content.
  87. To support this the <b>UICulture</b> attribute was also added to each page:
  88. <div class="code"><pre>
  89. <%@Page Culture="de" UICulture="de" Language="C#" %>
  90. </pre></div>
  91.  
  92. <p>
  93. The flag control (flag.aspc) for example just uses the culture name to build the
  94. src attribute of an <img> tag:
  95. <div class="code"><pre>
  96. <%@Import Namespace="System.Globalization"%>
  97.  
  98. <script runat="Server" Language="C#">
  99. override protected void PreRender() 
  100. {
  101.     FlagImage.Src = "../flags/" + CultureInfo.CurrentCulture + ".jpg";
  102.     FlagImage.Alt = CultureInfo.CurrentCulture.NativeName;
  103. }
  104. </script>
  105.  
  106. <img runat="server" id="FlagImage" />
  107. </pre></div>
  108. <p>
  109.  
  110. The search control (search.aspc) uses a switch-statement to initialize the 
  111. values of a label and a textbox, but the culture name could also be the
  112. parameter for a database query:
  113. <div class="code"><xmp>
  114. void LocalizeSearchText() 
  115. {
  116.     switch(String.Intern(CultureInfo.CurrentUICulture.Name)) 
  117.     {
  118.         case "en-us": 
  119.             SearchText.Text = "Clinton";
  120.             SearchButton.Text = "Search";
  121.             break;
  122.         case "de": 
  123.             ...          
  124.         case "ja": 
  125.             ...
  126.         default: 
  127.             SearchButton.Text = "Search";
  128.     }
  129. }
  130. </xmp></div>
  131.  
  132.  
  133. <table>
  134. <tr>
  135. <td>
  136. <Acme:SourceRef 
  137.   RunSample="/quickstart/aspplus/samples/localize/localize2/news-en-us.aspx" 
  138.   ViewSource="/quickstart/aspplus/samples/localize/localize2/news-en-us.src"
  139.   Icon="/quickstart/aspplus/samples/localize/flags/en-us.jpg"
  140.   Caption="news-en-us.aspx"
  141.   runat="server" />
  142.  
  143. </td>
  144. <td>
  145. <Acme:SourceRef
  146.   RunSample="/quickstart/aspplus/samples/localize/localize2/news-de.aspx" 
  147.   ViewSource="/quickstart/aspplus/samples/localize/localize2/news-de.src" 
  148.   Icon="/quickstart/aspplus/samples/localize/flags/de.jpg"
  149.   Caption="news-de.aspx" 
  150.   runat="server" />
  151. </td>
  152. <td>
  153. <Acme:SourceRef
  154.   RunSample="/quickstart/aspplus/samples/localize/localize2/news-ja.aspx" 
  155.   ViewSource="/quickstart/aspplus/samples/localize/localize2/news-ja.src" 
  156.   Icon="/quickstart/aspplus/samples/localize/flags/ja.jpg"
  157.   Caption="news-ja.aspx" 
  158.   runat="server" />
  159. </td>
  160. </tr>
  161. </table>
  162.  
  163.  
  164. <h4>Section Summary</h4>
  165. <ol>
  166. <li>ASP+ pages support Culture and UICulture attributes to support independent localized pages.
  167. <li>Controls on pages will pick the cultures of the page and can render culture-dependent content.
  168. </ol>
  169.  
  170. <!-- #include virtual="/quickstart/aspplus/include/footer.inc" -->
  171.  
  172.  
  173.  
  174.  
  175.  
  176.