Skip to content

Commit cbbe739

Browse files
committed
update locale
1 parent bd0036d commit cbbe739

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

src/app/app.component.ts

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,60 @@
1-
import { Component, Inject, LOCALE_ID } from '@angular/core';
2-
import { MenuItem } from './models/MenuItem';
3-
import { Router, NavigationStart } from '@angular/router';
4-
import { LoadingService } from './services/LoadingService';
5-
import { OAuthService } from 'angular-oauth2-oidc';
6-
import * as authConfig from './shared/authConfig';
1+
import { Component, Inject, LOCALE_ID } from "@angular/core";
2+
import { MenuItem } from "./models/MenuItem";
3+
import { Router, NavigationStart } from "@angular/router";
4+
import { LoadingService } from "./services/LoadingService";
5+
import { OAuthService } from "angular-oauth2-oidc";
6+
import * as authConfig from "./shared/authConfig";
77

88
@Component({
9-
selector: 'app-root',
10-
templateUrl: './app.component.html',
11-
styleUrls: ['./app.component.less'],
12-
standalone: false
9+
selector: "app-root",
10+
templateUrl: "./app.component.html",
11+
styleUrls: ["./app.component.less"],
12+
standalone: false,
1313
})
1414
export class AppComponent {
15-
constructor(public loadingSvc: LoadingService,
16-
private router:Router,
17-
private oauth: OAuthService,
18-
@Inject(LOCALE_ID) public currentLocale: string
19-
) {
15+
constructor(
16+
public loadingSvc: LoadingService,
17+
private router: Router,
18+
private oauth: OAuthService,
19+
@Inject(LOCALE_ID) public currentLocale: string
20+
) {
2021
this.oauth.configure(authConfig.authCodeFlowConfig);
2122
this.oauth.loadDiscoveryDocument();
2223

2324
this.loadingSvc.isLoading = true;
24-
this.router.events.subscribe((e) => { if(e instanceof NavigationStart) {this.loadingSvc.isLoading = true;} });
25+
this.router.events.subscribe((e) => {
26+
if (e instanceof NavigationStart) {
27+
this.loadingSvc.isLoading = true;
28+
}
29+
});
30+
31+
console.debug(`Current locale_id is ${currentLocale}`);
2532
}
2633

27-
title = 'OpenReservation';
34+
title = "OpenReservation";
2835
year = new Date().getFullYear();
2936

3037
menus: Array<MenuItem> = [
3138
{ Title: "首页", Link: "/" },
32-
{ Title: "我的", Link: "/account/reservations"},
33-
{ Title: "预约", Link: "/reservations/new"},
39+
{ Title: "我的", Link: "/account/reservations" },
40+
{ Title: "预约", Link: "/reservations/new" },
3441
{ Title: "公告", Link: "/notice" },
3542
{ Title: "关于", Link: "/about" },
3643
];
3744

38-
39-
localeChanged(event:any) {
45+
localeChanged(event: any) {
4046
var newLocale = event.value;
41-
var newLocation = location.href.replace(`/${this.currentLocale}/`, `/${newLocale}/`);
47+
if (newLocale === this.currentLocale){
48+
return;
49+
}
50+
// update locale
51+
var newLocation = location.href.replace(
52+
`/${this.currentLocale}/`,
53+
`/${newLocale}/`
54+
);
4255
if (newLocation === location.href) return;
4356

44-
console.log(`newLocation: ${newLocation}`);
57+
console.debug(`newLocation: ${newLocation}`);
4558
location.assign(newLocation);
4659
}
4760
}

0 commit comments

Comments
 (0)