protected void languagesGrid_ItemCreated(object sender, GridItemEventArgs e)
        {
            var gridItem = e.Item as GridDataItem;

            if (gridItem != null)
            {
                var languge = gridItem.DataItem as Locale;
                if (languge != null)
                {
                    var localizeLink = gridItem.FindControl("localizeLink") as HyperLink;
                    if (localizeLink != null)
                    {
                        Locale defaultLocale             = LocaleController.Instance.GetLocale(PortalDefault);
                        CultureDropDownTypes DisplayType = default(CultureDropDownTypes);
                        string _ViewType = Convert.ToString(Personalization.GetProfile("LanguageDisplayMode", "ViewType" + PortalId));
                        switch (_ViewType)
                        {
                        case "NATIVE":
                            DisplayType = CultureDropDownTypes.NativeName;
                            break;

                        case "ENGLISH":
                            DisplayType = CultureDropDownTypes.EnglishName;
                            break;

                        default:
                            DisplayType = CultureDropDownTypes.DisplayName;
                            break;
                        }

                        localizeLink.NavigateUrl = ModuleContext.NavigateUrl(ModuleContext.TabId,
                                                                             "LocalizePages",
                                                                             false,
                                                                             "mid=" + ModuleContext.ModuleId,
                                                                             "locale=" + languge.Code);

                        var publishButton = gridItem.FindControl("publishButton") as ImageButton;
                        if (publishButton != null)
                        {
                            string msgPublish = String.Format(Localization.GetString("Publish.Confirm", LocalResourceFile), Localization.GetLocaleName(languge.Code, DisplayType));
                            msgPublish = msgPublish.Replace("'", "\'");
                            msgPublish = Localization.GetSafeJSString(msgPublish);
                            publishButton.Attributes.Add("onclick", "alert('" + msgPublish + "');");
                        }
                    }
                }
            }
        }
示例#2
0
        ListItem CreateListItem(PortalController.PortalTemplateInfo template)
        {
            string text, value;

            if (string.IsNullOrEmpty(template.CultureCode))
            {
                text  = template.Name;
                value = Path.GetFileName(template.TemplateFilePath);
            }
            else
            {
                if (DisplayType == 0)
                {
                    string _ViewType = Convert.ToString(Services.Personalization.Personalization.GetProfile("LanguageDisplayMode", "ViewType" + PortalId));
                    switch (_ViewType)
                    {
                    case "NATIVE":
                        DisplayType = CultureDropDownTypes.NativeName;
                        break;

                    case "ENGLISH":
                        DisplayType = CultureDropDownTypes.EnglishName;
                        break;

                    default:
                        DisplayType = CultureDropDownTypes.DisplayName;
                        break;
                    }
                }

                text  = string.Format("{0} - {1}", template.Name, Localization.GetLocaleName(template.CultureCode, DisplayType));
                value = string.Format("{0}|{1}", Path.GetFileName(template.TemplateFilePath), template.CultureCode);
            }

            return(new ListItem(text, value));
        }
        public static string GetLocaleName(string code, CultureDropDownTypes displayType)
        {
            string name;

            // Create a CultureInfo class based on culture
            CultureInfo info = CultureInfo.CreateSpecificCulture(code);

            // Based on the display type desired by the user, select the correct property
            switch (displayType)
            {
                case CultureDropDownTypes.EnglishName:
                    name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(info.EnglishName);
                    break;
                case CultureDropDownTypes.Lcid:
                    name = info.LCID.ToString();
                    break;
                case CultureDropDownTypes.Name:
                    name = info.Name;
                    break;
                case CultureDropDownTypes.NativeName:
                    name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(info.NativeName);
                    break;
                case CultureDropDownTypes.TwoLetterIsoCode:
                    name = info.TwoLetterISOLanguageName;
                    break;
                case CultureDropDownTypes.ThreeLetterIsoCode:
                    name = info.ThreeLetterISOLanguageName;
                    break;
                default:
                    name = info.DisplayName;
                    break;
            }

            return name;
        }
        /// <summary>
        /// <para>LoadCultureDropDownList loads a DropDownList with the list of supported cultures
        ///     based on the languages defined in the supported locales file</para>
        ///  <para>This overload allows us to filter a language from the dropdown. To do so pass a language code to the Filter parameter</para>
        ///   <para>This overload allows us to display all installed languages. To do so, pass the value True to the Host parameter</para>
        /// </summary>
        /// <param name="displayType"></param>
        /// <param name="selectedValue"></param>
        /// <param name="filter"></param>
        /// <param name="host"></param>
        /// <returns></returns>
        public static IEnumerable<ListItem> LoadCultureInListItems(CultureDropDownTypes displayType, string selectedValue, string filter, bool host)
        {
            PortalSettings objPortalSettings = PortalController.Instance.GetCurrentPortalSettings();
            Dictionary<string, Locale> enabledLanguages;
            if (host)
            {
                enabledLanguages = LocaleController.Instance.GetLocales(Null.NullInteger);
            }
            else
            {
                enabledLanguages = LocaleController.Instance.GetLocales(objPortalSettings.PortalId);
            }

            var cultureListItems = new List<ListItem>(enabledLanguages.Count);
            foreach (KeyValuePair<string, Locale> kvp in enabledLanguages)
            {
                if (kvp.Value.Code != filter)
                {
                    cultureListItems.Add(new ListItem { Value = kvp.Value.Code, Text = GetLocaleName(kvp.Value.Code, displayType) });
                }
            }

            return cultureListItems;
        }
        /// <summary>
        ///   <para>LoadCultureDropDownList loads a DropDownList with the list of supported cultures
        ///     based on the languages defined in the supported locales file</para>
        ///   <para>This overload allows us to filter a language from the dropdown. To do so pass a language code to the Filter parameter</para>
        ///   <para>This overload allows us to display all installed languages. To do so, pass the value True to the Host parameter</para>
        /// </summary>
        /// <param name = "list">DropDownList to load</param>
        /// <param name = "displayType">Format of the culture to display. Must be one the CultureDropDownTypes values.
        ///   <see cref = "CultureDropDownTypes" /> for list of allowable values</param>
        /// <param name = "selectedValue">Name of the default culture to select</param>
        /// <param name = "filter">String value that allows for filtering out a specific language</param>
        /// <param name = "host">Boolean that defines wether or not to load host (ie. all available) locales</param>
        public static void LoadCultureDropDownList(DropDownList list, CultureDropDownTypes displayType, string selectedValue, string filter, bool host)
        {
            IEnumerable<ListItem> cultureListItems = LoadCultureInListItems(displayType, selectedValue, filter, host);

            //add the items to the list
            foreach (var cultureItem in cultureListItems)
            {
                list.Items.Add(cultureItem);
            }

            //select the default item
            if (selectedValue != null)
            {
                ListItem item = list.Items.FindByValue(selectedValue);
                if (item != null)
                {
                    list.SelectedIndex = -1;
                    item.Selected = true;
                }
            }
        }
 /// <summary>
 ///   <para>LoadCultureDropDownList loads a DropDownList with the list of supported cultures
 ///     based on the languages defined in the supported locales file. </para>
 ///   <para>This overload allows us to display all installed languages. To do so, pass the value True to the Host parameter</para>
 /// </summary>
 /// <param name = "list">DropDownList to load</param>
 /// <param name = "displayType">Format of the culture to display. Must be one the CultureDropDownTypes values.
 ///   <see cref = "CultureDropDownTypes" /> for list of allowable values</param>
 /// <param name = "selectedValue">Name of the default culture to select</param>
 /// <param name = "loadHost">Boolean that defines wether or not to load host (ie. all available) locales</param>
 public static void LoadCultureDropDownList(DropDownList list, CultureDropDownTypes displayType, string selectedValue, bool loadHost)
 {
     LoadCultureDropDownList(list, displayType, selectedValue, "", loadHost);
 }
 /// <summary>
 ///   <para>LoadCultureDropDownList loads a DropDownList with the list of supported cultures
 ///     based on the languages defined in the supported locales file, for the current portal</para>
 /// </summary>
 /// <param name = "list">DropDownList to load</param>
 /// <param name = "displayType">Format of the culture to display. Must be one the CultureDropDownTypes values.
 ///   <see cref = "CultureDropDownTypes" /> for list of allowable values</param>
 /// <param name = "selectedValue">Name of the default culture to select</param>
 public static void LoadCultureDropDownList(DropDownList list, CultureDropDownTypes displayType, string selectedValue)
 {
     LoadCultureDropDownList(list, displayType, selectedValue, "", false);
 }
示例#8
0
        /// <summary>
        ///   <para>LoadCultureDropDownList loads a DropDownList with the list of supported cultures
        ///     based on the languages defined in the supported locales file</para>
        ///   <para>This overload allows us to filter a language from the dropdown. To do so pass a language code to the Filter parameter</para>
        ///   <para>This overload allows us to display all installed languages. To do so, pass the value True to the Host parameter</para>
        /// </summary>
        /// <param name = "list">DropDownList to load</param>
        /// <param name = "displayType">Format of the culture to display. Must be one the CultureDropDownTypes values.
        ///   <see cref = "CultureDropDownTypes" /> for list of allowable values</param>
        /// <param name = "selectedValue">Name of the default culture to select</param>
        /// <param name = "filter">String value that allows for filtering out a specific language</param>
        /// <param name = "host">Boolean that defines wether or not to load host (ie. all available) locales</param>
        public static void LoadCultureDropDownList(DropDownList list, CultureDropDownTypes displayType, string selectedValue, string filter, bool host)
        {
            PortalSettings objPortalSettings = PortalController.GetCurrentPortalSettings();
            Dictionary<string, Locale> enabledLanguages;
            if (host)
            {
                enabledLanguages = _localeController.GetLocales(Null.NullInteger);
            }
            else
            {
                enabledLanguages = _localeController.GetLocales(objPortalSettings.PortalId);
            }
            var cultureListItems = new ListItem[enabledLanguages.Count];
            int intAdded = 0;
            foreach (KeyValuePair<string, Locale> kvp in enabledLanguages)
            {
                if (kvp.Value.Code != filter)
                {
                    //Create and initialize a new ListItem
                    var item = new ListItem { Value = kvp.Value.Code };
                    item.Text = GetLocaleName(item.Value, displayType);
                    cultureListItems[intAdded] = item;
                    intAdded += 1;
                }
            }

            //If the drop down list already has items, clear the list
            if (list.Items.Count > 0)
            {
                list.Items.Clear();
            }
            Array.Resize(ref cultureListItems, intAdded);
            //add the items to the list
            list.Items.AddRange(cultureListItems);

            //select the default item
            if (selectedValue != null)
            {
                ListItem item = list.Items.FindByValue(selectedValue);
                if (item != null)
                {
                    list.SelectedIndex = -1;
                    item.Selected = true;
                }
            }
        }
 /// <summary>
 /// <para>LoadCultureDropDownList loads a DropDownList with the list of supported cultures
 /// based on the languages defined in the supported locales file</para>
 /// <para>This overload allows us to filter a language from the dropdown. To do so pass a language code to the Filter parameter</para>
 /// <para>This overload allows us to display all installed languages. To do so, pass the value True to the Host parameter</para>
 /// </summary>
 /// <param name="list">DropDownList to load</param>
 /// <param name="displayType">Format of the culture to display. Must be one the CultureDropDownTypes values.
 /// <see cref="CultureDropDownTypes"/> for list of allowable values</param>
 /// <param name="selectedValue">Name of the default culture to select</param>
 /// <param name="Filter">Stringvalue that allows for filtering out a specifiec language</param>
 /// <param name="Host">Boolean that defines wether or not to load host (ie. all available) locales</param>
 public static void LoadCultureDropDownList(DropDownList list, CultureDropDownTypes displayType, string selectedValue, string Filter, bool Host)
 {
     PortalSettings objPortalSettings = PortalController.GetCurrentPortalSettings();
     Dictionary<string, Locale> enabledLanguages;
     if (Host)
     {
         enabledLanguages = Localization.GetLocales(Null.NullInteger);
     }
     else
     {
         enabledLanguages = Localization.GetLocales(objPortalSettings.PortalId);
     }
     ListItem[] _cultureListItems = new ListItem[enabledLanguages.Count];
     CultureDropDownTypes _cultureListItemsType = displayType;
     int intAdded = 0;
     foreach (KeyValuePair<string, Locale> kvp in enabledLanguages)
     {
         if (kvp.Value.Code != Filter)
         {
             CultureInfo info = CultureInfo.CreateSpecificCulture(kvp.Value.Code);
             ListItem item = new ListItem();
             item.Value = kvp.Value.Code;
             switch (displayType)
             {
                 case CultureDropDownTypes.EnglishName:
                     item.Text = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(info.EnglishName);
                     break;
                 case CultureDropDownTypes.Lcid:
                     item.Text = info.LCID.ToString();
                     break;
                 case CultureDropDownTypes.Name:
                     item.Text = info.Name;
                     break;
                 case CultureDropDownTypes.NativeName:
                     item.Text = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(info.NativeName);
                     break;
                 case CultureDropDownTypes.TwoLetterIsoCode:
                     item.Text = info.TwoLetterISOLanguageName;
                     break;
                 case CultureDropDownTypes.ThreeLetterIsoCode:
                     item.Text = info.ThreeLetterISOLanguageName;
                     break;
                 default:
                     item.Text = info.DisplayName;
                     break;
             }
             _cultureListItems[intAdded] = item;
             intAdded += 1;
         }
     }
     if (list.Items.Count > 0)
     {
         list.Items.Clear();
     }
     Array.Resize(ref _cultureListItems, intAdded);
     list.Items.AddRange(_cultureListItems);
     if (selectedValue != null)
     {
         ListItem item = list.Items.FindByValue(selectedValue);
         if (item != null)
         {
             list.SelectedIndex = -1;
             item.Selected = true;
         }
     }
 }
示例#10
0
        /// <Summary>
        /// LoadCultureDropDownList loads a DropDownList with the list of supported cultures
        /// based on the languages defined in the supported locales file
        /// </Summary>
        /// <Param name="list">DropDownList to load</Param>
        /// <Param name="displayType">
        /// Format of the culture to display. Must be one the CultureDropDownTypes values.
        /// for list of allowable values
        /// </Param>
        /// <Param name="selectedValue">Name of the default culture to select</Param>
        public static void LoadCultureDropDownList( DropDownList list, CultureDropDownTypes displayType, string selectedValue )
        {
            LocaleCollection supportedLanguages = GetSupportedLocales();
            ListItem[] _cultureListItems = new ListItem[supportedLanguages.Count - 1 + 1];
            PortalSettings objPortalSettings = PortalController.GetCurrentPortalSettings();
            XmlDocument xmlLocales = new XmlDocument();
            bool bXmlLoaded = false;
            int intAdded = 0;

            if (File.Exists(HttpContext.Current.Server.MapPath(ApplicationConfigDirectory + "/Locales.Portal-" + objPortalSettings.PortalId + ".xml")))
            {
                try
                {
                    xmlLocales.Load(HttpContext.Current.Server.MapPath(ApplicationConfigDirectory + "/Locales.Portal-" + objPortalSettings.PortalId + ".xml"));
                    bXmlLoaded = true;
                }
                catch
                {
                }
            }

            for (int i = 0; i < supportedLanguages.Count; i++)
            {
                // Only load active locales
                if (!bXmlLoaded || xmlLocales.SelectSingleNode("//locales/inactive/locale[.='" + ((Locale)supportedLanguages[i].Value).Code + "']") == null)
                {
                    // Create a CultureInfo class based on culture
                    CultureInfo info = CultureInfo.CreateSpecificCulture(((Locale)supportedLanguages[i].Value).Code);

                    // Create and initialize a new ListItem
                    ListItem item = new ListItem();
                    item.Value = ((Locale)supportedLanguages[i].Value).Code;

                    // Based on the display type desired by the user, select the correct property
                    switch (displayType)
                    {
                        case CultureDropDownTypes.EnglishName:

                            item.Text = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(info.EnglishName);
                            break;
                        case CultureDropDownTypes.Lcid:

                            item.Text = info.LCID.ToString();
                            break;
                        case CultureDropDownTypes.Name:

                            item.Text = info.Name;
                            break;
                        case CultureDropDownTypes.NativeName:

                            item.Text = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(info.NativeName);
                            break;
                        case CultureDropDownTypes.TwoLetterIsoCode:

                            item.Text = info.TwoLetterISOLanguageName;
                            break;
                        case CultureDropDownTypes.ThreeLetterIsoCode:

                            item.Text = info.ThreeLetterISOLanguageName;
                            break;
                        default:

                            item.Text = info.DisplayName;
                            break;
                    }
                    _cultureListItems[intAdded] = item;
                    intAdded++;
                }
            }

            // If the drop down list already has items, clear the list
            if (list.Items.Count > 0)
            {
                list.Items.Clear();
            }

            _cultureListItems = (ListItem[])Utils.CopyArray(_cultureListItems, new ListItem[intAdded - 1 + 1]);
            // add the items to the list
            list.Items.AddRange(_cultureListItems);

            // select the default item
            if (selectedValue != null)
            {
                ListItem item = list.Items.FindByValue(selectedValue);
                if (item != null)
                {
                    list.SelectedIndex = -1;
                    item.Selected = true;
                }
            }
        }