void InitCulture() { try { string currentCulture = ServerSettings.Instance.Culture; cboLanguages.ItemsSource = UserCulture.SupportedLanguages; for (int i = 0; i < cboLanguages.Items.Count; i++) { UserCulture ul = cboLanguages.Items[i] as UserCulture; if (ul.Culture.Trim().ToUpper() == currentCulture.Trim().ToUpper()) { cboLanguages.SelectedIndex = i; break; } } if (cboLanguages.SelectedIndex < 0) { cboLanguages.SelectedIndex = 0; } } catch (Exception ex) { Utils.ShowErrorMessage(ex); } }
public static string GetGlobalizedLabel(string page, string label, string CultureName) { if (string.IsNullOrWhiteSpace(label)) { return(label); } if (label.Contains(' ')) { return(label); } UserCulture userCulture = new UserCulture(); userCulture = GetCultureObject(CultureName); if (userCulture.CultureXML != null) { string globalTextForLabel = label; string xmlSearchPattern = "/CultureInformation/" + page + "/" + label; XmlNode objNode = userCulture.CultureXML.SelectSingleNode(xmlSearchPattern); if (objNode != null) { globalTextForLabel = objNode.InnerText; } return(globalTextForLabel); } return(label); }
public static UserCulture GetCultureObject(string CultureName) { UserCulture user = new UserCulture(); user.CultureName = CultureName; user.CultureXML = objCultureInformation[CultureName]; return(user); }
public async Task <ActionResult> Register(RegisterViewModel model, string returnUrl) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { // Linkea la cuenta remota con la local var r = await db.StoredProcedureRegisterUser(user.Id, model.Sex.ToString()); if (r) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); using (var userService = new UserService()) { userService.AddRoleToUser("User", user.Id); // Save User Language // TODO: Get ISO Country Code from USER IP Adress // var userInformation = userService.UserInformation; // var userHostAddress = GetIPAddress() ?? Request.UserHostAddress; // var countryISORegion = userService.GetUserHostRegion(userHostAddress); var userInformation = await db.StoredProcedureGetUserInformationId(user.Id); var userCulture = new UserCulture { UserId = userInformation.Id, ISORegion = Service.Region, ISOLanguage = Service.Language }; db.UserCulture.Add(userCulture); db.SaveChanges(); } // Save Language cookie SaveCookie("County", Service.Region); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToLocal($"~/{Service.Language}/{Service.HomeTitle}")); } } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public static UserCulture GetCultureObject() { ///if sessionmanagement.loggedinuser is not null ///get culture of loggedin user ///else if get culutre from cookie ///else ///get culdture from application var UserCulture userCulture = new UserCulture(); if (HttpContext.Current.Application[CultureInformationManagement.CurrentUserCulture] != null) { userCulture = (UserCulture)HttpContext.Current.Application[CultureInformationManagement.CurrentUserCulture]; } return(userCulture); }
/// <summary> /// This methid will set the culture at application label /// </summary> /// <param name="cultureName"></param> /// <param name="lablesXML"></param> public static void SetCultureObject(string cultureName, string lablesXML, bool isActive = true) { UserCulture userCulture = new UserCulture(); XmlDocument xmlDocCulture = new XmlDocument(); if (isActive == false) { HttpContext.Current.Application[cultureName] = userCulture; } else { if (!string.IsNullOrEmpty(lablesXML)) { xmlDocCulture.LoadXml(lablesXML); } userCulture.CultureName = cultureName; userCulture.CultureXML = xmlDocCulture; HttpContext.Current.Application[cultureName] = userCulture; } }
public static string GetGlobalizedDropDownItemText(string dropDownName, string itemText) { UserCulture userCulture = new UserCulture(); userCulture = CultureInformationManagement.GetCultureObject(); if (userCulture.CultureXML != null) { string globalTextForLabel = itemText; string xmlSearchPattern = "/CultureInformation/" + dropDownName + "/" + itemText; XmlNode objNode = userCulture.CultureXML.SelectSingleNode(xmlSearchPattern); if (objNode != null) { globalTextForLabel = objNode.InnerText; } return(globalTextForLabel); } return(itemText); }
private void SetCulture() { if (cboLanguages.SelectedItem == null) { return; } UserCulture ul = cboLanguages.SelectedItem as UserCulture; bool isLanguageChanged = ServerSettings.Culture != ul.Culture; System.Windows.Forms.DialogResult result; try { CultureInfo ci = new CultureInfo(ul.Culture); CultureInfo.DefaultThreadCurrentUICulture = ci; CultureManager.UICulture = ci; ServerSettings.Culture = ul.Culture; if (isLanguageChanged) { result = System.Windows.Forms.MessageBox.Show(Shoko.Commons.Properties.Resources.Language_Info, Shoko.Commons.Properties.Resources.Language_Switch, System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Information); if (result != System.Windows.Forms.DialogResult.OK) { return; } System.Windows.Forms.Application.Restart(); ShokoServer.Instance.ApplicationShutdown(); } } catch (Exception ex) { Utils.ShowErrorMessage(ex); } }