Get languages and culture to website?

  • Thread starter Thread starter trint
  • Start date Start date
T

trint

what is the best way to make a .net (english) website viewable in other
languages, cultures?
Thanks,
Trint
 
Hi Trint,

IMO, Satellite Assemblies is the best way. Here's a quick description of
what you need to do. I hope I didn't leave anything out.

In your Page_Load set Thread.CurrentThread.CurrentUICulture to
Request.Languages[0]. Then create a Satellite assembly for each locale you
want to use. Alternatively, you could set CurrentUICulture from where the
user selects a culture out of a list. Additionally, set
Thread.CurrentThread.CurrentCulture for globalization format settings such
as numbers, date/times, and currency.

In VS.NET create a *.resx file for each locale you want to support. Name
each one <YourAppName>.<locale>.resx (locale is case sensitive). When you
compile, VS.NET will create sub-directories for each satellite assembly.
The CLR is smart enough to know which directory to look at, based on the
culture you set CurrentUICulture to. Use the ResourceManager class to
extract strings based on a Name/Value pair you added to your resx files.

http://msdn.microsoft.com/library/d...emresourcesresourcemanagerclassctortopic3.asp

For example, given the following:

1. My browser's locale is set to "en-US".
2. My Apps default namespace is set to "MyNamespace" (configurable through
project properties)
3. My App name is "MyAppName" (configurable through project properties)
4. I added a resx file to my project named "MyAppName.en-US.resx"
(available via Add New Item Wizard)
5. I added a name/value pair of "HelloKey" and "Hello C#!" to my resx file,
respectively.
6. The following code would emit "Hello C#!" at the top of my response
stream.

Thread.CurrentThread.CurrentUICulture = new
CultureInfo(Request.UserLanguages[0]);

ResourceManager rm = new ResourceManager("MyNamespace.MyAppName",
Assembly.GetExecutingAssembly());

string greeting = rm.GetString("HelloKey");

Response.Write(greeting);


Joe
 
Joe,
Will this make everything on the website, let's say - in Korea, Korean
language and likewise in other countries with just what you gave in your
example? It's very important that it does.
Thanks,
Trint

.Net programmer
(e-mail address removed)
 
No. What you can do is the check the language preference of the browser or
check the clients ip address and depending on the result change the culture.

Gabriel Lozano-Morán
 
Back
Top