Skip to content

Commit

Permalink
update locale
Browse files Browse the repository at this point in the history
  • Loading branch information
WeihanLi committed Dec 26, 2024
1 parent bd0036d commit cbbe739
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,60 @@
import { Component, Inject, LOCALE_ID } from '@angular/core';
import { MenuItem } from './models/MenuItem';
import { Router, NavigationStart } from '@angular/router';
import { LoadingService } from './services/LoadingService';
import { OAuthService } from 'angular-oauth2-oidc';
import * as authConfig from './shared/authConfig';
import { Component, Inject, LOCALE_ID } from "@angular/core";
import { MenuItem } from "./models/MenuItem";
import { Router, NavigationStart } from "@angular/router";
import { LoadingService } from "./services/LoadingService";
import { OAuthService } from "angular-oauth2-oidc";
import * as authConfig from "./shared/authConfig";

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.less'],
standalone: false
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.less"],
standalone: false,
})
export class AppComponent {
constructor(public loadingSvc: LoadingService,
private router:Router,
private oauth: OAuthService,
@Inject(LOCALE_ID) public currentLocale: string
) {
constructor(
public loadingSvc: LoadingService,
private router: Router,
private oauth: OAuthService,
@Inject(LOCALE_ID) public currentLocale: string
) {
this.oauth.configure(authConfig.authCodeFlowConfig);
this.oauth.loadDiscoveryDocument();

this.loadingSvc.isLoading = true;
this.router.events.subscribe((e) => { if(e instanceof NavigationStart) {this.loadingSvc.isLoading = true;} });
this.router.events.subscribe((e) => {
if (e instanceof NavigationStart) {
this.loadingSvc.isLoading = true;
}
});

console.debug(`Current locale_id is ${currentLocale}`);
}

title = 'OpenReservation';
title = "OpenReservation";
year = new Date().getFullYear();

menus: Array<MenuItem> = [
{ Title: "首页", Link: "/" },
{ Title: "我的", Link: "/account/reservations"},
{ Title: "预约", Link: "/reservations/new"},
{ Title: "我的", Link: "/account/reservations" },
{ Title: "预约", Link: "/reservations/new" },
{ Title: "公告", Link: "/notice" },
{ Title: "关于", Link: "/about" },
];


localeChanged(event:any) {
localeChanged(event: any) {
var newLocale = event.value;
var newLocation = location.href.replace(`/${this.currentLocale}/`, `/${newLocale}/`);
if (newLocale === this.currentLocale){
return;
}
// update locale
var newLocation = location.href.replace(
`/${this.currentLocale}/`,
`/${newLocale}/`
);
if (newLocation === location.href) return;

console.log(`newLocation: ${newLocation}`);
console.debug(`newLocation: ${newLocation}`);
location.assign(newLocation);
}
}

0 comments on commit cbbe739

Please sign in to comment.