11import { BrowserModule } from '@angular/platform-browser' ;
22import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
33import { NgModule , Injector , APP_INITIALIZER , LOCALE_ID } from '@angular/core' ;
4- import { PlatformLocation } from '@angular/common' ;
4+ import { PlatformLocation , registerLocaleData } from '@angular/common' ;
55
66import { AbpModule } from '@abp/abp.module' ;
77import { AbpHttpInterceptor } from '@abp/abpHttpInterceptor' ;
@@ -20,6 +20,8 @@ import { AppPreBootstrap } from './AppPreBootstrap';
2020import { ModalModule } from 'ngx-bootstrap' ;
2121import { HttpClientModule } from '@angular/common/http' ;
2222
23+ import * as _ from 'lodash' ;
24+
2325export function appInitializerFactory ( injector : Injector ,
2426 platformLocation : PlatformLocation ) {
2527 return ( ) => {
@@ -35,7 +37,17 @@ export function appInitializerFactory(injector: Injector,
3537 appSessionService . init ( ) . then (
3638 ( result ) => {
3739 abp . ui . clearBusy ( ) ;
38- resolve ( result ) ;
40+
41+ if ( shouldLoadLocale ( ) ) {
42+ let angularLocale = convertAbpLocaleToAngularLocale ( abp . localization . currentLanguage . name ) ;
43+ import ( `@angular/common/locales/${ angularLocale } .js` )
44+ . then ( module => {
45+ registerLocaleData ( module . default ) ;
46+ resolve ( result ) ;
47+ } , reject ) ;
48+ } else {
49+ resolve ( result ) ;
50+ }
3951 } ,
4052 ( err ) => {
4153 abp . ui . clearBusy ( ) ;
@@ -47,6 +59,23 @@ export function appInitializerFactory(injector: Injector,
4759 }
4860}
4961
62+ export function convertAbpLocaleToAngularLocale ( locale : string ) : string {
63+ if ( ! AppConsts . localeMappings ) {
64+ return locale ;
65+ }
66+
67+ let localeMapings = _ . filter ( AppConsts . localeMappings , { from : locale } ) ;
68+ if ( localeMapings && localeMapings . length ) {
69+ return localeMapings [ 0 ] [ 'to' ] ;
70+ }
71+
72+ return locale ;
73+ }
74+
75+ export function shouldLoadLocale ( ) : boolean {
76+ return abp . localization . currentLanguage . name && abp . localization . currentLanguage . name !== 'en-US' ;
77+ }
78+
5079export function getRemoteServiceBaseUrl ( ) : string {
5180 return AppConsts . remoteServiceBaseUrl ;
5281}
0 commit comments