Sitefinity ASP.NET CMS - Content Management System

KB Article

Home >  Support >  Knowledge Base >  KB Article
Enabling localization and globalization in Sitefinity - ID#1017
Rating: Not rated
Last Modified: 6/19/2008
Related categories: Localization;

Article information

Article relates to

 3.x

Created by

Joseph Anderson, MCP 

Last modified by

 Rebecca


Introduction

Our modules have a series of public controls that are available in the Sitefinity toolbox. Each public control consists of two parts: compiled code and markup file with an .ascx extension and these files (a.k.a. templates) are mostly a collection of ITextControl components, such as labels and literal controls. Rather than adding a value to the text properties, the text field is bound to a localization file which controls its value. This setup makes localizing public controls possible. 
This article shows how to localize the Blog Posts control in Italian. It also shows how to change the date format to Italian for every page in your application using globalization. Since this article is written for software developers with limited experience with localization and globalization, it will also give a high level overview on how to localize pages in .NET 2.0. 

How to localize an .aspx page in a regular .NET application

Here is an example localization setup of an .aspx page in Italian:
1. Create a new web application.
2. Place a label control on the default.aspx page and do not change any properties.
3. From the Visual Studio 2005 menu in design mode, go to Tools > Generate Local Resource.
4. Create App_LocalResources folder under the application root. 
5. Copy the ~/App_LocalResources/default.aspx.resx file and rename it do default.aspx.it.resx.
6. Open default.aspx.it.resx file.
7. Change the text and tooltip properties to “Italiano” as shown below:



When your page is viewed in a browser with Italian set as the default language, the label will appear with the text and tooltip “Italiano.” 

Localizing Sitefinity Module pages

Before you can work with localization with Sitefinity, you must enable localization following these instructions:
Localizing Sitefinity

Then you need to add Italian as a culture as shown below:

<localization defaultProvider="Sitefinity"   
persistenceMode="PathPrefix"   
defaultCulture="en"   
cultures="en, es, fr, de, bg, it"

In this example, we are going to localize the Blogs module. The public blog templates are located in the ~/Sitefinity/ControlTemplates/Blogs folder. We’ll  localize the word “Tags” in the ContentViewItemList.ascx template to read “Italian Tags” when Sitefinity is in Italian.  The ContentViewItemList.ascx corresponds to the Blog Posts control from the toolbox.

Here is what the blog page looks like when the Blog Posts control is placed on a Sitefinity page:

Blog Posts public control

On the page, there is also a Language Selector control:


 
If you open any user control page, you will notice that all controls inheriting from the ITextControl Interface have their text properties stored in localization files. Here is a code snippet from the Blog Posts control:

<asp:Literal ID="TagsLiteral" runat="server" Text="<%$Resources:Tags %>" />   
 

The App_LocalResources folder has already been created and the localization files are in the folder for English only. The localization file we need in this example is contentviewitemlist.ascx.resx.

Here is how to change the text for Italian users:
1. Copy the contentviewitemlist.ascx.resx file.
2. Rename the copy to contentviewitemlist.ascx.it.resx (the language abbreviation comes before the .resx extension).
2. Locate “Tags” under the name column.
3. Change its value property to “Italian Tags.” In a real application, you would translate this phrase appropriately.
4. Save the file.

Now, you need to create a page in Italian. To do so, follow these steps:
1. At the Pages tab, select Italian as shown below:

Create Italian version of the page
 
2. At the Page Properties tab, in the Menu label field, enter “Italian Blog” and save the changes.
3. Copy the template, theme and controls from the English language version of the page following the Copy from another language version link.
4. Publish the page.
5. Click View page in a new window.
6. Select Italian in the Language Selector dropdown.

You should see “Italian tags” at the bottom of the page as shown below:

View result

Globalization

Localization would change the words on a page, but localization would not change a background theme on the whole CMS as an example. Here is a good analogy for globalization: your country’s government would make a gasoline tax for the whole country, whereas your city or town would enact a local tax for anyone living in your hometown. If your city made a law, it would only take effect in your area and not the whole state or country. While localization would be used to translate words, globalization would be used to change an entire application’s background color or the date format throughout CMS.
Here is how to change the date format of all pages to Italian:

1. Open the web.config and find the <system.web> section.
2. Add the following code:

<globalization  
      fileEncoding="utf-8" 
      requestEncoding="utf-8" 
      responseEncoding="utf-8" 
      culture="it-IT" 
      uiCulture="it-IT" /> 
 
Notice the date format has changed:

Date format changed

Useful links

For more information on localization and globalization, please read Scott Guthrie’s blog post:
ASP.NET 2.0 Localization 

Here is a link where you can check culture names and identifiers:
CultureInfo Class



Article Comments

There are no comments yet.
Please Sign In to rate this article or to add it to your favorites.