Posted by: lornecjones | April 20, 2009

Steps to Localizing your Web Site With Resources

Steps for Converting an Application to be Translated using Resources Files and Master Page

1. Generate Local Resources
a. Note: Some local resources may not generate if converted to a newer visual studio and / or within a panel. Must check each one on the page in HTML Source View in Visual Studio.
b. Add any non generated resource file strings to Local Resources.
2. Update the cs file to include the following code:

string CurrentURL = Request.ServerVariables["HTTP_Host"].ToString();
//string CurrentURL = “www.mmm.de”;
//Intialize Country code
string countrycode = “”;

//Intialize CountryTrans .dll
CountryTrans.Country trans = new CountryTrans.Country();

//get country from CountryTrans .dll
countrycode = trans.GetCountrybySite(CurrentURL);
Session["countrycode"] = countrycode;
// //Set the CultureInfo to generic countrycode, which will be used throughout application to switch text to correct language
Thread.CurrentThread.CurrentUICulture = new CultureInfo(countrycode);
Thread.CurrentThread.CurrentCulture = new CultureInfo(countrycode);

3. Add the following .dll “CountryTrans.dll”
4. Make a global resource folder by right-clicking project and add “ASP.NET Folder” Global Resource folder
5. Add Global resource file to the Global Resource folder (such as “grs.resx”)
6. This file will serve all cs file text strings that will display to user. Such as error text, labels that are initialized within the cs file, etc.
7. To replace text you can use the following:
a. String OnpageError.Text = (String)GetLocalResourceObject(“OnpageErrorResource1.Text”).ToString(); -use for LocalResources

Or for Global strings

b. (String)GetGlobalResourceObject(“”,” ”).ToString();
i. Tip – Global resources can be reused…
8. Once complete, copy the local resource file and make a copy with the culture desired as an internal extension within the file name of the new resource file. For example, if German is desired, then copy the original “Default.aspx.resx” and change pasted file to “Default.aspx.de.resx”…repeat for each culture desired for translation.
9. Do the same for the global resource file as well. (For example, “gsr.de.resx” for German)
10. Then once done, change the domain on page load to test that German (or some other language(culture) will replace the text). It is important to note that, the German strings in the resource files must also, be changed to the German text to have an accurate test. Run the page with that url and the text should be replaced).

To add a master page that was added to a GAC, do the following:

1. Add the web config values (assembly, and connection string for the master page if necessary)
2. Create a child master and add the Master page CSS to the child page. Then move any css links and/or javascript links to the child page(s). For example:

3. Add the masterpage .ddl to the project as a reference
4. Add the following sections (in yellow) to the web config:

.
.
.

5. Remove all other cs pages or other pages from the child.master
6. Then on the target page, remove the Head tags, and html, body, form tags.
7. Add MasterPageFile=”~/Child.Master” to the html source page
8. Enclose the head section with
9. And enclose the body section in:
10.
11. Done!


Leave a response

Your response:

Categories