Learn MVC Using Angular Dynamic Localization

Introduction

This article demonstrates low to use Agular dynamic localization in MVC using the Angular i18n package in Visual Studio 2017.

Localization

Localization is a very important part of region based applications. It customizes your application for a given culture and locale. So, this localization can change dynamically using Angular Dynamic Locale Module.

By following the below steps, you can use Angular file upload in MVC.

  • Create MVC Project.
  • Configure Angular i18n and Dynamic Locale.
  • Work in Angular i18n and Dynamic Locale.

Create MVC Project

Open Visual Studio 2017.

Angular

Go to New menu > click New and Project. Now, it will open a New Project window.

Angular

You can select ASP.NET Web Application on Framework 4.5. Enter the name of the project in “Solution name” text box, then click OK.

Angular

One more window should appear. Select the MVC Template in this pop-up and click OK. Now, start cropping the image.

Configure Angular i18n and Dynamic Locale

You can download the plug-in from:

Or you can install it from npm. If you try npm, don’t forget to install Node.js. Then, use the following commands:

npm install angular-i18n 

npm install angular-dynamic-locale 

Open the _Layout.cshtml and refer the.js file from downloaded folder to this View page.


Link your Angular configurable file.


Angular Module

You will need to include the module as a dependency on your application.


 Work in Angular i18n and Dynamic Locale

“Locale” is my Angular module name. So, I have added as the value for “ng-app.”

HTML Code

Angular Config

This module expects for the Angular locales to present at ‘angular-i18n/angular-locale_{{locale}}.js.’ If the locales are at another URL, this can be changed at tmhDynamicLocaleProvider using localeLocationPattern (string).

Angular Controller

Angular initiates the locale in a dropdown and sets the locale id as “en” in Angular.

When using this method, tmhDynamicLocale.set will return a promise that will be resolved when the locale is loaded and will resolve to the new locale

Click the F5 button and run the application. Now, it will open the browser where you can see the result.

Output 1

Angular

I have loaded default locale as English.

Output 2

Angular

I have changed the locale to Chinese, so the data is changed to Chinese.

Conclusion

In this article, we have seen dynamic localization using Angular i18n. If you have any queries, please tell me through the comments section.

Happy Coding!

Related Posts

  • 79
    This article demonstrates MVC using Angular Idle with a UI Bootstrap. This article will show you how to get your application to report if a…
    Tags: angular, will, /script, script, mvc, studio, visual, angularjs
  • 78
    Introduction Hi, audience. I thought I would share my experiences with Microsoft ASP.NET MVC and AngularJS. This article will be more helpful for “MVC with…
    Tags: mvc, angularjs, will, studio, visual
  • 76
    Introduction This article demonstrates how to use MVC using Angular Image Crop and Bootstrap Filestyle in Visual Studio 2017. Angular Image Crop When you upload…
    Tags: angular, will, script, /script, mvc, studio, visual, angularjs
  • 76
    Introduction In this article, we will learn MVC, using Angular Pie Chart, which is used for two types of UI, which are given below. Angular…
    Tags: angular, mvc, /script, script, will, studio, visual, angularjs
  • 74
    Introduction This article demonstrates how to create MVC applications using Angular UI-Select with Bootstrap. This article is useful for implementing auto-complete text in your application.…
    Tags: angular, studio, visual, angularjs
Show Buttons
Hide Buttons