I want to internationalize my asp.net application. How to do this? What steps exactly do I have to follow?
See this link on creating localized resource files: http://msdn.microsoft.com/en-us/library/ms247246.aspx
Basically you create a new resource file each language/culture you want to support. Then you access the strings inside them by name in your markup pages and code behind files.
Additionally these resource files need to be in a specific folder in your project called: App_GlobalResources
Global resource files must be in the App_GlobalResources folder. If you try to create a .resx file outside of this folder, Visual Web Developer prompts you to create it in the folder.
This is a complex topic and requires a lot of work to get right, through all layers of your system.
Start here.
ASP.NET resx files which will let you configure constant strings easily, but your DB will also need to support unicode, and you'll need to do different things depending on the languages you wish to support.
Good luck, and ask questions when you have specific problems.
It's a pretty big question to be able to give you the exact steps, and there are several different approaches.
The approach we took on my most recent project (simplified) was:
- Set up a domain for each country
- Create a resource file for all the hard-coded strings (form labels etc) for each culture (en-US, de-DE, fr-FR)
- Change the Thread.CurrentCulture based on the domain the site is being accessed from - this means that all your number formats, date formats will be correct and use the correct localised resource file
Hope this helps!
See here for the Microsoft white papers on Internationalization.
1.) If you use database, then you must modify your tables. At least with adding the LCID column.
2.) Set default culture and UI culture in web.config
<system.web>
<globalization culture="cs-CZ" uiCulture="cs-CZ"/>
</system.web>
3.) Then you can set actual thread culture either in global.asax in e.g. BeginRequest event, or in base class of your page classes in InitializeCulture method
protected override void InitializeCulture()
{
string language = Request["lang"];
if (!string.IsNullOrEmpty(language))
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(language);
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
}
else
{
base.InitializeCulture();
}
}
- For static texts you can use Resources. E.g. you create Mytexts.resx where you write texts for default laguage (en-us) and then you create Mytexts.en-UK.resx for uk english and overwrite text that are different from default laguage. Then you can insert this strings in your page :
<asp:Label runat="server" Text='<%$ Resources: Mytests,WelcomeMessage %>' />
This are only briefly steps for beginning with localization, but for small pages / apllications is it sufficient.
Simply make a basepage class that will inherited from Page class, put this method in basepage class and inherit basepage class in your every aspx.cs page to acheive globalization.
protected override void InitializeCulture()
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
base.InitializeCulture();
}
set in this method whatever culuture you want, like ar-sa for arabic....