Exemplo n.º 1
0
    protected string GenerateLocaleList(List<long> selections, int defaultLocale, bool? addRemoveReplace)
    {
        plcLangsSelected.Visible = addRemoveReplace == null;

        Ektron.Cms.Framework.Localization.LocaleManager locale = new Ektron.Cms.Framework.Localization.LocaleManager();
        Ektron.Cms.Framework.Localization.LocalizationObject lobj = new Ektron.Cms.Framework.Localization.LocalizationObject();

        List<Ektron.Cms.Localization.LocaleData> locales = locale.GetEnabledLocales();

        // If not adding/deleting, loop through each of the selected content items to try and find selected locales
        List<int> selectedLocales = new List<int>();
        if (addRemoveReplace == null)
        {
            List<int> contentLocales = new List<int>();
            lMultiNotice.Visible = false;
            foreach (long item in selections)
            {
                contentLocales = lobj.GetObjectLanguages(Ektron.Cms.Localization.LocalizableCmsObjectType.Content, item);
                contentLocales.Sort();
                if (selectedLocales.Count == 0)
                    selectedLocales.AddRange(contentLocales);
                if (!LocaleListsMatch(selectedLocales, contentLocales))
                {
                    selectedLocales = new List<int>();
                    lMultiNotice.Visible = true;
                    break;
                }
            }

            if (!selectedLocales.Contains(defaultLocale))
                selectedLocales.Add(defaultLocale);
        }

        DataTable dt = new DataTable("locales");
        dt.Columns.Add("Id", typeof(int));
        dt.Columns.Add("Enabled", typeof(bool));
        dt.Columns.Add("EnglishName", typeof(string));
        dt.Columns.Add("Loc", typeof(string));
        dt.Columns.Add("CombinedName", typeof(string));
        dt.Columns.Add("FlagUrl", typeof(string));
        dt.Columns.Add("Default", typeof(bool));

        DataRow dr;

        foreach (Ektron.Cms.Localization.LocaleData ld in locales)
        {
            dr = dt.NewRow();
            dr.ItemArray = new object[] { ld.Id, selectedLocales.Contains(ld.Id) || ld.Id == CurrentLanguageId, ld.EnglishName, ld.Loc, ld.CombinedName, ld.FlagUrl, ld.Id == defaultLocale };
            dt.Rows.Add(dr);
        }

        DataTable sdt, adt;
        sdt = GetRowsFromArray(dt.Select("Enabled = true", "Loc"));
        adt = GetRowsFromArray(dt.Select("Enabled = false", "Loc"));

        // Databind
        rptSelectedLangs.DataSource = sdt;
        rptAvailableLangs.DataSource = adt;
        pnlLangSelector.DataBind();

        List<int> availableLocales = locales.ConvertAll<int>(new Converter<Ektron.Cms.Localization.LocaleData, int>(delegate(Ektron.Cms.Localization.LocaleData ld) { return ld.Id; }));
        foreach (int l in selectedLocales)
            if (availableLocales.Contains(l))
                availableLocales.Remove(l);

        // Set up the links
        plcSelectLinks.Controls.Clear();

        if (adt.Rows.Count > 0)
        {
            string links = "<a onclick=\"" + SelectAllScript(true, availableLocales) +
                " return false;\" href=\"#\" title=\"" + GetMessage("lbl select all languages") + "\">" + GetMessage("lbl select all languages") + "</a> | " +
                "<a onclick=\"" + SelectAllScript(false, availableLocales) +
                " return false;\" href=\"#\" title=\"" + GetMessage("lbl deselect all languages") + "\">" + GetMessage("lbl deselect all languages") + "</a>";

            plcSelectLinks.Controls.Add(new LiteralControl(links));
        }
        else
        {
            rptAvailableLangs.Visible = false;
        }

        // Render
        return RenderControl(pnlLangSelector);
    }
Exemplo n.º 2
0
    /// <param name="addRemoveReplace">true for add, false for remove, null for replace</param>
    protected void SetLocales(List<long> selections, List<int> selectedLocales, int defaultLocale, bool? addRemoveReplace)
    {
        Ektron.Cms.Framework.Localization.LocaleManager locale = new Ektron.Cms.Framework.Localization.LocaleManager();
        Ektron.Cms.Framework.Localization.LocalizationObject lobj = new Ektron.Cms.Framework.Localization.LocalizationObject();

        List<Ektron.Cms.Localization.LocaleData> locales = locale.GetEnabledLocales();

        // Loop through each of the selected content items to try and find selected locales
        List<int> contentLocales = new List<int>();
        if (!selectedLocales.Contains(defaultLocale))
            selectedLocales.Add(defaultLocale);
        selectedLocales.Sort();

        List<int> localesToDelete = new List<int>();
        List<int> localesToAdd = new List<int>();
        List<Ektron.Cms.Localization.LocalizationObjectData> localeData = new List<Ektron.Cms.Localization.LocalizationObjectData>();

        foreach (long item in selections)
        {
            Ektron.Cms.Localization.LocalizableCmsObjectType objectType = Ektron.Cms.Localization.LocalizableCmsObjectType.Content;
            contentLocales = lobj.GetObjectLanguages(Ektron.Cms.Localization.LocalizableCmsObjectType.Content, item);
            if (contentLocales.Count == 0)
            {
                objectType = Ektron.Cms.Localization.LocalizableCmsObjectType.DmsAsset;
                contentLocales = lobj.GetObjectLanguages(Ektron.Cms.Localization.LocalizableCmsObjectType.DmsAsset, item);
            }
            bool skip = true;
            if (addRemoveReplace == null && !LocaleListsMatch(selectedLocales, contentLocales))
                skip = false;
            if (addRemoveReplace == true && !LocaleListContains(contentLocales, selectedLocales))
                skip = false;
            if (addRemoveReplace == false && LocaleListContains(contentLocales, selectedLocales))
                skip = false;

            if (!skip)
            {
                localeData = lobj.GetLocalizationObjectList(objectType, item, -1);
                localesToDelete.Clear();
                localesToAdd.Clear();
                if (addRemoveReplace == null || addRemoveReplace == true)
                    foreach (int i in selectedLocales)
                        if (!contentLocales.Contains(i))
                            localesToAdd.Add(i);
                if (addRemoveReplace == null)
                    foreach (int i in contentLocales)
                        if (!selectedLocales.Contains(i))
                            localesToDelete.Add(i);
                if (addRemoveReplace == false)
                    foreach (int i in contentLocales)
                        if (selectedLocales.Contains(i))
                            localesToDelete.Add(i);

                foreach (int i in localesToDelete)
                    foreach (Ektron.Cms.Localization.LocalizationObjectData ldata in localeData)
                        if (ldata.ObjectLanguage == i)
                            lobj.Delete(ldata.Id);

                foreach (int i in localesToAdd)
                    lobj.MarkReadyForTranslation(objectType, item, i);
            }
        }
    }