find and solve || findandsolve.com
Please wait.....

Globalization and Localization in ASP.NET

Globalization and Localization in ASP.NET


Globalization and Localization in ASP.NET MVC.Globalization and globalization is the process of designing apps that support different cultures   different type of language. in ASP.Net. Localization using Microsoft.AspNet.Mvc.

This article try to  address this types of topic.

globalization and localization in asp.net mvc

5 how to create multi language website in asp net mvc

asp.net mvc 5 localization

asp.net core localization shared resource

localization in asp.net core web api

razor pages localization

how to change language using resource file in asp net

mvc localization best practices 


Globalization :The process of designing and developing that works across multiple cultures / locales.

Localization  :The process of customizing a particular language. ie, which is easy to use in the target country.

In this post we will look at how we apply localization 

Step 1

open your mvc project as given below image

Implementing Globalization , Localization in MVC Razor

Step 2  

You must Create folder under your project solution like that
Right click your soluction name > click Add > click New Folder as giveb below
I have renmae folder name Language :-You can rename folder name as you like.

Implementing Globalization , Localization in MVC Razor

Step 3

Right click your folder name  "Language" > click "Add button" > Click "New Item"  As given below
When you click on New Item and you see the new windows layout like this.

Implementing Globalization , Localization in MVC Razor
 

Select Visual C # After selecting Visual C # you will see the menu of Visual C # on the site to your right. 

Find the Resources File on the menu of the Visual C # right site and select it. After selecting
Rename the Resources file as shown in the image below. I rename the Resources file to "Localization", you can name it yourself.

Implementing Globalization , Localization in MVC Razor

After Click Add button you will see given below image
 

Implementing Globalization , Localization in MVC Razor


Step 4 

Open Resources.resx fils 
Implementing Globalization , Localization in MVC Razor

 

Step 5 

Enter the key and value as like below screen.
Implementing Globalization , Localization in MVC Razor

 

 


Now I will add another file which will be language.ne.resx. This file will be used for local language. And I will add the same as shown above as given below. 

Note: you must select  "Acccess Modifire" Public as given below
 

Implementing Globalization , Localization in MVC Razor

 

 

Setp 6

Open "Global.asax" file under the project solution and past this code as given below  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace LocalizationDemo {     public class MvcApplication : System.Web.HttpApplication     {         protected void Application_Start()         {             AreaRegistration.RegisterAllAreas();             FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);             RouteConfig.RegisterRoutes(RouteTable.Routes);             BundleConfig.RegisterBundles(BundleTable.Bundles);         }           protected void Application_BeginRequest(object sender, EventArgs e)         {             HttpCookie cookie = HttpContext.Current.Request.Cookies["Language"];             if (cookie != null && cookie.Value != null )             {                 System.Threading.Thread.CurrentThread.CurrentCulture
                = new System.Globalization.CultureInfo(cookie.Value);                 System.Threading.Thread.CurrentThread.CurrentUICulture
                = new System.Globalization.CultureInfo(cookie.Value);             }             else             {                 System.Threading.Thread.CurrentThread.CurrentCulture 
                 = new System.Globalization.CultureInfo("en");                 System.Threading.Thread.CurrentThread.CurrentUICulture
               = new System.Globalization.CultureInfo("en");             }         }
    } }  

Step 7

Open your home controller and put this code 

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;
namespace LocalizationDemo.Controllers {     public class HomeController : Controller     {        public ActionResult Index()         {             return View();         }
        public ActionResult About()         {             ViewBag.Message = "Your application description page.";
            return View();         }
        public ActionResult Contact()         {             ViewBag.Message = "Your contact page.";
            return View();         }         public ActionResult ChangeLanguage(string selectedlanguage)         {             if (selectedlanguage != null)             {                 Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedlanguage);                 Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedlanguage);                 var cookie = new HttpCookie("Language");                 cookie.Value = selectedlanguage;                 Response.Cookies.Add(cookie);             }             return RedirectToAction("Index", "Home");         }     } }  

Step 8 

Open your home controller and go to Index page then put the given below code 

@{
    ViewBag.Title = "Home Page";
}
<div class="container">
    <h1>Localization Demo Project</h1>
    @Html.ActionLink("Local Language", "ChangeLanguage", "Home", new 
   { selectedlanguage = "ne" }, new { @class = "btn btn-default" })
    @Html.ActionLink("English Language", "ChangeLanguage", "Home",
    new { selectedlanguage = "en" }, new { @class = "btn btn-default" })
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />     <br />     <br />     <br />     <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <div class="row">
        <label>@LocalizationDemo.Language.Localization.First_name</label>
          <br />
        <label>@LocalizationDemo.Language.Localization.Last_name</label>
        <br />
       <label>@LocalizationDemo.Language.Localization.Address</label>
    </div>
</div>
</div>
</div>
</div>

If you have an any query please contact us by our website contact page 

More Details here


Sundar  Neupane

Sundar Neupane

I like working on projects with a team that cares about creating beautiful and usable interfaces.

If findandsolve.com felt valuable to you, feel free to share it.

1 Comments


Avatar for Rahul   Sharma
Rahul Sharma

Thank you so much for your beafutifule blog.Love it..........


Report Response