Arnoldus The Multi Language Site in C#

Multi Language Site: “Loose Strings” (Part 3.3)



This is the continuation of Part 3.2 (Multi Language Site: "Loose Phrases": Sitemap Files)


Local Resource Files

As an alternative to global resource files you can use local resource files. If you choose this option you should create a resource file for each page that you want to localize. Local resource files are stored in the “App_LocalResources” directories (if you use more than one directory to store your pages an “App_LocalResources” directory should exist in each directory where you want to localize pages).

Visual Studio 2008 is better equiped to handle local resource files than global resource files: it can create the local resource file for the default language.

NameValue
lnkPickCategoryResource1.ToolTipView blog entries on the topic of


How to make sure that what needs to be translated gets in the resource file

Resource files (both global and local) allow to localize properties of objects. Thus plain text
(e.g.: <p>Blah, blah .......</p>)
cannot be localized because it is not linked to an object (an html element like “<p>” is not an object that can be localized). The solution for this problem is the use of the “Literal” server control with the Text property set to the string that needs translation, which results in code like:


<asp:FormView ID="FormView1" runat="server" DefaultMode="Insert"
OnItemInserting="FormView1_ItemInserting" BorderWidth="0px"
CellPadding="0">
<InsertItemTemplate>
<h3><asp:Literal ID="litTitles" runat="server" Text="        Titles"
meta:resourcekey="litTitlesResource1" /></h3>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="You must give the English   title."
ControlToValidate="txtEnglishTitle" Display="Dynamic" Enabled="False"
meta:resourcekey="RequiredFieldValidator1Resource1" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="You must give the Dutch title."
ControlToValidate="txtDutchTitle" Display="Dynamic" Enabled="False"
meta:resourcekey="RequiredFieldValidator2Resource1" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ErrorMessage="You must give the Italian   title."
ControlToValidate="txtItalianTitle" Display="Dynamic" Enabled="False"
meta:resourcekey="RequiredFieldValidator3Resource1" />
<p>
<asp:Image ID="FlagUsa" runat="server"
ImageUrl="~/Images/mini_usa.gif" Height="10px"
Width="15px" />&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txtEnglishTitle" runat="server"
Width="200px" /><br />
<asp:Image ID="FlagNl" runat="server" ImageUrl="~/Images/mini_nl.gif"
Height="10px" Width="15px" />&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txtDutchTitle" runat="server" Width="200px" /><br />
<asp:Image ID="FlagIt" runat="server" ImageUrl="~/Images/mini_it.gif"
Height="10px" Width="15px" />&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txtItalianTitle" runat="server"
Width="200px" /><br />
<asp:CheckBox ID="chkIsPublic" runat="server"
Text="Make this album public"
meta:resourcekey="chkIsPublicResource1" />
</p>
<p style="text-align: right;">
<arn:DynamicButton ID="btnAdd" runat="server" CommandName="Insert"
ButtonText="add" meta:resourcekey="btnAddResource1" />
</p>
</InsertItemTemplate>
<ItemTemplate>
<asp:Literal ID="litAlbumId" runat="server" Text="AlbumID: "
meta:resourcekey="litAlbumIdResource1"></asp:Literal>
<asp:Label ID="labAlbumID" runat="server" /><br />
<asp:Literal ID="litCount" runat="server" Text="Count: "
meta:resourcekey="litCountResource1"></asp:Literal>
<asp:Label ID="labCount" runat="server" /><br />
<asp:Literal ID="LitTitleEn" runat="server" Text="English Title: "
meta:resourcekey="LitTitleEnResource1"></asp:Literal>
<asp:Label ID="labTitleEn" runat="server" /><br />
<asp:Literal ID="LitTitleNl" runat="server" Text="Dutch Title: “
meta:resourcekey="LitTitleNlResource1"></asp:Literal>
<asp:Label ID="labTitleNl" runat="server" /><br />
<asp:Literal ID="LitTitleIt" runat="server" Text="Italian Title: "
meta:resourcekey="LitTitleItResource1"></asp:Literal>
<asp:Label ID="labTitleIt" runat="server" /><br />
<asp:Literal ID="litIsPublic" runat="server" Text="IsPublic: "
meta:resourcekey="litIsPublicResource1"></asp:Literal>
<asp:CheckBox ID="chkIsPublic" runat="server" Enabled="False"
meta:resourcekey="chkIsPublicResource2" /><br />
</ItemTemplate>
</asp:FormView>


Note the statements like: meta:resourcekey="LitTitleEnResource1". These statements refer to the entries in the local resource files that contain entries for each property that can be localized like: “LitTitleEnResource1.Text”

The fragment of code above, which shows part of the page that handles the insertion of a new album in the database, references a “DynamicButton”:


<arn:DynamicButton ID="btnAdd" runat="server" CommandName="Insert" ButtonText="add"
     meta:resourcekey="btnAddResource1" />


which will be the subject of the next section of these articles. Continue to: Multi Language Site (Part 4.1): Image Buttons.