Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: correctly use local language in document site #1648

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/theme/src/services/i18n/i18n-url.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export class AlainI18NGuardService {
}

/**
* Simple 路由守卫, [ACL Document](https://ng-alain.com/auth/guard).
* Internationalization guard, automatically recognizes the language in Url and triggers the `ALAIN_I18N_TOKEN.use` method
*
* 国际化守卫,自动识别Url中的语言,并触发 `ALAIN_I18N_TOKEN.use` 方法
*
* ```ts
* data: {
Expand All @@ -37,7 +39,9 @@ export class AlainI18NGuardService {
export const alainI18nCanActivate: CanActivateFn = childRoute => inject(AlainI18NGuardService).process(childRoute);

/**
* Simple 路由守卫, [ACL Document](https://ng-alain.com/auth/guard).
* Internationalization guard, automatically recognizes the language in Url and triggers the `ALAIN_I18N_TOKEN.use` method
*
* 国际化守卫,自动识别Url中的语言,并触发 `ALAIN_I18N_TOKEN.use` 方法
*
* ```ts
* data: {
Expand Down
3 changes: 2 additions & 1 deletion src/app/layout/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { copy } from '@delon/util/browser';
import type { NzSafeAny } from 'ng-zorro-antd/core/types';
import { NzMessageService } from 'ng-zorro-antd/message';

import { I18NService, MobileService } from '@core';
import { I18NService, LangType, MobileService } from '@core';

import { MetaSearchGroupItem } from '../../interfaces';
import { LayoutComponent } from '../layout.component';
Expand Down Expand Up @@ -100,6 +100,7 @@ export class HeaderComponent implements AfterViewInit {
}

langChange(language: 'en' | 'zh'): void {
this.i18n.use(language as LangType, {}, false);
this.router.navigateByUrl(`${this.i18n.getRealUrl(this.router.url)}/${language}`).then(() => {
this.layout.render = false;
setTimeout(() => {
Expand Down
3 changes: 0 additions & 3 deletions src/app/routes/routes.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { NgModule } from '@angular/core';
import { Route, RouterModule } from '@angular/router';

import { alainI18nCanActivate } from '@delon/theme';

import { NotFoundComponent } from './404/404.component';
import { HomeComponent } from './home/home.component';
import { LayoutComponent } from '../layout/layout.component';
Expand All @@ -14,7 +12,6 @@ const routes: Route[] = [
{
path: '',
component: LayoutComponent,
canActivateChild: [alainI18nCanActivate],
children: [
{ path: '', redirectTo: 'en', pathMatch: 'full' },
{ path: ':lang', component: HomeComponent, data: { titleI18n: 'slogan' } },
Expand Down