| |
|
How to store information about a user's locale in ASP.NET? What is localization?
Localization is the feature of ASP.NET through which an application may be localized
for a specific location. There are built-in mechanisms in .NET to allow localization process.
The concept of localization is achieved in .NET as .NET is based on Unicode, thus it
allows multiple characters of regions across the globe to be sent across in applications.
In .NET, the concept of localization is achieved using the System.Globalization
namespace. A class named CultureInfo is used to localize .NET objects in
the web applications. The functions provided in the globalization namespace work in tandem
with the browswer's culture encoding properties. In order to set the culture encoding
of a web application, changes may simply be done in the web.config file.
<configuration>
<system.web>
<globalization
requestencoding="utf-8"
responseencoding=" utf-8"
fileencoding=" utf-8"
culture="hi-IN"
uiculture="en" />
</system.web>
</configuration>
Here, the default culture is set to Hindi (hi-IN). However, the rest of the
web application will use UTF8 character encoding. The default UI culture is "en"
by default. Now in order to render different locality specific characters
for different locations, different folders with their own Web.config files are
created. Each of this folder will cater to a location. Note that in ASP.NET, a web.config
file is allowed on any folder, this web.config file will override any settings
provided in the web.config of any of its parent folder.
This is how locale specific directories are created for a site. Further note that
culture settings may be set at page level as well. This is done using the @Page directive
by setting its culture attribute to the desired culture.
<%@ Page Culture="hi-IN" UICulture="hi" ResponseEncoding="utf-8"%>
Instances of the CultureInfo class may also be created in code, to set the culture
of a page through code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| |