Exemple #1
0
        /// <summary>
        /// Internals the state of the set view.
        /// </summary>
        /// <param name="myLanguageCultureItem">My language culture item.</param>
        /// <param name="switcher">The switcher.</param>
        private static void InternalSetViewState(LanguageCultureItem myLanguageCultureItem, LanguageSwitcher switcher)
        {
            if (switcher == null)
            {
                return;
            }

            // Trace.WriteLine("Persisting in view state");
            switcher.ViewState["RB_Language_CurrentUICulture"] = myLanguageCultureItem.UICulture;
            switcher.ViewState["RB_Language_CurrentCulture"]   = myLanguageCultureItem.Culture;
        }
Exemple #2
0
        /// <summary>
        /// Gets the label cell.
        /// </summary>
        /// <param name="l">The l.</param>
        /// <returns></returns>
        private TableCell GetLabelCell(LanguageCultureItem l)
        {
            var tableCellLabel = new TableCell
            {
                CssClass =
                    l.UICulture.ToString() == GetCurrentLanguage().UICulture.ToString()
                            ? "rb_LangSw_sel"
                            : "rb_LangSw_tbl"
            };

            var label = new HyperLink {
                NavigateUrl = this.GetLangUrl(l.UICulture.Name), Text = this.GetName(l)
            };

            tableCellLabel.Controls.Add(label);

            return(tableCellLabel);
        }
Exemple #3
0
        /// <summary>
        /// Gets the flag cell.
        /// </summary>
        /// <param name="l">The l.</param>
        /// <returns></returns>
        private TableCell GetFlagCell(LanguageCultureItem l)
        {
            var tableCellFlag = new TableCell
            {
                CssClass =
                    l.UICulture.ToString() == GetCurrentLanguage().UICulture.ToString()
                            ? "rb_LangSw_sel"
                            : "rb_LangSw_tbl"
            };

            var image = new HyperLink
            {
                NavigateUrl = this.GetLangUrl(l.UICulture.Name),
                ImageUrl    = this.GetFlagImg(l),
                Text        = this.GetName(l)
            };

            tableCellFlag.Controls.Add(image);
            return(tableCellFlag);
        }
Exemple #4
0
        /// <summary>
        /// Internals the set cookie.
        /// </summary>
        /// <param name="myLanguageCultureItem">My language culture item.</param>
        /// <param name="cookieAlias">The cookie alias.</param>
        private static void InternalSetCookie(LanguageCultureItem myLanguageCultureItem, string cookieAlias)
        {
            // Set language cookie  --- hack.. do not set cookie if cookieAlias is languageSwitcher
            if (HttpContext.Current == null || cookieAlias == null || cookieAlias == SwitcherCookieName)
            {
                return;
            }

            // Trace.WriteLine("Persisting in cookie: '" + SWITCHER_COOKIE_PREFIX + cookieAlias + "'");
            var langCookie = HttpContext.Current.Response.Cookies[SwitcherCookiePrefix + cookieAlias];

            if (langCookie == null)
            {
                return;
            }

            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);
        }
 /// <summary>
 /// The set current language.
 /// </summary>
 /// <param name="langItem">The lang item.</param>
 /// <param name="cookieAlias">Cookie name used for persist Language</param>
 public static void SetCurrentLanguage(LanguageCultureItem langItem, string cookieAlias)
 {
     SetCurrentLanguage(langItem, cookieAlias, null);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LanguageSwitcherEventArgs"/> class.
 /// </summary>
 /// <param name="uiCulture">The UI culture.</param>
 /// <param name="culture">The culture.</param>
 public LanguageSwitcherEventArgs(CultureInfo uiCulture, CultureInfo culture)
 {
     this.cultureItem = new LanguageCultureItem(uiCulture, culture);
 }
Exemple #7
0
 /// <summary>
 /// Sets the current language.
 /// </summary>
 /// <param name="langItem">The lang item.</param>
 public static void SetCurrentLanguage(LanguageCultureItem langItem)
 {
     SetCurrentLanguage(langItem);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LanguageSwitcherEventArgs"/> class.
 /// </summary>
 /// <param name="cultureItem">The culture item.</param>
 public LanguageSwitcherEventArgs(LanguageCultureItem cultureItem)
 {
     this.cultureItem = cultureItem;
 }
        /// <summary>
        /// Gets the flag img.
        /// </summary>
        /// <param name="languageItem">The language item.</param>
        /// <returns></returns>
        private string GetFlagImg(LanguageCultureItem languageItem)
        {
            CultureInfo culture;

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

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

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

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

            string flagImgUrl = culture.Name.Length > 0 ? string.Format("{0}flags_{1}.gif", this.ImagePath, culture.Name) : string.Format("{0}flags_unknown.gif", this.ImagePath);

            return flagImgUrl;
        }
        /// <summary>
        /// Gets the flag cell.
        /// </summary>
        /// <param name="l">The l.</param>
        /// <returns></returns>
        private TableCell GetFlagCell(LanguageCultureItem l)
        {
            var tableCellFlag = new TableCell
                {
                    CssClass =
                        l.UICulture.ToString() == GetCurrentLanguage().UICulture.ToString()
                            ? "rb_LangSw_sel"
                            : "rb_LangSw_tbl"
                };

            var image = new HyperLink
                {
                    NavigateUrl = this.GetLangUrl(l.UICulture.Name),
                    ImageUrl = this.GetFlagImg(l),
                    Text = this.GetName(l)
                };
            tableCellFlag.Controls.Add(image);
            return tableCellFlag;
        }
        /// <summary>
        /// Internals the state of the set view.
        /// </summary>
        /// <param name="myLanguageCultureItem">My language culture item.</param>
        /// <param name="switcher">The switcher.</param>
        private static void InternalSetViewState(LanguageCultureItem myLanguageCultureItem, LanguageSwitcher switcher)
        {
            if (switcher == null)
            {
                return;
            }

            // Trace.WriteLine("Persisting in view state");
            switcher.ViewState["RB_Language_CurrentUICulture"] = myLanguageCultureItem.UICulture;
            switcher.ViewState["RB_Language_CurrentCulture"] = myLanguageCultureItem.Culture;
        }
        /// <summary>
        /// Internals the set cookie.
        /// </summary>
        /// <param name="myLanguageCultureItem">My language culture item.</param>
        /// <param name="cookieAlias">The cookie alias.</param>
        private static void InternalSetCookie(LanguageCultureItem myLanguageCultureItem, string cookieAlias)
        {
            // Set language cookie  --- hack.. do not set cookie if cookieAlias is languageSwitcher
            if (HttpContext.Current == null || cookieAlias == null || cookieAlias == SwitcherCookieName)
            {
                return;
            }

            // Trace.WriteLine("Persisting in cookie: '" + SWITCHER_COOKIE_PREFIX + cookieAlias + "'");
            var langCookie = HttpContext.Current.Response.Cookies[SwitcherCookiePrefix + cookieAlias];
            if (langCookie == null)
            {
                return;
            }

            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);
        }
        /// <summary>
        /// The set current language.
        /// </summary>
        /// <param name="langItem">The lang item.</param>
        /// <param name="cookieAlias">Cookie name used for persist Language</param>
        /// <param name="switcher">The 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);
        }
 public string getNameLCI(LanguageCultureItem languageItem)
 {
     return this.GetName(languageItem);
 }
 public string GetFlagImgLCI(LanguageCultureItem languageItem)
 {
     return this.GetFlagImg(languageItem);
 }
 /// <summary>
 /// Equals the specified a.
 /// </summary>
 /// <param name="a">
 /// The a.
 /// </param>
 /// <param name="b">
 /// The b.
 /// </param>
 /// <returns>
 /// The equals.
 /// </returns>
 public static bool Equals(LanguageCultureItem a, LanguageCultureItem b)
 {
     return (a != null) && (b != null) && (a.ToString() == b.ToString() || a.Equals(b));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LanguageSwitcherEventArgs"/> class.
 /// </summary>
 /// <param name="uiCulture">The UI culture.</param>
 /// <param name="culture">The culture.</param>
 public LanguageSwitcherEventArgs(CultureInfo uiCulture, CultureInfo culture)
 {
     this.cultureItem = new LanguageCultureItem(uiCulture, culture);
 }
        /// <summary>
        /// Gets the label cell.
        /// </summary>
        /// <param name="l">The l.</param>
        /// <returns></returns>
        private TableCell GetLabelCell(LanguageCultureItem l)
        {
            var tableCellLabel = new TableCell
                {
                    CssClass =
                        l.UICulture.ToString() == GetCurrentLanguage().UICulture.ToString()
                            ? "rb_LangSw_sel"
                            : "rb_LangSw_tbl"
                };

            var label = new HyperLink { NavigateUrl = this.GetLangUrl(l.UICulture.Name), Text = this.GetName(l) };
            tableCellLabel.Controls.Add(label);

            return tableCellLabel;
        }
Exemple #19
0
        //      public static bool operator==(LanguageCultureItem a, LanguageCultureItem b)
        //      {
        //          return LanguageCultureItem.Equals(a, b);
        //      }

        //      public static bool operator!=(LanguageCultureItem a, LanguageCultureItem b)
        //      {
        //          return !LanguageCultureItem.Equals(a, b);
        //      }
        #region Public Methods

        /// <summary>
        /// Equals the specified a.
        /// </summary>
        /// <param name="a">
        /// The a.
        /// </param>
        /// <param name="b">
        /// The b.
        /// </param>
        /// <returns>
        /// The equals.
        /// </returns>
        public static bool Equals(LanguageCultureItem a, LanguageCultureItem b)
        {
            return((a != null) && (b != null) && (a.ToString() == b.ToString() || a.Equals(b)));
        }
        /// <summary>
        /// Gets the name.
        /// </summary>
        /// <param name="languageItem">The language item.</param>
        /// <returns></returns>
        private string GetName(LanguageCultureItem languageItem)
        {
            CultureInfo culture;

            switch (this.Labels)
            {
                default:
                // case LanguageSwitcherDisplay.DisplayNone:
                    return string.Empty;

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

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

            switch (this.ShowNameAs)
            {
                default:
                // case LanguageSwitcherName.NativeName:
                    return languageItem.Culture.TextInfo.ToTitleCase(culture.NativeName);

                case LanguageSwitcherName.DisplayName:
                    return languageItem.Culture.TextInfo.ToTitleCase(culture.DisplayName);

                case LanguageSwitcherName.EnglishName:
                    return languageItem.Culture.TextInfo.ToTitleCase(culture.EnglishName);
            }
        }
Exemple #21
0
 /// <summary>
 /// The set current language.
 /// </summary>
 /// <param name="langItem">The lang item.</param>
 /// <param name="cookieAlias">Cookie name used for persist Language</param>
 public static void SetCurrentLanguage(LanguageCultureItem langItem, string cookieAlias)
 {
     SetCurrentLanguage(langItem, cookieAlias, null);
 }
Exemple #22
0
 /// <summary>
 /// Adds the specified item.
 /// </summary>
 /// <param name="item">
 /// The item.
 /// </param>
 public void Add(LanguageCultureItem item)
 {
     this.InnerList.Add(item);
 }
Exemple #23
0
 /// <summary>
 /// Determines whether [contains] [the specified item].
 /// </summary>
 /// <param name="item">
 /// The item.
 /// </param>
 /// <returns>
 /// <c>true</c> if [contains] [the specified item]; otherwise, <c>false</c>.
 /// </returns>
 public virtual bool Contains(LanguageCultureItem item)
 {
     return(this.InnerList.Contains(item));
 }
Exemple #24
0
 /// <summary>
 /// Indexes the of.
 /// </summary>
 /// <param name="item">
 /// The item.
 /// </param>
 /// <returns>
 /// The index of.
 /// </returns>
 public virtual int IndexOf(LanguageCultureItem item)
 {
     return(this.InnerList.IndexOf(item));
 }
Exemple #25
0
 /// <summary>
 /// Get flage image of language culture item
 /// </summary>
 /// <param name="languageItem"></param>
 /// <returns></returns>
 public string GetFlagImgLCI(LanguageCultureItem languageItem)
 {
     return(this.GetFlagImg(languageItem));
 }
Exemple #26
0
 /// <summary>
 /// Inserts the specified index.
 /// </summary>
 /// <param name="index">
 /// The index.
 /// </param>
 /// <param name="item">
 /// The item.
 /// </param>
 public void Insert(int index, LanguageCultureItem item)
 {
     this.InnerList.Insert(index, item);
 }
Exemple #27
0
 /// <summary>
 /// get language culture item's name
 /// </summary>
 /// <param name="languageItem"></param>
 /// <returns></returns>
 public string getNameLCI(LanguageCultureItem languageItem)
 {
     return(this.GetName(languageItem));
 }
Exemple #28
0
 /// <summary>
 /// Removes the specified item.
 /// </summary>
 /// <param name="item">
 /// The item.
 /// </param>
 public void Remove(LanguageCultureItem item)
 {
     this.InnerList.Remove(item);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LanguageSwitcherEventArgs"/> class.
 /// </summary>
 /// <param name="cultureItem">The culture item.</param>
 public LanguageSwitcherEventArgs(LanguageCultureItem cultureItem)
 {
     this.cultureItem = cultureItem;
 }
 /// <summary>
 /// Sets the current language.
 /// </summary>
 /// <param name="langItem">The lang item.</param>
 public static void SetCurrentLanguage(LanguageCultureItem langItem)
 {
     SetCurrentLanguage(langItem);
 }