Globalization and Localization in C#


Introduction

Globalization is the process of designing and developing applications that function for multiple cultures.

Localization is the process of customizing your application for a given culture and locale.

Cultures and Locales

The language needs to be associated with the particular region where it is spoken, and this is done by using locale (language + location). For example: fr is the code for French language. fr-FR means French language in France. So, fr specifies only the language whereas fr-FR is the locale. Similarly, fr-CA defines another locale implying French language and culture in Canada. If we use only fr, it implies a neutral culture (i.e., location neutral).

Set culture information

Application level -In web.config file

<configuration>
  <
system.web>
    <
globalization culture="fr-FR" uiCulture="fr-FR"/>
 
</system.web>
</configuration>


web-config.gif

 
Resource Files

  1. A resource file is an XML file that contains the strings that you want to translate into different languages or paths to images.
  2. The resource file contains key/value pairs. Each pair is an individual resource. Key names are not case sensitive.

e.g. A resource file might contain a resource with the key Button1 and the value Submit
Resource files in ASP. NET have an .resx extension. At run time, the .resx file is compiled into an assembly.

Global Resource Files

  1. You create a global resource file by putting it in the reserved folder App_GlobalResources at the root of the application.
  2. Any .resx file that is in the App_GlobalResources folder has global scope.


app-global.gif

 
Local Resource Files

A local resources file is one that applies to only one ASP. NET page or user control (an ASP. NET file that has a file-name extension of .aspx, .ascx, or .master).

applocal.gif


Implicit Localization with Local Resources

  1. If you have created local resource files for a specific page, you can use implicit localization to fill the property values for a control from the resource file. In implicit localization, ASP.NET reads a resource file and matches resources to property values.
  2. To use implicit localization, you must use a naming convention for resources in the local resource file that uses the  pattern: meta:resourcekey

Explicit Localization

  1. Alternatively, you can use explicit localization, where you use a resource expression. Unlike implicit localization,   you must use a resource expression for each property that you want to set.
             
    <asp:Button ID="Button1" runat="server" Text="Button" Text="<%$ Resources:WebResources, Button1Caption %>" />

Localizing Static Text

  1. If a page includes static text, you can use ASP.NET localization by including it in a Localize control, and then using explicit localization to set the static text. The Localize control renders no markup; its only function is to act as a placeholder for localized text.
  2. The Localize control can be edited in Design view, not only in the property grid. At run time, ASP.NET treats the Localize controlas a Literal control.

      <asp:Localize ID="l1" runat="server" Text="Welcome!" meta:resourcekey="button1" />

Get Resource value programmetically


Label3.Text = Resources.Resource.b1;
Label3.Text = GetLocalResourceObject("Button1.Text").ToString();
Label3.Text = GetGlobalResourceObject("resource", "color");

Example

Create a Multi-Lingual Site with Localization

Web page


Step 1
 Drag a button and Label
Step 2 Right click on web site- Add ASP.NET Folder - Add App_Local Resource -Select -
Step 3 Right click on  Add New item - Resource File - Name (Default.aspx.resx)- Name (Button1.Text)- Ok / Label1.Text-English-Copy the RESX file and Paste it
Step 4 Rename it - (Deafult.aspx.fr.resx)- edit it..(Button1.Text)- Namaste / Label1.Text- French.

.aspx page

<asp:Button meta:resourcekey="button1" />
<asp:Label meta:resourcekey="label1" />

Header

<%@ Page Language="C#"  CodeFile="Default.aspx.cs" Inherits="_Default" Culture="Auto:en-US" UICulture="Auto" %>

Next.. Right cilck on web site- Add ASP.NET Folder - Add App_GlobalResources - Add Resource - Name and Value
copy and paste and rename (Resource.fr.resx)-

Now drag a new label :- label id(name)-renamecopypaste- expression - text - expression type=resource- expression property=class key=resource
Resource key-welcome

FOR LANG TRANSLATION 

http://code.google.com/intl/fr/apis/language/transliterate/v1/getting_started.html