Themelia Pro A powerful new development platform built on ASP.NET.
 
Using the PageTranslator Class
 
 

If you are unable to obtain professional translation services or if a particular page need not be professionally translated at all, you may use Themelia Pro's Themelia.Web.Globalization.PageTranslator utility. By using this utility, you can automatically translate an entire web page from just about any language into just about any other language. This feature uses internally uses Google Translator to do the translation.

To use it, you call one of the Translate method overloads somewhere in your OnPreRender method:

public static void Translate<T>(System.Web.UI.Control control, String sourceLanguageCode)
public static void Translate<T, T2>(System.Web.UI.Control control, String sourceLanguageCode)
public static void Translate<T, T2, T3>(System.Web.UI.Control control, String sourceLanguageCode)
public static void Translate<T, T2, T3, T4>(System.Web.UI.Control control, String sourceLanguageCode)
public static void Translate<T, T2, T3, T4, T5>(System.Web.UI.Control control, String sourceLanguageCode)
 
public static void Translate<T>(System.Web.UI.Control control, String sourceLanguageCode, String targetLanguageCode)
public static void Translate<T, T2>(System.Web.UI.Control control, String sourceLanguageCode, String targetLanguageCode)
public static void Translate<T, T2, T3>(System.Web.UI.Control control, String sourceLanguageCode, String targetLanguageCode)
public static void
 Translate<T, T2, T3, T4>(System.Web.UI.Control control, 
String sourceLanguageCode, String targetLanguageCode)
public static void Translate<T, T2, T3, T4, T5>(System.Web.UI.Control control, String sourceLanguageCode, String targetLanguageCode)

There are two sets of overloads: those that use the current user's culture as the target and those that specify a target culture manually. Each of the generic parameters have the following constraint: "where TX : System.Web.UI.Control, ITextControl". That is each "T" must be of type System.Web.UI.Control and implement the System.Web.UI.ITextControl interface.

Examples of built in controls that implement these controls are the ASP.NET Label and Literal controls. Thus, you can use something like the following syntax to translate all Literal controls in a specific web page from English into Italian:

Themelia.Web.Globalization.PageTranslator.Translate<System.Web.UI.WebControls.Literal>(this, "en", "it");

Note that you can also do page translation for parts of a page as well. That is instead of "this", you can put any control. All children will be translated. Here's another example:

Themelia.Web.Globalization.PageTranslator.Translate<System.Web.UI.WebControls.Literal>(phSideBar, "en");

This example translates all controls under the phSideBar PlaceHolder control from English to the user's current culture.