Arnoldus The Multi Language Site in C#

Multi Language Site: Page Text (Part 1.1)



Creation of table 'SiteContents' that contains the text for the pages:


Pages are bodies of text, images and other controls. Text may be in complete blocks (paragraphs), a sentence (for instance a header), or may be fragmented as a few words, descriptors, prompts etc. In the case of blocks of text, I decided to store those in a database that can also store phrases (such as headers). In the case of few phrases (for instance one page title and no paragraphs), it may be more convenient to use resource files (use the “Text” property of the “Literal” control which can be used in the resource files for each language supported), see the “Loose Strings” section for a more detailed discussion.


/****** Object: Table [dbo].[SiteContents]    Script Date: 07/15/2008 12:50:25 ******/

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[SiteContents](
      [textID] [int] IDENTITY(1,1) NOT NULL,
      [Application] [nvarchar](50) NOT NULL CONSTRAINT [DF_SiteContents_Application] DEFAULT (N'Arnoldus'),
      [Page] [nvarchar](50) NOT NULL,
      [hdr1] [nvarchar](max) NULL,
      [hdr2] [nvarchar](max) NULL,
 
 
.........
 
      [fld8] [nvarchar](max) NULL,
      [fld9] [nvarchar](max) NULL,
      [IsPublic] [bit] NOT NULL,
      [Lang] [char](2) NULL,
 CONSTRAINT [PK_SiteContents] PRIMARY KEY CLUSTERED
(
      [textID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
 
GO
SET ANSI_PADDING OFF
ALTER TABLE [dbo].[SiteContents] ADD CONSTRAINT [DF_SiteContents_Application] DEFAULT (N'Arnoldus') FOR [Application]
 
/****** Object: Index [PK_SiteContents]    Script Date: 07/15/2008 12:53:15 ******/
ALTER TABLE [dbo].[SiteContents] ADD CONSTRAINT [PK_SiteContents] PRIMARY KEY CLUSTERED
(
      [textID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

Having created the table for the storage of page text let's examine the table's layout.

  • Field: textID is the usual unique record identifier with the identity insert property enabled.
  • Field: Application; Given that certain hosting companies allow you to host more than one application in your assigned space, I created this field in most tables to allow for the use of the same table with more applications.
  • Field: Page contains a unique name for the page. Personally, I use the real names like “Defaul.aspx” or “Download/Default.aspx” as I prefer to keep things simple. However, you are free to use any name you like.
  • Field: hdrx (1 - 8) are fields intended to contain header texts (such as: “Hello World” or “What's New”).
  • Field: fldx (1 - 9) are fields intended to contain paragraphs (for instance: “Tomorrow is my birthday and my collegues promised me a birthday cake and my boss promised me a rise.”).
  • Field: IsPublic; Having the page contents stored in a database offers the possibility to enable the table for a full text search. As you may have pages that are used for management purposes or contain content that should not be seen by the general public, you can use this field to indicate whether the page should show-up in a search.
  • Field: Lang indicates the language of the record. For instance, a hypothetical page named: “Default.aspx”, could have fld1 = “Hello World” and the language field (Lang) as “en”, while another record with the same name “Default.aspx” would have fld1 with a value of “Ciao Mondo” and Lang: “it” or yet another one with “Bonjour Monde” and “fr”. There is nothing to prevent you to use this field for other purposes as well, for instance, you could create another record for the page with a name like “Default.code” and language “C#” or “Default.code” and language “VB”. Such a mechanism could then allow the user the choice to view a code fragment in “C#” or “VB” using  something like a DropDownList or a CheckBox as a selection mechanism.

Continue to: Multi Language Site: Page Text (Part 1.2): Displaying Content.