Elie Todjom

Elie Todjom

  • NA
  • 18
  • 1k

Localization with CurrentCulture

Sep 18 2017 3:09 PM
Hello Everybody,
 
I'm new in hier and I need some Help. I follow this example
 
http://www.c-sharpcorner.com/UploadFile/4d9083/globalization-and-localization-in-Asp-Net-mvc-4/
 
to create a asp.net Mvc app in English and German, but to my supprise the App is only showing German and not English.
 
I don't know what a did wrog hier is my code.
 
Home Controller:
 
  1. namespace FirstCargoApp.Controllers  
  2. {  
  3. public class HomeController : BaseController  
  4. {  
  5. public ActionResult Index()  
  6. {  
  7. return View(new LoginViewModel());  
  8. }  
  9. public ActionResult ChangeCurrentCulture(int id)  
  10. {  
  11. //  
  12. // Change the current culture for this user.  
  13. //  
  14. LocalisationHelper.CurrentCulture = id;  
  15. //  
  16. // Cache the new current culture into the user HTTP session.  
  17. //  
  18. Session["CurrentCulture"] = id;  
  19. //  
  20. // Redirect to the same page from where the request was made!  
  21. //  
  22. return Redirect(Request.UrlReferrer.ToString());  
  23. }  
  24. }  
  25. }  
LoginView:
  1. @model FirstCargoApp.Models.LoginViewModel  
  2. @{  
  3. ViewBag.Title = "Anmelden";  
  4. }  
  5. @ViewBag.Title.  
  6.   
  7. @using (Html.BeginForm("Login""Account"new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))  
  8. {  
  9. @Html.AntiForgeryToken()  
  10. Lokales Konto für die Anmeldung verwenden.  
  11.   
  12. @Html.ValidationSummary(true)  
  13. @Html.LabelFor(model => model.UserName, new { @class = "col-md-2 control-label" })  
  14. @Html.TextBoxFor(model => model.UserName, new { @class = "form-control" })  
  15. @Html.ValidationMessageFor(model => model.UserName)  
  16. @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })  
  17. @Html.PasswordFor(m => m.Password, new { @class = "form-control" })  
  18. @Html.ValidationMessageFor(m => m.Password)  
  19. @Html.CheckBoxFor(m => m.RememberMe)  
  20. @Html.LabelFor(m => m.RememberMe)  
  21. Anmelden  
  22.   
  23. @Html.ActionLink("Registrieren""Register") wenn Sie kein lokales Konto besitzen.  
  24.   
  25. }  
  26. @*  
  27. @Html.Partial("_ExternalLoginsListPartial"new { Action = "ExternalLogin", ReturnUrl = ViewBag.ReturnUrl })  
  28. *@  
  29. @section Scripts {  
  30. @Scripts.Render("~/bundles/jqueryval")  
  31. }  
  32. using FirstCargoApp.LocalResource;  
  33. namespace FirstCargoApp.Models  
  34. {  
  35. public class ExternalLoginConfirmationViewModel  
  36. {  
  37. [Required]  
  38. [Display(Name = "UserName", ResourceType = typeof(Resource))]  
  39. public string UserName { getset; }  
  40. }  
  41. public class ManageUserViewModel  
  42. {  
  43. [Required]  
  44. [DataType(DataType.Password)]  
  45. [Display(Name = "Aktuelles Kennwort")]  
  46. public string OldPassword { getset; }  
  47. [Required]  
  48. [StringLength(100, ErrorMessage = "\"{0}\" muss mindestens {2} Zeichen lang sein.", MinimumLength = 6)]  
  49. [DataType(DataType.Password)]  
  50. [Display(Name = "Neues Kennwort")]  
  51. public string NewPassword { getset; }  
  52. [DataType(DataType.Password)]  
  53. [Display(Name = "Neues Kennwort bestätigen")]  
  54. [Compare("NewPassword", ErrorMessage = "Das neue Kennwort stimmt nicht mit dem Bestätigungskennwort überein.")]  
  55. public string ConfirmPassword { getset; }  
  56. }  
  57. public class LoginViewModel  
  58. {  
  59. [Required]  
  60. [Display(Name = "UserName", ResourceType = typeof(Resource))]  
  61. public string UserName { getset; }  
  62. [Required]  
  63. [DataType(DataType.Password)]  
  64. [Display(Name = "Password", ResourceType = typeof(Resource))]  
  65. public string Password { getset; }  
  66. [Display(Name = "Speichern?")]  
  67. public bool RememberMe { getset; }  
  68. }  
I have 3 Resource Files
 
Resource.en-GB
Resource.de-DE
Resource
 
For the rest i just copy it from the Tutorial up.
 
Please can someone help me
 
Thanks

Answers (1)