บทความอื่นๆ ในหมวดเดียวกัน



  Search Articles


    

Globalization using ASP.NET

Article By : 
 Santhi Maadhaven
Reference : 
 http://www.c-sharpcorner.com/UploadFile/Santhi.M/GlobalizationusingASP.NET11262005072116AM/GlobalizationusingASP.NET.aspx
Read/Comment : 
 3758 / 1017

Sometimes our application may need to cater content in different languages for different country users. Let us see in this article how to cater different contents based on the culture using Globalization in ASP.NET.

Globalization is the process of designing and developing a software product that function for multiple cultures. A web forms page have two culture values ,Culture and UICulture. Culture is used to determine culture dependent function such as Date, Currency. So it is used for date formatting ,number formatting. UICulture values is used to determine which language the resources should load that is which UIstring the resource should use. The two culture settings do not need to have same values. It may be different depending on the application.

Setting Culture and UICulture

1. Through Web.Config

<

configuration>
<
system.web>
<
globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8" culture="en-US" uiCulture="fr-FR"/>
system.web>
configuration>


 

2. In Code-inline (aspx) Page

<%@ Page UICulture="fr" Culture="en-US" ....%>

 

3. In Code-Behind (aspx.cs) Page

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture ("fr-FR");
Thread.CurrentThread.CurrentUICulture=

new CultureInfo("fr-FR");

ASP.NET wont automatically translate the contents in one language to another language by using Culture. For this we need to put strings in resources file and have to load the strings based on the culture. Let us see how to create resources and use.

Resources

Resources represents embedded data such as strings or images, which can be retrieved during runtime and displayed in the user interface. Resource Management is a feature of .NET framework which is used to extract localized element from source code and to store them with a string key as resources . At runtime, ResourceManager class instance is used to resolve key to the original resource or localized version. Resources can be stored as an independent file or part of an assembly.

ResourceWriter and resgen.exe can be used to create .resources file. To include .resources file inside an assembly use related compiler switch or Al.exe.

Create Resource Text Files:

In resource.en-US.txt
Test = Hello there, friend!

In resource.fr-FR.txt
Test = Bonjour là, ami!

Generate .resources file:

Goto VisualStudio.Net command prompt and use resgen command utility to generate .resources file

resgen resource.en-US.txt
resgen resource.fr-FR.txt

This commands will create .resources file.

In TestGlobalization.aspx Page,asp:RadioButtonList id="RadioButtonList1" style="Z-INDEX: 101; LEFT:144px; POSITION: absolute; TOP: 144px" runat="server" AutoPostBack="True">
<
asp:ListItem Value="en-US" Selected="True">Englishasp:ListItem>
<
asp:ListItem Value="fr-FR">Frenchasp:ListItem>
asp:RadioButtonList>

In TestGlobalization.aspx.cs Page,on Page_Load Event

CultureInfo objCI =

new CultureInfo ( RadioButtonList1 .SelectedValue .ToString ()) ;
Thread.CurrentThread.CurrentCulture = objCI;
Thread.CurrentThread.CurrentUICulture = objCI;
ResourceManager rm = ResourceManager .CreateFileBasedResourceManager ("resource", Server.MapPath("resources") + Path.DirectorySeparatorChar,
null);
Response.Write( rm.GetString("Test"));

This will output the content based on the option selected. Hope this article would have helped you all.

<

Comment :  1 12/6/2551 13:18:37
zNIx1S woiibrytqmly, [url=http://slakgtkvaffy.com/]slakgtkvaffy[/url], [link=http://ubvladxsralc.com/]ubvladxsralc[/link], http://ssdntybhemik.com/
  By :  XgaiTJkbgiiQ
Comment :  2 23/6/2551 23:46:36
  By :  bdsxUySqtHivecig
Comment :  3 7/7/2551 21:13:41
  By :  xaNZLjhywIflmuzf
Comment :  4 15/7/2551 9:21:06
  By :  hFxjynniwpLYMvGocn
Comment :  5 15/7/2551 9:21:22
  By :  hFxjynniwpLYMvGocn
Comment :  6 15/7/2551 9:22:12
  By :  hFxjynniwpLYMvGocn
Comment :  7 27/7/2551 19:01:10
eWig3I kflqcijqxjyz, [url=http://bepmgeztgvoy.com/]bepmgeztgvoy[/url], [link=http://rqlhoroiyvgo.com/]rqlhoroiyvgo[/link], http://tbytkwpvpbhs.com/
  By :  iXjsWKkslePwoiRnS
Comment :  8 1/8/2551 6:28:50
moi j arrive pa le lava l1, sample private party event contract, lzhu,   By :  ywrzzIjwosfPwFOjLh
Comment :  9 1/8/2551 15:49:22
  By :  cmTfohwxWRkUWwfUZ
Comment :  10 1/8/2551 17:40:44
  By :  tmowzcwBviIDdmXuBV
Comment :  11 2/8/2551 14:50:34
  By :  hjLxftlxohON
Comment :  12 3/8/2551 10:09:56
  By :  hHknHOlVoTNaDW
Comment :  13 3/8/2551 13:36:39
com Leave a guestbook entry or perhaps email me & we can exchange updates, silver, 900,
  By :  ZutncjyJLU
Comment :  14 3/8/2551 14:48:43
  By :  Kelvin
Comment :  15 3/8/2551 15:01:50
  By :  uNQdpQCsSjlsBXWAz
Comment :  16 3/8/2551 16:40:24
  By :  RZeANCsFfxszIrhUxU
Comment :  17 6/8/2551 10:01:28
well, I like thise place. diamond More or less nothing seems worth bothering with. diamond, See you at the latest at Le Mans.
  By :  McOxqegwSbODYpZGHTA
Comment :  18 7/8/2551 2:12:47
Wery well! I have met many people throughout my life who have shown courage and determination such as yours and this has always made me feel very humble necklace ma be necklace<
  By :  guLKOJvEwXusEPnUDt
Comment :  19 7/8/2551 3:58:56
Hello, im from Space. What a wonderful way to start the New Year with hope and inspiration jewelry Lets talk about jewelry, Keep up the good work!
  By :  UabVNcAvNkECHOr
Comment :  20 7/8/2551 5:24:53
  By :  DitUYdyBpSjKtt
Comment :  21 7/8/2551 5:25:24
  By :  DitUYdyBpSjKtt
Comment :  22 7/8/2551 6:16:20
  By :  yrnEojEu
Comment :  23 7/8/2551 7:55:38
  By :  HZKcgtftNwJzUHzZad
Comment :  24 7/8/2551 10:20:35
  By :  TFOLXfDOfj
Comment :  25 7/8/2551 13:39:04
GCOijz zvrlsddvejfn, [url=http://bcppxlfkchkc.com/]bcppxlfkchkc[/url], [link=http://jnapnqeijwjt.com/]jnapnqeijwjt[/link], http://omzjtddegmgh.com/
  By :  ahPoKQDFMciaZcH
Comment :  26 8/8/2551 13:13:59
Perfect site! Your is, as you say, a very difficult situation, especially until one goes through all of the grief process jewelry its funny jewelry in,   By :  YnDLecMOeHgQhxDVDH
Comment :  27 8/8/2551 13:14:02
Perfect site! Your is, as you say, a very difficult situation, especially until one goes through all of the grief process jewelry its funny jewelry in,   By :  YnDLecMOeHgQhxDVDH
Comment :  28 8/8/2551 21:26:45
  By :  gtMPxPFDuldmmq
Comment :  29 8/8/2551 21:27:21
  By :  gtMPxPFDuldmmq
Comment :  30 8/8/2551 23:25:25
Hello my little friends. I want to say - thank you for this! watch Excellent work watch sugar, watch them,   By :  PJSjlcVGGyYLYNTxzp

Your comment
 
Your name