using System.Text; using System.Web; using CMS.CMSHelper; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.PortalEngine; public partial class CMSWebParts_Localization_BingTranslator : CMSAbstractWebPart { #region "Public properties" /// /// Webpart no script text. /// public string NoScriptText { get { return ValidationHelper.GetString(GetValue("NoScriptText"), ""); } set { SetValue("NoScriptText", value); } } /// /// Translation mode. /// public string TranslationMode { get { return ValidationHelper.GetString(GetValue("TranslationMode"), "manual"); } set { SetValue("TranslationMode", value); } } /// /// Indicates, whether the web part will be invisible or not. /// public bool DisplayTranslationDialog { get { return ValidationHelper.GetBoolean(GetValue("DisplayTranslationDialog"), true); } set { SetValue("DisplayTranslationDialog", value); } } /// /// Web part border color. /// public string BorderColor { get { return ValidationHelper.GetString(GetValue("BorderColor"), "black"); } set { SetValue("BorderColor", value); } } /// /// Web part background color. /// public string BackgroundColor { get { return ValidationHelper.GetString(GetValue("BackgroundColor"), "gray"); } set { SetValue("BackgroundColor", value); } } /// /// Web part width. /// public int Width { get { return ValidationHelper.GetInteger(GetValue("Width"), 200); } set { SetValue("Width", value); } } #endregion #region "Page events" /// /// Loads the web part content. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } #endregion #region "Other methods" /// /// Sets up the control. /// protected void SetupControl() { if (StopProcessing) { // Do nothing } else { if ((CMSContext.ViewMode == ViewModeEnum.LiveSite) || (CMSContext.ViewMode == ViewModeEnum.Preview)) { string culture = CultureHelper.GetShortCultureCode(CMSContext.CurrentDocumentCulture.CultureCode); string src = "http://www.microsofttranslator.com/Ajax/V2/Widget.aspx"; string query = ""; string display = ""; string borderColor = ""; string backgroundColor = ""; int width = 200; if (BorderColor != "") { borderColor = "border-color: " + BorderColor + "; "; } if (BackgroundColor != "") { backgroundColor = "background-color: " + BackgroundColor + "; "; } if (Width > 0) { width = Width; } // If widget is not visible, translation mode auto is set if (!DisplayTranslationDialog && ((TranslationMode == "auto") || (TranslationMode == "notify"))) { query = URLHelper.AddUrlParameter(query, "mode", TranslationMode); query = URLHelper.AddUrlParameter(query, "widget", "none"); display = "display: none;"; } else { query = URLHelper.AddUrlParameter(query, "mode", TranslationMode); } query = URLHelper.AddUrlParameter(query, "from", culture); query = URLHelper.AddUrlParameter(query, "layout", "ts"); // Add query parameters to the url src = URLHelper.EncodeQueryString(URLHelper.AppendQuery(src, query)); string url = HttpUtility.UrlEncode(URLHelper.GetFullApplicationUrl()); ScriptHelper.RegisterStartupScript(Page, typeof(string), "BingTranslatorScript", ScriptHelper.GetScript("setTimeout(function() { var s = document.createElement(\"script\"); s.type = \"text/javascript\"; s.charset = \"UTF-8\"; s.src = \"" + src + "\"; var p = document.getElementsByTagName('head')[0] || document.documentElement; p.insertBefore(s, p.firstChild); }, 0);")); StringBuilder builder = new StringBuilder(); builder.Append("
"); builder.Append("
"); ltlBingTranslator.Text = builder.ToString(); } } } #endregion }