diff --git a/projects/common/src/fm/actions/app-common.actions.ts b/projects/common/src/fm/actions/app-common.actions.ts index ca8ef37..71e17e7 100644 --- a/projects/common/src/fm/actions/app-common.actions.ts +++ b/projects/common/src/fm/actions/app-common.actions.ts @@ -83,6 +83,8 @@ export const SETPAGEMODE = '[AppCommon] SetPageMode'; export const SETUNREADNOTIFICATIONS = '[AppCommon] SetUnreadNotifications'; +export const SWITCHLANGUAGE = '[AppCommon] SwitchLanguage'; + export class InitUser implements Action { readonly type = INITUSER; @@ -371,6 +373,12 @@ export class SetUnreadNotifications implements Action { } +export class SwitchLanguage implements Action { + readonly type = SWITCHLANGUAGE; + + constructor(public locale:string) { } +} + export type Actions = OpenModal | InitRoot @@ -418,6 +426,7 @@ export type Actions = OpenModal | ToggleHelpMenu | ToggleSettingMenu | NotificationEvent - | SetUnreadNotifications; + | SetUnreadNotifications + | SwitchLanguage; diff --git a/projects/common/src/fm/effects/app-common.effects.ts b/projects/common/src/fm/effects/app-common.effects.ts index 87e42ff..da41a12 100644 --- a/projects/common/src/fm/effects/app-common.effects.ts +++ b/projects/common/src/fm/effects/app-common.effects.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@angular/core'; +import { Injectable, Inject, LOCALE_ID } from '@angular/core'; import { Router } from '@angular/router'; import { OAuthService,UserInfo } from 'angular-oauth2-oidc'; import { Store } from '@ngrx/store'; @@ -16,6 +16,7 @@ import {StateSerializerService} from '../services/state-serializer.service'; @Injectable() export class AppCommonEffects { + locale: string; login$ = createEffect(() => this.actions$.pipe( ofType(appCommonActions.LOGIN), @@ -47,11 +48,24 @@ export class AppCommonEffects { first(), switchMap((action) => { return zip(this.userService$.getCurrentUser(),from(this.oauthService$.loadUserProfile())).pipe( - switchMap(([user,userInfo]) => {return of(new appCommonActions.InitUserSuccess(user,userInfo as UserInfo))} ), + switchMap(([user,userInfo]) => { + if (location.hostname === 'localhost' || user.language === undefined || user.language === this.locale) + { + return of(new appCommonActions.InitUserSuccess(user,userInfo as UserInfo)) + } + return of(new appCommonActions.SwitchLanguage(user.language)) + }), catchError(error => of(new appCommonActions.Fail(error)))) } ))); - + + switchLanguage$ = createEffect(() => this.actions$.pipe( + ofType(appCommonActions.SWITCHLANGUAGE), + switchMap((action) => { + const a = action as appCommonActions.SwitchLanguage; + location.replace(`/${a.locale}/`); + return of(undefined); + })),{ dispatch:false}); initUserPackages$ = createEffect(() => this.actions$.pipe( ofType(appCommonActions.INITUSERPACKAGES), @@ -208,7 +222,12 @@ export class AppCommonEffects { - constructor(private actions$: Actions, private store$: Store, private oauthService$: OAuthService, private itemService$: ItemService, private folderService$:FolderService, private userService$: UserService, private router$: Router, private stateSerializerService$:StateSerializerService) { + constructor(private actions$: Actions, private store$: Store, private oauthService$: OAuthService, private itemService$: ItemService, private folderService$:FolderService, private userService$: UserService, private router$: Router, private stateSerializerService$:StateSerializerService, @Inject(LOCALE_ID) locale: string) { + this.locale = locale; store$.dispatch(new appCommonActions.LoadItemTypes()); } } +function tap(arg0: () => any): any { + throw new Error('Function not implemented.'); +} +