public ActionResult LstLanguages() { LanguageSwitcher ls = new LanguageSwitcher(); Appleseed.Framework.Web.UI.WebControls.LanguageCultureCollection lcc = Appleseed.Framework.Localization.LanguageSwitcher.GetLanguageCultureList(); List <string[]> datos = new List <string[]>(); var settings = PortalSettings.HasEnablePageFriendlyUrl(Portal.PageID, Config.DefaultPortal); var pageextenstion = System.Configuration.ConfigurationManager.AppSettings["friendlyUrlExtension"]; foreach (Appleseed.Framework.Web.UI.WebControls.LanguageCultureItem l in lcc) { string[] dato = new string[3]; string aux = l.ToString(); char[] array = new char[1]; array[0] = '/'; string[] lang = aux.Split(array); dato[0] = settings == true?HttpUrlBuilder.BuildUrl("~/Home" + pageextenstion + "?lang=" + lang[0]) : HttpUrlBuilder.BuildUrl("~/site/0/Home?lang=" + lang[0]); LanguageSwitcher lswitcher = new LanguageSwitcher(); dato[1] = lswitcher.GetFlagImgLCI(l); dato[1] = dato[1].Replace("images", "~/aspnet_client"); dato[1] = HttpUrlBuilder.BuildUrl(dato[1]); dato[2] = lswitcher.getNameLCI(l); datos.Add(dato); } ViewData["datos"] = datos; return(View()); }
/// <summary> /// Binds data source to grid /// </summary> public override void DataBind() { base.DataBind(); LanguageCultureCollection LanguagesDataSource = (LanguageCultureCollection)DataSource; if (LanguagesDataSource.Count > 1) { Columns[2].Visible = true; } else { Columns[2].Visible = false; //do not allow deleting last row } for (Int32 i = 0; i < Items.Count; i++) { DropDownList ddLanguage = (DropDownList)Items[i].Cells[0].Controls[0]; DropDownList ddCulture = (DropDownList)Items[i].Cells[1].Controls[0]; if (ddLanguage.Items.FindByValue(LanguagesDataSource[i].UICulture.Name) != null) { ddLanguage.Items.FindByValue(LanguagesDataSource[i].UICulture.Name).Selected = true; } if (ddCulture.Items.FindByValue(LanguagesDataSource[i].Culture.Name) != null) { ddCulture.Items.FindByValue(LanguagesDataSource[i].Culture.Name).Selected = true; } } }
public ActionResult LstLanguages() { LanguageSwitcher ls = new LanguageSwitcher(); Appleseed.Framework.Web.UI.WebControls.LanguageCultureCollection lcc = Appleseed.Framework.Localization.LanguageSwitcher.GetLanguageCultureList(); List <string[]> datos = new List <string[]>(); foreach (Appleseed.Framework.Web.UI.WebControls.LanguageCultureItem l in lcc) { string[] dato = new string[3]; string aux = l.ToString(); char[] array = new char[1]; array[0] = '/'; string[] lang = aux.Split(array); dato[0] = HttpUrlBuilder.BuildUrl("~/site/0/Home?lang=" + lang[0]); LanguageSwitcher lswitcher = new LanguageSwitcher(); dato[1] = lswitcher.GetFlagImgLCI(l); dato[1] = dato[1].Replace("images", "~/aspnet_client"); dato[1] = HttpUrlBuilder.BuildUrl(dato[1]); dato[2] = lswitcher.getNameLCI(l); datos.Add(dato); } ViewData["datos"] = datos; return(View()); }
/// <summary> /// Get current Language from User language list /// </summary> /// <param name="myLanguagesCultureList">My languages culture list.</param> /// <returns></returns> private static LanguageCultureItem InternalGetUserLanguages(LanguageCultureCollection myLanguagesCultureList) { // Get userLangs if (HttpContext.Current != null && HttpContext.Current.Request.UserLanguages != null && HttpContext.Current.Request.UserLanguages.Length > 0) { var arrUserLangs = new ArrayList(HttpContext.Current.Request.UserLanguages); if (arrUserLangs.Count > 0) { for (var i = 0; i <= arrUserLangs.Count - 1; i++) { string currentLanguage; if (arrUserLangs[i].ToString().IndexOf(';') >= 0) { currentLanguage = arrUserLangs[i].ToString().Substring( 0, arrUserLangs[i].ToString().IndexOf(';')); } else { currentLanguage = arrUserLangs[i].ToString(); } try { // We try the full one... if this fails we catch it arrUserLangs[i] = new CultureInfo(currentLanguage); } catch (ArgumentException) { try { // Some browsers can send an invalid language // we try to get first two letters.. this is usually valid arrUserLangs[i] = new CultureInfo(currentLanguage.Substring(2)); } catch (ArgumentException) { } return(null); } } } var userLangs = (CultureInfo[])arrUserLangs.ToArray(typeof(CultureInfo)); // Try to match browser "accept languages" list return(myLanguagesCultureList.GetBestMatching(userLangs)); } return(null); }
/// <summary> /// Updates data sources with grid content /// </summary> public void UpdateRows() { LanguageCultureCollection LanguagesDataSource = (LanguageCultureCollection)DataSource; for (Int32 i = 0; i < Items.Count; i++) { DropDownList ddLanguage = (DropDownList)Items[i].Cells[0].Controls[0]; DropDownList ddCulture = (DropDownList)Items[i].Cells[1].Controls[0]; LanguagesDataSource[i].UICulture = new CultureInfo(ddLanguage.SelectedItem.Value); LanguagesDataSource[i].Culture = new CultureInfo(ddCulture.SelectedItem.Value); } }
/// <summary> /// Get current Language from Query string /// </summary> /// <param name="myLanguagesCultureList">My languages culture list.</param> /// <returns></returns> private static LanguageCultureItem InternalGetQuerystring(LanguageCultureCollection myLanguagesCultureList) { if (HttpContext.Current != null && HttpContext.Current.Request.Params["Lang"] != null && HttpContext.Current.Request.Params["Lang"].Length > 0) { try { return (myLanguagesCultureList.GetBestMatching( new CultureInfo(HttpContext.Current.Request.Params["Lang"]))); } catch (ArgumentException) { // Maybe an invalid CultureInfo return(null); } } return(null); }
/// <summary> /// Get current Language from Cookie /// </summary> /// <param name="myLanguagesCultureList">My languages culture list.</param> /// <param name="cookieAlias">The cookie alias.</param> /// <returns></returns> private static LanguageCultureItem InternalGetCookie( LanguageCultureCollection myLanguagesCultureList, string cookieAlias) { if (HttpContext.Current != null && cookieAlias != null && HttpContext.Current.Request.Cookies[SwitcherCookiePrefix + cookieAlias] != null && HttpContext.Current.Request.Cookies[SwitcherCookiePrefix + cookieAlias].Value.Length > 0) { try { return (myLanguagesCultureList.GetBestMatching( new CultureInfo( HttpContext.Current.Request.Cookies[SwitcherCookiePrefix + cookieAlias].Value))); } catch (ArgumentException) { // Maybe an invalid CultureInfo } } return(null); }
private LanguageCultureCollection GetLanguagesCultureList(string keyValueList) { //Trim last separator if found keyValueList = keyValueList.TrimEnd(itemsSeparator); string[] nameValues = keyValueList.Split(itemsSeparator); LanguageCultureCollection nameValueColl = new LanguageCultureCollection(); foreach (string nameValue in nameValues) { if (nameValue != string.Empty) { string[] arrNameValue = nameValue.Split(keyValueSeparator); CultureInfo language; CultureInfo culture; language = new CultureInfo(arrNameValue[0]); if (arrNameValue.Length == 2) { culture = new CultureInfo(arrNameValue[1]); nameValueColl.Add(new LanguageCultureItem(language, culture)); } if (arrNameValue.Length == 1) { culture = new CultureInfo(arrNameValue[0]); if (culture.IsNeutralCulture) //we cannot allow this { culture = CultureInfo.CreateSpecificCulture(culture.Name); //creates a specific culture } nameValueColl.Add(new LanguageCultureItem(language, culture)); } } } return(nameValueColl); }
/// <summary> /// Occours when user clicks on ADD or DELETE /// </summary> /// <param name="e">A <see cref="T:System.Web.UI.WebControls.DataGridCommandEventArgs"></see> that contains event data.</param> protected override void OnItemCommand(DataGridCommandEventArgs e) { LanguageCultureCollection LanguagesDataSource = (LanguageCultureCollection)DataSource; switch (e.CommandName) { case "Add": LanguagesDataSource.Insert(e.Item.ItemIndex, new LanguageCultureItem()); DataBind(); break; case "Delete": LanguagesDataSource.RemoveAt(e.Item.ItemIndex); DataBind(); break; case "Up": break; case "Down": break; } base.OnItemCommand(e); }
/// <summary> /// Get default /// </summary> /// <param name="myLanguagesCultureList">My languages culture list.</param> /// <returns></returns> private static LanguageCultureItem InternalGetDefault(LanguageCultureCollection myLanguagesCultureList) { return(myLanguagesCultureList[0]); }