This articles explains the concept of Localization, Globlization, Resources, Satelite Assembly etc for developing Multi-lingual ASP.Net.
Introduction:
Developing Multi-lingual Web Application we first need to
understand the concept behind multi-lingual.
As per name we can say that it should support various languages
to display its web contents and stores data in various languages.
- Understanding Globalization, Localization and Culture
- Resources
- Local Resources, Global Resources and Satellite Assemblies
- Implementing Internalization
.Net provides concepts of Globalization and localization
for it, so first understand it.
Understanding Globalization:
Globalization is process of identifying all the
localizable resources in the application that will support multiple cultures.
Ideally it is performing during design phase of an application, so that the resources
always remain separate from the code.
Understanding Localization:
In Localization you customize the application for new
locales. This consists of translating resources that you identified during the
globalization phase.
Difference between Localization and Globalization:
Globalization is process of identifying how many resources
needs to be localized to adopt a multiple culture support, while Localization
is actual process of translating resource to a specific culture. So
Localization is the part of Globalization.
Culture:
Culture means geographical location which identify group
of people having same type interest, life style, language etc.
As for Example:
Hi-IN - indication Hindi spoken at India.
En-US - indication English spoken at United States.
En-GB - indication English spoken at Great Briton.
Resource Files:
Microsoft .Net provides .resx files to support
Globalization concept.
Resource file is xml format file having key-value pair for
resource.
Resource files consists of user interface data, like
texts, logos, images etc resources.
Example:
English - Hello, good morning.
Hindi- ????,
??? ????????
You can not use any special character in key pair.
Local Resources:
Local Resource is xml based file, which stores resources
with local scope into App_LocalResource directory. We can not access one pages
local resource from another page.
They can be generated by ASP.Net automatically. For it go
to design view of aspx page and then Tools > Generate
Local Resource.
Way 1:
<asp:Button ID="Button1" runat="server" Text="<%$Resources: MyLocalResourcekey1%>" />
Way 2:
Button1.Text = GetLocalResourceObject("MyLocalResourcekey1").ToString();
Global Resources:
Global Resource is also xml format file, used to store
resources globally, means we can access same resource from different pages. It
store in App_GlobalResource folder.
As like Local Resource we can not generate it
automatically.
Way 1:
<asp:Button ID="Button1" runat="server" Text="<%$Resources:MyGlobalResourceClass, MyGlobalResourcekey1%>" />
Way 2:
Button1.Text = GetGlobalResourceObject("MyGlobalResourcekey1").ToString();
Way 3:
Button1.Text = Resources. MyGlobalResourceClass. MyGlobalResourcekey1;
Local Resource vs. Global Resource:
1. Performance: Global Resources are faster than Local
Resource- because Global Resources are Strongly Typed.
2. Data Consistency. Explanation: In your
application you have Label Text as Category and ten pages. Now you want to
change it to CATEGORY then if you using Local Resource concept then you have to
change 10 resource files, where as in Global Resource you need to change only
one.
3. Difference as per Project Type:
a. ASP.Net Website (Microsoft Visual Studio’s
default type):
i.
Local Resource is treated as
content based resource, so we can change it and it affects to website.
ii.
Global Resource is treated as
embedded resource, So they are compiled into specific language dlls into bin
folder.
b. ASP.Net Web Application
i.
Both Local and Global resource
are treated as content based resource, so both are editable.
Any change in any type of
resource cause whole resource compilation.
Satellite Assemblies:
Assembly containing no
executable code—only resources. Typically, satellite assemblies are used for
storing localized data. Satellite assembles can be added, modified, and loaded
into a .NET application at runtime without recompiling. Use the Assembly
Linking Utility to create satellite assemblies by compiling .resource files.
It reduces the overhead of
compiling resources and makes application faster.
Step 1: Creating
Compile resource files (.resource)
Use “resgen.exe” tool to create Compile resource files (.resource) from resource file (.txt or
.resx).
Command line:
resgen myresource.resx
Step 2: Creating
Satellite Assemblies(.dll)
Use following AL commandline to
create .dll
AL /t:lib /culture:en-US /embed: myresource.en-GU.resources /out: myresource.resources.dll
Where,
/t
switch tells that the output is of type library (DLL),
/culture
switch tells that the resources being embedded in the assembly are for en-US
culture.
/embed switch specifies the
.resources file that is to be embedded in the Satellite Assembly,
/out
switch specifies the name of output assembly.