Multiple-lanugage support in ASP.NET question

  • Thread starter Thread starter 00_CuMPe3WaR3D12
  • Start date Start date
0

00_CuMPe3WaR3D12

I know there is Culture feature with Asp.net, but what I want to know is
how to organize/design a web application that supports multiple languages.
What is the best approach? Do I use "If, then.." to display one block of
HTML in English, and then another block in French? Is there an easy way?

Also, "string" itself doesn't support multiple cultures, right? If I
write a "string" property in a class, how do I make the property support
multiple cultures?
 
I will break this down into two parts :

- fixed strings for the UI could be taken from resources files. .NET
provides support for this. You could also take those values from a DB
(likely cached) or some other location in particular if translation should
be updatable "live" by someone... You'll have support for this in .NET 2.0.
See the doc for "resources".

- I'm not really sure about what you meant by the second part. If you meant
by the "property", a "data" entered by the user there is little you can do.
Either the application insulates each group of users (for example the app
manages multiple projects using each an official language). If not, the data
model for your application will have to make provision so that users are
able to entered a localized version for each of their "data"...

Patrice
 
Hello,
This is a huge field (almost like saying "how do I make my ASP.Net app
secure?), but here are some things to get you started:
Your best bet may be to use Resource files. These are xml files of
name-value pairs that contain all the text-strings. The current culture of
the app then automatically picks which file to use.

Check out the Globalization Namespace
http://msdn.microsoft.com/library/d...en-us/cpref/html/frlrfsystemglobalization.asp

Here are some tutorials to get you started:
http://samples.gotdotnet.com/quickstart/aspplus
http://msdn.microsoft.com/library/d...en-us/cpref/html/frlrfsystemglobalization.asp
Also, "string" itself doesn't support multiple cultures, right? If I
write a "string" property in a class, how do I make the property support
multiple cultures?
Depends. If your string just returns values from the Database, then you
don't need to do anything.
If it returns something that included concentation, dates, or currency
formats, then you'll need to pass the object the current culture, and send
that into the ToString() method used to generate the strings for your
property.

HTH,
Tim
http://timstall.dotnetdevelopersjournal.com/
 
Thanks for the "resources", I will look into that.

For Property.. this is what I meant, for example I am creating a Person
class:

public class Person
{
private string _FirstName;

public FirstName(string myFirstName)
{
_FirstName = myFirstName;
}
}

In ASP.NET, string, by default doesn't support multi-languages.

Person myPerson = new Person();
myPerson.FirstName("John");

// I want to do something like this:
myPerson.FirstName("Le John", new CultureInfo("fr-FR"));
myPerson.FirstName("John", new CultureInfo("en-US"));


My solution is to implement this by using Hash Table and Methods (not using
Properties), by putting CultureInfo name as the key of hashtable. It works,
but not sure if that's the best way. What do you think? Does ASP.NET has a
better way?

public class FirstName
{
private Hashtable _FirstName = new Hashtable();

public string GetFirstName(CultureInfo myCulture)
{
return _FirstName[myCulture.Name].ToString();
}

public void SetFirstName(string myFirstName, CultureInfo myCulture)
{
_FirstName[myCulture.Name] = myFirstName;
}
}


C.P.
 
Back
Top