Multi-Language for ASP.Net Website Project using Satellite Assembly

By | March 15, 2013

Satellite assembly introduction

A satellite assembly is a compiled library (DLL) that contains (“localizable”) resources such as strings, bitmaps, etc. You are likely to use them when creating a multilingual (UI) application. Satellite assemblies provide you with the capability of designing and deploying your solution to multiple cultures, rather than hard coding strings, bitmaps, etc., into your main application. Satellite assemblies are used to deploy applications in multiple cultures (not languages), with 1 satellite assembly per culture – this is the default behavior, but you can obviously have more granular control if you handle the build process manually.

This is quoted from global developer blog:http://blogs.msdn.com/b/global_developer/archive/2011/07/22/introduction-to-satellite-assemblies.aspx

Here’s the instruction how to apply satellite assembly i18n for ASP.Net Website.

Install the Visual Studio Web Publish Update

Since by default, the ASP.Net Website project dose not compile all the code into one assembly, there’s no way to link the satellite assembly.

To fix that, you can download the latest Visual Studio Web Publish Update from here: http://msdn.microsoft.com/en-us/library/jj161045.aspx. Install it to your visual studio.

Configure your WebSite project

After that, you have the option to compile all the website code into one assembly like ASP.Net Web Application does:

1. Open the context menu on your project –> Publish Web Siteimage_thumb[1]

2. Create a new profile, in the Settings section, under File Publish Options menu, check Precompile during publishing.
SNAGHTML123db75_thumb[2]

3. Click Configure on the side, in the popup dialog, select Merge all outputs to a single assembly, and give the assembly a name:
SNAGHTML1257795_thumb[2]

4. Then publish the website to see if it works.
image_thumb[3]

Apply basic settings to your project

After setup the project, now let’s move the apply multi-language to the project.

1. Copy the following files to your project(from the sample project):
image_thumb[6]

2. Reference the dlls in Library folder.

3. Modify the build_lang.bat, change the assembly name according to the name you gave the project dll. Don’t forget to make the path to each culture bat correct.

4. Modify the assembly information in the bat files in each culture folder.

5. Try to run the build_lang.bat, see if dlls and resources generated in each culture folder:
image_thumb[8]

 

Apply multi-language to your page

To use multi-language, there are two ways:

1. Use multi-language enabled control.
image_thumb[11]

a. register Hon.Web to your page.
b. add HonLiteral(or HonButton, HonLabel etc) to your page.
c. Set the ResKey property to the control which the ResKey is the key the [assembly_name].[culture].txt file.

2. Get the culture string by code.
image_thumb[13]

Add language switch to your page

1. Copy the images folder from sample package to your project which contains the flags icons.
image_thumb[15]

2. Add the css to your stylesheet:

/*language bar start*/
.language-ul
{
    margin:0 10px 0 0;
    white-space: nowrap;
}

.language-li
{
    display:inline;
}

.language-li a
{
    line-height:40px;
    margin:3px;
}

.language-li a img{
    margin:-1px 2px 0 2px;
}

.language-li a:hover
{
    border-bottom:0px;
    text-decoration:underline;
}
/*language bar end*/

2. Register Hon.Web to your page.

<%@ Register Assembly="Hon.Web" Namespace="Hon.Web.UI.WebControls" TagPrefix="ct" %>

3. Add the language control to your page:

<ct:HonLanguage ID="hlLanguage" runat="server" />

4. Publish your website. (You must publish the site to see the effect because there’s no assembly generated when you build your site.)

5. Run the build_lang.bat in the bin folder.

6. Check if you can see like the following:

image_thumb[16]

You can download and play with the sample from here: http://www.jinweijie.com/download/TestI18N.zip

Enjoy!