/// <summary>
        ///
        /// </summary>
        /// <param name="langItem"></param>
        /// <param name="cookieAlias">Cookie name used for persist Language</param>
        /// <param name="switcher"></param>
        internal static void SetCurrentLanguage(LanguageCultureItem langItem, string cookieAlias,
                                                LanguageSwitcher switcher)
        {
            Thread.CurrentThread.CurrentUICulture = langItem.UICulture;
            Thread.CurrentThread.CurrentCulture   = langItem.Culture;

            //Persists choice
            InternalSetViewState(langItem, switcher);
            InternalSetCookie(langItem, cookieAlias);
        }
 /// <summary>
 /// Equalses the specified a.
 /// </summary>
 /// <param name="a">A.</param>
 /// <param name="b">The b.</param>
 /// <returns></returns>
 public static bool Equals(LanguageCultureItem a, LanguageCultureItem b)
 {
     if ((a == null) || (b == null))
     {
         return(false);
     }
     if (a.ToString() == b.ToString())
     {
         return(true);
     }
     return(a.Equals(b));
 }
        /// <summary>
        /// Implement the RaisePostBackEvent method
        /// from the IPostBackEventHandler interface.
        /// </summary>
        /// <param name="eventArgument"></param>
        public void RaisePostBackEvent(string eventArgument)
        {
            //Trace.WriteLine("RaisingPostBackEvent: eventArgument = '" + eventArgument + "'");

            if (ChangeLanguageAction == LanguageSwitcherAction.LinkRedirect)
            {
                Context.Response.Redirect(GetLangUrl(eventArgument));
            }
            else
            {
                LanguageCultureItem myItem = LanguageList.GetBestMatching(new CultureInfo(eventArgument));
                OnChangeLanguage(new LanguageSwitcherEventArgs(myItem));
            }
        }
        /// <summary>
        /// Set current Cookie from Language
        /// </summary>
        /// <param name="myLanguageCultureItem"></param>
        /// <param name="cookieAlias"></param>
        /// <returns></returns>
        private static void InternalSetCookie(LanguageCultureItem myLanguageCultureItem, string cookieAlias)
        {
            // Set language cookie
            if (HttpContext.Current != null && cookieAlias != null)
            {
                //Trace.WriteLine("Persisting in cookie: '" + SWITCHER_COOKIE_PREFIX + cookieAlias + "'");
                HttpCookie langCookie = HttpContext.Current.Response.Cookies[SWITCHER_COOKIE_PREFIX + cookieAlias];
                langCookie.Value = myLanguageCultureItem.UICulture.Name;
                langCookie.Path  = "/";

                // Keep the cookie?
                if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    langCookie.Expires = DateTime.Now.AddYears(50);
                }
            }
        }
        private TableCell GetLabelCell(LanguageCultureItem l)
        {
            TableCell myTableCellLabel = new TableCell();

            if (l.UICulture.ToString() == GetCurrentLanguage().UICulture.ToString())
            {
                myTableCellLabel.CssClass = "rb_LangSw_sel"; // TODO: not hardcode
            }
            else
            {
                myTableCellLabel.CssClass = "rb_LangSw_tbl"; // TODO: not hardcode
            }
            HyperLink myLabel = new HyperLink();

            myLabel.NavigateUrl = GetLangUrl(l.UICulture.Name);
            myLabel.Text        = GetName(l);
            myTableCellLabel.Controls.Add(myLabel);

            return(myTableCellLabel);
        }
        private string GetFlagImg(LanguageCultureItem languageItem)
        {
            CultureInfo myCulture;

            switch (Flags)
            {
            default:
            case LanguageSwitcherDisplay.DisplayNone:
                return(string.Empty);

            case LanguageSwitcherDisplay.DisplayUICultureList:
                myCulture = languageItem.UICulture;
                break;

            case LanguageSwitcherDisplay.DisplayCultureList:
                myCulture = languageItem.Culture;
                break;
            }

            //Flag must be specific
            if (myCulture.IsNeutralCulture)
            {
                myCulture = CultureInfo.CreateSpecificCulture(myCulture.Name);
            }

            string flagImgUrl;

            if (myCulture.Name.Length > 0)
            {
                flagImgUrl = ImagePath + "flags_" + myCulture.Name + ".gif";
            }
            else
            {
                flagImgUrl = ImagePath + "flags_unknown.gif";
            }

            return(flagImgUrl);
        }
Exemplo n.º 7
0
 public void Remove(LanguageCultureItem item)
 {
     InnerList.Remove(item);
 }
Exemplo n.º 8
0
 public virtual int IndexOf(LanguageCultureItem item)
 {
     return(InnerList.IndexOf(item));
 }
Exemplo n.º 9
0
 public virtual bool Contains(LanguageCultureItem item)
 {
     return(InnerList.Contains(item));
 }
Exemplo n.º 10
0
 public void Insert(Int32 index, LanguageCultureItem item)
 {
     InnerList.Insert(index, item);
 }
Exemplo n.º 11
0
 public void Add(LanguageCultureItem item)
 {
     InnerList.Add(item);
 }
 public LanguageSwitcherEventArgs(LanguageCultureItem cultureItem) : base()
 {
     this.cultureItem = cultureItem;
 }
 public LanguageSwitcherEventArgs(CultureInfo uiCulture, CultureInfo culture) : base()
 {
     cultureItem = new LanguageCultureItem(uiCulture, culture);
 }
        /// <summary>
        /// Override CreateChildControls to create the control tree.
        /// </summary>
        protected override void CreateChildControls()
        {
            //Trace.WriteLine("Creating controls: Type: " + Type.ToString() + " / ChangeLanguageAction: " + ChangeLanguageAction.ToString() + " / Labels: " + Labels.ToString() + " / Flags: " + Flags.ToString() + " / LanguageListString: " + LanguageListString);

            ProcessCultures(LanguageListString, SWITCHER_COOKIE_NAME, this);

            Controls.Clear();
            Table myTable = new Table();

            myTable.CellPadding = 3;
            myTable.CellSpacing = 0;
            TableRowCollection myRows = myTable.Rows;

            switch (Type)
            {
            //Drop down list
            case LanguageSwitcherType.DropDownList:

                TableRow myTableRowDD = new TableRow();

                if (Flags != LanguageSwitcherDisplay.DisplayNone)
                {
                    Image myImage = new Image();
                    myImage.ImageUrl = GetFlagImg(GetCurrentLanguage());

                    TableCell myTableCellFlag = new TableCell();
                    myTableCellFlag.Controls.Add(myImage);

                    myTableRowDD.Controls.Add(myTableCellFlag);
                }

                TableCell myTableCellDropDown = new TableCell();
                langDropDown          = new DropDownList();
                langDropDown.CssClass = "rb_LangSw_dd";     //TODO make changeable

                LanguageCultureItem myCurrentLanguage = GetCurrentLanguage();

                // bind the dropdownlist
                langDropDown.Items.Clear();
                foreach (LanguageCultureItem i in LanguageList)
                {
                    langDropDown.Items.Add(new ListItem(GetName(i), i.UICulture.Name));
                    if (i.UICulture.ToString() == myCurrentLanguage.UICulture.ToString())     //Select current language
                    {
                        langDropDown.Items[langDropDown.Items.Count - 1].Selected = true;
                    }
                }

                langDropDown.Attributes.Add("OnChange",
                                            GetLangAction().Replace("''", "this[this.selectedIndex].value"));

                myTableCellDropDown.Controls.Add(langDropDown);
                myTableRowDD.Controls.Add(myTableCellDropDown);
                myRows.Add(myTableRowDD);
                break;

            // Links
            case LanguageSwitcherType.VerticalLinksList:

                foreach (LanguageCultureItem l in LanguageList)
                {
                    TableRow myTableRowLinks = new TableRow();

                    if (Flags != LanguageSwitcherDisplay.DisplayNone)
                    {
                        myTableRowLinks.Controls.Add(GetFlagCell(l));
                    }
                    if (Labels != LanguageSwitcherDisplay.DisplayNone)
                    {
                        myTableRowLinks.Controls.Add(GetLabelCell(l));
                    }
                    myRows.Add(myTableRowLinks);
                }
                break;

            // Horizontal links
            case LanguageSwitcherType.HorizontalLinksList:

                TableRow myTableRowLinksHorizontal = new TableRow();

                foreach (LanguageCultureItem l in LanguageList)
                {
                    if (Flags != LanguageSwitcherDisplay.DisplayNone)
                    {
                        myTableRowLinksHorizontal.Controls.Add(GetFlagCell(l));
                    }
                    if (Labels != LanguageSwitcherDisplay.DisplayNone)
                    {
                        myTableRowLinksHorizontal.Controls.Add(GetLabelCell(l));
                    }
                }

                myRows.Add(myTableRowLinksHorizontal);
                break;
            }

            Controls.Add(myTable);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="langItem"></param>
 /// <param name="cookieAlias">Cookie name used for persist Language</param>
 public static void SetCurrentLanguage(LanguageCultureItem langItem, string cookieAlias)
 {
     SetCurrentLanguage(langItem, cookieAlias, null);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="langItem"></param>
 public static void SetCurrentLanguage(LanguageCultureItem langItem)
 {
     SetCurrentLanguage(langItem);
 }