protected void publishedCheckbox_CheckChanged(object sender, EventArgs e) { try { if ((sender) is CheckBox) { var publishedCheckbox = (CheckBox)sender; GridDataItem item = (GridDataItem)publishedCheckbox.NamingContainer; DnnLanguageLabel code = item.FindControl("translationStatusLabel") as DnnLanguageLabel; Locale locale = LocaleController.Instance.GetLocale(code.Language); if (publishedCheckbox.Enabled) { LocaleController.Instance.PublishLanguage(PortalId, locale.Code, publishedCheckbox.Checked); } //Redirect to refresh page (and skinobjects) Response.Redirect(Globals.NavigateURL(), true); } } catch (Exception ex) { Exceptions.ProcessModuleLoadException(this, ex); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); cmdCancel.NavigateUrl = Globals.NavigateURL(); try { var files = new SortedList(); Dictionary <string, Locale> locales = LocaleController.Instance.GetLocales(Null.NullInteger); SectionHeadControl shc; GetResourceFiles(files, Server.MapPath("~\\admin")); GetResourceFiles(files, Server.MapPath("~\\controls")); GetResourceFiles(files, Server.MapPath("~\\desktopmodules")); GetResourceFiles(files, Server.MapPath("~\\providers")); GetResourceFiles(files, Server.MapPath("~\\install")); GetResourceFiles(files, Server.MapPath("~\\Portals\\_Default\\Skins")); // Add global and shared resource files files.Add(Server.MapPath(Localization.GlobalResourceFile), new FileInfo(Server.MapPath(Localization.GlobalResourceFile))); files.Add(Server.MapPath(Localization.SharedResourceFile), new FileInfo(Server.MapPath(Localization.SharedResourceFile))); foreach (var locale in locales.Values) { var languageLabel = new DnnLanguageLabel { Language = locale.Code }; var tableTop = new HtmlTable { ID = locale.Code }; var rowTop = new HtmlTableRow(); var cellTop = new HtmlTableCell(); var tableMissing = new HtmlTable { ID = "Missing" + locale.Code }; var tableEntries = new HtmlTable { ID = "Entry" + locale.Code }; var tableObsolete = new HtmlTable { ID = "Obsolete" + locale.Code }; var tableOld = new HtmlTable { ID = "Old" + locale.Code }; var tableDuplicate = new HtmlTable { ID = "Duplicate" + locale.Code }; var tableError = new HtmlTable { ID = "Error" + locale.Code }; foreach (DictionaryEntry file in files) { // check for existance if (!File.Exists(ResourceFile(file.Key.ToString(), locale.Code))) { var row = new HtmlTableRow(); var cell = new HtmlTableCell { InnerText = ResourceFile(file.Key.ToString(), locale.Code).Replace(Server.MapPath("~"), "") }; cell.Attributes["Class"] = "Normal"; row.Cells.Add(cell); tableMissing.Rows.Add(row); } else { var dsDef = new DataSet(); var dsRes = new DataSet(); DataTable dtDef; DataTable dtRes; try { dsDef.ReadXml(file.Key.ToString()); } catch { var row = new HtmlTableRow(); var cell = new HtmlTableCell { InnerText = file.Key.ToString().Replace(Server.MapPath("~"), "") }; cell.Attributes["Class"] = "Normal"; row.Cells.Add(cell); tableError.Rows.Add(row); dsDef = null; } try { dsRes.ReadXml(ResourceFile(file.Key.ToString(), locale.Code)); } catch { if (locale.Text != Localization.SystemLocale) { var row = new HtmlTableRow(); var cell = new HtmlTableCell { InnerText = ResourceFile(file.Key.ToString(), locale.Code).Replace(Server.MapPath("~"), "") }; cell.Attributes["Class"] = "Normal"; row.Cells.Add(cell); tableError.Rows.Add(row); dsRes = null; } } if (dsRes != null && dsDef != null && dsRes.Tables["data"] != null && dsDef.Tables["data"] != null) { dtDef = dsDef.Tables["data"]; dtDef.TableName = "default"; dtRes = dsRes.Tables["data"].Copy(); dtRes.TableName = "localized"; dsDef.Tables.Add(dtRes); // Check for duplicate entries in localized file try { // if this fails-> file contains duplicates var c = new UniqueConstraint("uniqueness", dtRes.Columns["name"]); dtRes.Constraints.Add(c); dtRes.Constraints.Remove("uniqueness"); } catch { var row = new HtmlTableRow(); var cell = new HtmlTableCell { InnerText = ResourceFile(file.Key.ToString(), locale.Code).Replace(Server.MapPath("~"), "") }; cell.Attributes["Class"] = "Normal"; row.Cells.Add(cell); tableDuplicate.Rows.Add(row); } // Check for missing entries in localized file try { // if this fails-> some entries in System default file are not found in Resource file dsDef.Relations.Add("missing", dtRes.Columns["name"], dtDef.Columns["name"]); } catch { var row = new HtmlTableRow(); var cell = new HtmlTableCell { InnerText = ResourceFile(file.Key.ToString(), locale.Code).Replace(Server.MapPath("~"), "") }; cell.Attributes["Class"] = "Normal"; row.Cells.Add(cell); tableEntries.Rows.Add(row); } finally { dsDef.Relations.Remove("missing"); } // Check for obsolete entries in localized file try { // if this fails-> some entries in Resource File are not found in System default dsDef.Relations.Add("obsolete", dtDef.Columns["name"], dtRes.Columns["name"]); } catch { var row = new HtmlTableRow(); var cell = new HtmlTableCell { InnerText = ResourceFile(file.Key.ToString(), locale.Code).Replace(Server.MapPath("~"), "") }; cell.Attributes["Class"] = "Normal"; row.Cells.Add(cell); tableObsolete.Rows.Add(row); } finally { dsDef.Relations.Remove("obsolete"); } // Check older files var resFile = new FileInfo(ResourceFile(file.Key.ToString(), locale.Code)); if (((FileInfo)file.Value).LastWriteTime > resFile.LastWriteTime) { var row = new HtmlTableRow(); var cell = new HtmlTableCell { InnerText = ResourceFile(file.Key.ToString(), locale.Code).Replace(Server.MapPath("~"), "") }; cell.Attributes["Class"] = "Normal"; row.Cells.Add(cell); tableOld.Rows.Add(row); } } } } if (tableMissing.Rows.Count > 0) { // ------- Missing files shc = (SectionHeadControl)LoadControl("~/controls/sectionheadcontrol.ascx"); shc.Section = "Missing" + locale.Code; shc.IncludeRule = false; shc.IsExpanded = false; shc.CssClass = "SubHead"; shc.Text = Localization.GetString("MissingFiles", LocalResourceFile) + tableMissing.Rows.Count; cellTop.Controls.Add(shc); cellTop.Controls.Add(tableMissing); } if (tableDuplicate.Rows.Count > 0) { // ------- Duplicate keys shc = (SectionHeadControl)LoadControl("~/controls/sectionheadcontrol.ascx"); shc.Section = "Duplicate" + locale.Code; shc.IncludeRule = false; shc.IsExpanded = false; shc.CssClass = "SubHead"; shc.Text = Localization.GetString("DuplicateEntries", LocalResourceFile) + tableDuplicate.Rows.Count; cellTop.Controls.Add(shc); cellTop.Controls.Add(tableDuplicate); } if (tableEntries.Rows.Count > 0) { // ------- Missing entries shc = (SectionHeadControl)LoadControl("~/controls/sectionheadcontrol.ascx"); shc.Section = "Entry" + locale.Code; shc.IncludeRule = false; shc.IsExpanded = false; shc.CssClass = "SubHead"; shc.Text = Localization.GetString("MissingEntries", LocalResourceFile) + tableEntries.Rows.Count; cellTop.Controls.Add(shc); cellTop.Controls.Add(tableEntries); } if (tableObsolete.Rows.Count > 0) { // ------- Missing entries shc = (SectionHeadControl)LoadControl("~/controls/sectionheadcontrol.ascx"); shc.Section = "Obsolete" + locale.Code; shc.IncludeRule = false; shc.IsExpanded = false; shc.CssClass = "SubHead"; shc.Text = Localization.GetString("ObsoleteEntries", LocalResourceFile) + tableObsolete.Rows.Count; cellTop.Controls.Add(shc); cellTop.Controls.Add(tableObsolete); } if (tableOld.Rows.Count > 0) { // ------- Old files shc = (SectionHeadControl)LoadControl("~/controls/sectionheadcontrol.ascx"); shc.Section = "Old" + locale.Code; shc.IncludeRule = false; shc.IsExpanded = false; shc.CssClass = "SubHead"; shc.Text = Localization.GetString("OldFiles", LocalResourceFile) + tableOld.Rows.Count; cellTop.Controls.Add(shc); cellTop.Controls.Add(tableOld); } if (tableError.Rows.Count > 0) { // ------- Error files shc = (SectionHeadControl)LoadControl("~/controls/sectionheadcontrol.ascx"); shc.Section = "Error" + locale.Code; shc.IncludeRule = false; shc.IsExpanded = false; shc.CssClass = "SubHead"; shc.Text = Localization.GetString("ErrorFiles", LocalResourceFile) + tableError.Rows.Count; cellTop.Controls.Add(shc); cellTop.Controls.Add(tableError); } rowTop.Cells.Add(cellTop); tableTop.Rows.Add(rowTop); PlaceHolder1.Controls.Add(languageLabel); PlaceHolder1.Controls.Add(tableTop); PlaceHolder1.Controls.Add(new LiteralControl("<br>")); } //Module failed to load } catch (Exception exc) { Exceptions.ProcessModuleLoadException(this, exc); } }
protected void enabledCheckbox_CheckChanged(object sender, EventArgs e) { try { if ((sender) is CheckBox) { var enabledCheckbox = (CheckBox)sender; GridDataItem item = (GridDataItem)enabledCheckbox.NamingContainer; DnnLanguageLabel code = item.FindControl("translationStatusLabel") as DnnLanguageLabel; Locale locale = LocaleController.Instance.GetLocale(code.Language); Locale defaultLocale = LocaleController.Instance.GetDefaultLocale(PortalId); Dictionary <string, Locale> enabledLanguages = LocaleController.Instance.GetLocales(PortalId); var localizedTabs = PortalSettings.ContentLocalizationEnabled ? TabController.Instance.GetTabsByPortal(PortalId).WithCulture(locale.Code, false).AsList() : new List <TabInfo>(); var redirectUrl = string.Empty; if (enabledCheckbox.Enabled) { // do not touch default language if (enabledCheckbox.Checked) { if (!enabledLanguages.ContainsKey(locale.Code)) { //Add language to portal Localization.AddLanguageToPortal(PortalId, locale.LanguageId, true); } //restore the tabs and modules foreach (var tab in localizedTabs) { TabController.Instance.RestoreTab(tab, PortalSettings); ModuleController.Instance.GetTabModules(tab.TabID).Values.ToList().ForEach(ModuleController.Instance.RestoreModule); } } else { //remove language from portal Localization.RemoveLanguageFromPortal(PortalId, locale.LanguageId); //if the disable language is current language, should redirect to default language. if (locale.Code.Equals(Thread.CurrentThread.CurrentUICulture.ToString(), StringComparison.InvariantCultureIgnoreCase)) { redirectUrl = Globals.NavigateURL(PortalSettings.ActiveTab.TabID, PortalSettings.ActiveTab.IsSuperTab, PortalSettings, "", defaultLocale.Code); } //delete the tabs in this language foreach (var tab in localizedTabs) { tab.DefaultLanguageGuid = Guid.Empty; TabController.Instance.SoftDeleteTab(tab.TabID, PortalSettings); } } } //Redirect to refresh page (and skinobjects) if (string.IsNullOrEmpty(redirectUrl)) { redirectUrl = Globals.NavigateURL(); } Response.Redirect(redirectUrl, true); } } catch (Exception ex) { Exceptions.ProcessModuleLoadException(this, ex); } }