Skip to content

Commit 0048e70

Browse files
Localization error. Fixes :#315
1 parent a4dcecf commit 0048e70

File tree

5 files changed

+56
-10
lines changed

5 files changed

+56
-10
lines changed

angular/src/AppPreBootstrap.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export class AppPreBootstrap {
2626
}).done(result => {
2727
AppConsts.appBaseUrl = result.appBaseUrl;
2828
AppConsts.remoteServiceBaseUrl = result.remoteServiceBaseUrl;
29-
29+
AppConsts.localeMappings = result.localeMappings;
30+
3031
callback();
3132
});
3233
}

angular/src/assets/appconfig.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
{
22
"remoteServiceBaseUrl": "http://localhost:21021",
3-
"appBaseUrl": "http://localhost:4200"
4-
}
3+
"appBaseUrl": "http://localhost:4200",
4+
"localeMappings": [
5+
{
6+
"from": "pt-BR",
7+
"to": "pt"
8+
},
9+
{
10+
"from": "zh-CN",
11+
"to": "zh"
12+
},
13+
{
14+
"from": "he-IL",
15+
"to": "he"
16+
}
17+
]
18+
}

angular/src/root.module.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BrowserModule } from '@angular/platform-browser';
22
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
33
import { NgModule, Injector, APP_INITIALIZER, LOCALE_ID } from '@angular/core';
4-
import { PlatformLocation } from '@angular/common';
4+
import { PlatformLocation, registerLocaleData } from '@angular/common';
55

66
import { AbpModule } from '@abp/abp.module';
77
import { AbpHttpInterceptor } from '@abp/abpHttpInterceptor';
@@ -20,6 +20,8 @@ import { AppPreBootstrap } from './AppPreBootstrap';
2020
import { ModalModule } from 'ngx-bootstrap';
2121
import { HttpClientModule } from '@angular/common/http';
2222

23+
import * as _ from 'lodash';
24+
2325
export 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+
5079
export function getRemoteServiceBaseUrl(): string {
5180
return AppConsts.remoteServiceBaseUrl;
5281
}

angular/src/shared/AppConsts.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export class AppConsts {
44
static appBaseUrl: string;
55
static appBaseHref: string; // returns angular's base-href parameter value if used during the publish
66

7+
static localeMappings: any = [];
8+
79
static readonly userManagement = {
810
defaultAdminUserName: 'admin'
911
};

angular/src/tsconfig.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"experimentalDecorators": true,
66
"lib": [ "es6", "dom" ],
77
"mapRoot": "./",
8-
"module": "es6",
8+
"module": "esnext",
99
"moduleResolution": "node",
1010
"outDir": "../dist/out-tsc",
1111
"sourceMap": true,
@@ -15,10 +15,10 @@
1515
],
1616
"baseUrl": ".",
1717
"paths": {
18-
"@abp/*": [ "../node_modules/abp-ng2-module/dist/src/*" ],
19-
"@app/*": [ "./app/*" ],
20-
"@shared/*": [ "./shared/*" ],
21-
"@node_modules/*": [ "../node_modules/*" ]
18+
"@abp/*": [ "../node_modules/abp-ng2-module/dist/src/*" ],
19+
"@app/*": [ "./app/*" ],
20+
"@shared/*": [ "./shared/*" ],
21+
"@node_modules/*": [ "../node_modules/*" ]
2222
}
2323
},
2424
"exclude": [

0 commit comments

Comments
 (0)