Showing posts with label Localization. Show all posts
Showing posts with label Localization. Show all posts

Wednesday, January 16, 2019

how to use the resource file from other page in ASP.Net web application

we can localize the web application with the resource file from Visual studio. Visual studio automaticaly generate the resource file under this folder.

c:\projectfolder\App_LocalResources

in the page level we can use the key in the resource to reference the content.

<asp:Literal runat="server" Text="<%$ Resources:MyKey %>" />

if we want to use this content in other pages.

we can simply follow the steps below

1. add the reference to the resource namespace, you can find the namespace from the design.cs file.

<%@ Import Namespace="Resources.UserControls" %>



2. add the following line to your page which have a reference to the resource file and key.

<%=MyOtherPage_ascx.MyOtherKey %> 






Thursday, February 22, 2018

How to implement localization on MVC web application with ActionFilterAttribute?

when we implement the asp.net web application. we can easily to localize the web UI with Resource files. we just need to override the InitializeCulture Method in the Page class to initialize the Culture and UICulture information for the page.

However the approach is quite different in the MVC app implement. we will create new ActionFilterAction attribute to render the content in the OnActionExecuting event.


 public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            your business logic on localization handling
        }

put the above inside your class that extend the ActionFilterAttribute.

public class LanguageAttribute : ActionFilterAttribute
    {
    
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //put yPostsour logic here to handle the localization
        }
    }