Skip to main content

Localization in angular4 by fetching data from server using VS2017

Localization in angular4 by fetching data from server using VS2017

Localization  in angular4 by fetching data from server using VS2017




1,This is my webapi controller from where the data for localization is fetched


//This is our webApi COntroller
 // GET: api/local/5
   [HttpGet, Route("api/local/{name}")]
        public IDictionary Get(string name)
        {
           
                Dictionary dict = new Dictionary();
                dict.Add("user01", "Nombre");//Name
                dict.Add("user02", "Nombre del Padre");//Father Name
                dict.Add("user03", "Direccion postal");//Postal Address
                return dict.ToDictionary(p => p.Key, p => p.Value);

        }


2,In our template url file, we will be giving the key of the dictionary object and covering it with a function which will fetch the value from the key  from the component


                    {{name("user01")}}
   


3,In our component  we have to write a get method to fetch the localization values from webapi controller



My Component.ts





//localisation-Json result from the service is passed to a html localstorage where our value is stored
and is used by our html page
        this.dataService.getlocal()
            .subscribe((item: any[]) => {
                if (item != null || item != undefined) {
                 
                    if (localStorage.getItem("localizationAray") != null) {
                        localStorage.removeItem("localizationAray");
                    }
                    localStorage.setItem("localizationAray", JSON.stringify(item));
                }
            });

    }

  //localization -This method is call from template url to get value fro  key . We will fetch value from the local storage in html5
    name(value: string) {
       
        var retVal = localStorage.getItem("localizationAray");
        var OrgVal = JSON.parse(retVal);
        if (OrgVal != null || OrgVal != undefined) {

            retVal = OrgVal[value];
        }

        return retVal;
    }



My Service.ts

//local- This service fetch dictionary value from webApi controller
    getlocal() {
        var retVal = localStorage.getItem("userlang").toString();
      //  return this.http.get('api/local/?name=${retVal}')
        //'"' + retVal + '"'
        return this.http.get('api/local/' + retVal )
            .map((res: Response) => res.json());
    }


Please free to comment under for any further clarification.



Comments

Popular posts from this blog

Gemini software Dot net interview question for experienced

Gemini Interview questions 4-8 year experienced Dot net professional Gemini Interview questions 4-8 year experienced Dot net professional 1,Asp .net mvc request life cycle. 2,How routing works 3,Where codes for routing are written 4,What is attribute based routing in aap.net Mvc 5,Is multiple routes possible on a single action method. 6,What is action filters. 7,what is authentication and authorization filters 8,What are the types of authentication 8,What is the use of data annotation 9,Can we fire data annotation in client side. 10,What is model binding 11,what are Html helpers

TCS Interview Questions .Net experienced

   TCS Interview Questions .Net experienced 1)How did you implemented classes in your project? 2) Asp.net page life cycle? Explain briefly? 3) Asp.net page events? 4) How iis recognize that which web application we are requesting? 5) How iis recognize that web application is developed in which language? 6) How iis will use authentication? 7) Is it pages will compile in server? 8) In server pages will compile or execute? 9) What is diff between compile and execute? 10) What is appdomain? 11) What is aspnet_issapi.dll? 12) What is aspnet_wp.exe? 13) What is application? 14) What is view state? 15) Why we use view state? 16) What are the validation controls? Explain the use of validation controls? 17) Validation controls are client side or server side? 18) How to make raise JavaScript at the page is displaying? (which page event will use eg: page_load) ? 19) What is session? 20) Is it necessary to create session object? (ans :no)   21) What...

ASP .Net MVC

ASp .Net MVC 1. Explain MVC (Model-View-Controller) in general? MVC (Model-View-Controller) is an architectural software pattern that basically decouples various components of a web application. By using MVC pattern, we can develop applications that are more flexible to changes without affecting the other components of our application. §    “Model”, is basically domain data. §    “View”, is user interface to render domain data. §    “Controller”, translates user actions into appropriate operations performed on model. 2. What is ASP.NET MVC? ASP.NET MVC is a web development framework from Microsoft that is based on MVC (Model-View-Controller) architectural design pattern. Microsoft has streamlined the development of MVC based applications using ASP.NET MVC framework. 3. Difference between ASP.NET MVC and ASP.NET WebForms? ASP.NET Web Forms uses Page controller pattern approach for rendering layout, whereas ASP.NET MVC uses Front con...