Browse Source

Merge pull request #22629 from abpframework/issue/22627

Angular - Fixing the navbar localization problem for the basic theme
pull/22642/head
oykuermann 1 year ago
committed by GitHub
parent
commit
4e9e0187cd
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 15
      npm/ng-packs/packages/theme-basic/src/lib/components/routes/routes.component.html
  2. 9
      npm/ng-packs/packages/theme-basic/src/lib/components/routes/routes.component.ts
  3. 1
      npm/ng-packs/packages/theme-basic/src/lib/pipes/index.ts
  4. 20
      npm/ng-packs/packages/theme-basic/src/lib/pipes/lazy-translate.pipe.ts
  5. 2
      npm/ng-packs/packages/theme-basic/src/lib/theme-basic.module.ts
  6. 1
      npm/ng-packs/packages/theme-basic/src/public-api.ts

15
npm/ng-packs/packages/theme-basic/src/lib/components/routes/routes.component.html

@ -3,8 +3,7 @@
<ng-container <ng-container
[ngTemplateOutlet]="isDropdown(route) ? dropdownLink : defaultLink" [ngTemplateOutlet]="isDropdown(route) ? dropdownLink : defaultLink"
[ngTemplateOutletContext]="{ $implicit: route }" [ngTemplateOutletContext]="{ $implicit: route }"
> />
</ng-container>
} }
<ng-template #defaultLink let-route> <ng-template #defaultLink let-route>
@ -13,7 +12,7 @@
@if (route.iconClass) { @if (route.iconClass) {
<i [ngClass]="route.iconClass"></i> <i [ngClass]="route.iconClass"></i>
} }
{{ route.name | abpLocalization }} {{ route.name | abpLazyTranslate | async }}
</a> </a>
</li> </li>
</ng-template> </ng-template>
@ -40,7 +39,7 @@
@if (route.iconClass) { @if (route.iconClass) {
<i [ngClass]="route.iconClass"></i> <i [ngClass]="route.iconClass"></i>
} }
{{ route.name | abpLocalization }} {{ route.name | abpLazyTranslate | async }}
</a> </a>
<div <div
#routeContainer #routeContainer
@ -48,9 +47,7 @@
(click)="$event.preventDefault(); $event.stopPropagation()" (click)="$event.preventDefault(); $event.stopPropagation()"
[class.d-block]="smallScreen && rootDropdownExpand[route.name]" [class.d-block]="smallScreen && rootDropdownExpand[route.name]"
> >
<ng-container <ng-container *ngTemplateOutlet="forTemplate; context: { $implicit: route }" />
*ngTemplateOutlet="forTemplate; context: { $implicit: route }"
></ng-container>
</div> </div>
</li> </li>
} }
@ -61,7 +58,7 @@
<ng-template <ng-template
[ngTemplateOutlet]="child.children?.length ? dropdownChild : defaultChild" [ngTemplateOutlet]="child.children?.length ? dropdownChild : defaultChild"
[ngTemplateOutletContext]="{ $implicit: child }" [ngTemplateOutletContext]="{ $implicit: child }"
></ng-template> />
} }
</ng-template> </ng-template>
@ -105,7 +102,7 @@
class="dropdown-menu dropdown-menu-start border-0 shadow-sm" class="dropdown-menu dropdown-menu-start border-0 shadow-sm"
[class.d-block]="smallScreen && dropdownSubmenu.isOpen()" [class.d-block]="smallScreen && dropdownSubmenu.isOpen()"
> >
<ng-container *ngTemplateOutlet="forTemplate; context: { $implicit: child }"></ng-container> <ng-container *ngTemplateOutlet="forTemplate; context: { $implicit: child }" />
</div> </div>
</div> </div>
</ng-template> </ng-template>

9
npm/ng-packs/packages/theme-basic/src/lib/components/routes/routes.component.ts

@ -2,6 +2,7 @@ import { ABP, RoutesService, TreeNode } from '@abp/ng.core';
import { import {
Component, Component,
ElementRef, ElementRef,
inject,
Input, Input,
QueryList, QueryList,
Renderer2, Renderer2,
@ -15,6 +16,9 @@ import {
templateUrl: 'routes.component.html', templateUrl: 'routes.component.html',
}) })
export class RoutesComponent { export class RoutesComponent {
public readonly routesService = inject(RoutesService);
protected renderer = inject(Renderer2);
@Input() smallScreen?: boolean; @Input() smallScreen?: boolean;
@ViewChildren('childrenContainer') childrenContainers!: QueryList<ElementRef<HTMLDivElement>>; @ViewChildren('childrenContainer') childrenContainers!: QueryList<ElementRef<HTMLDivElement>>;
@ -23,11 +27,6 @@ export class RoutesComponent {
trackByFn: TrackByFunction<TreeNode<ABP.Route>> = (_, item) => item.name; trackByFn: TrackByFunction<TreeNode<ABP.Route>> = (_, item) => item.name;
constructor(
public readonly routesService: RoutesService,
protected renderer: Renderer2,
) {}
isDropdown(node: TreeNode<ABP.Route>) { isDropdown(node: TreeNode<ABP.Route>) {
return !node?.isLeaf || this.routesService.hasChildren(node.name); return !node?.isLeaf || this.routesService.hasChildren(node.name);
} }

1
npm/ng-packs/packages/theme-basic/src/lib/pipes/index.ts

@ -0,0 +1 @@
export * from './lazy-translate.pipe';

20
npm/ng-packs/packages/theme-basic/src/lib/pipes/lazy-translate.pipe.ts

@ -0,0 +1,20 @@
import { LocalizationService, ConfigStateService } from '@abp/ng.core';
import { inject, Pipe, PipeTransform } from '@angular/core';
import { Observable, filter, take, switchMap, shareReplay } from 'rxjs';
@Pipe({
name: 'abpLazyTranslate',
})
export class LazyTranslatePipe implements PipeTransform {
private localizationService = inject(LocalizationService);
private configStateService = inject(ConfigStateService);
transform(key: string): Observable<string> {
return this.configStateService.getAll$().pipe(
filter(config => !!config.localization),
take(1),
switchMap(() => this.localizationService.get(key)),
shareReplay({ bufferSize: 1, refCount: true }),
);
}
}

2
npm/ng-packs/packages/theme-basic/src/lib/theme-basic.module.ts

@ -16,6 +16,7 @@ import { PageAlertContainerComponent } from './components/page-alert-container/p
import { RoutesComponent } from './components/routes/routes.component'; import { RoutesComponent } from './components/routes/routes.component';
import { ValidationErrorComponent } from './components/validation-error/validation-error.component'; import { ValidationErrorComponent } from './components/validation-error/validation-error.component';
import { provideThemeBasicConfig } from './providers'; import { provideThemeBasicConfig } from './providers';
import { LazyTranslatePipe } from './pipes';
export const LAYOUTS = [ApplicationLayoutComponent, AccountLayoutComponent, EmptyLayoutComponent]; export const LAYOUTS = [ApplicationLayoutComponent, AccountLayoutComponent, EmptyLayoutComponent];
@ -48,6 +49,7 @@ export const LAYOUTS = [ApplicationLayoutComponent, AccountLayoutComponent, Empt
NgbCollapseModule, NgbCollapseModule,
NgbDropdownModule, NgbDropdownModule,
NgxValidateCoreModule, NgxValidateCoreModule,
LazyTranslatePipe,
], ],
}) })
export class BaseThemeBasicModule {} export class BaseThemeBasicModule {}

1
npm/ng-packs/packages/theme-basic/src/public-api.ts

@ -6,6 +6,7 @@ export * from './lib/components';
export * from './lib/enums'; export * from './lib/enums';
export * from './lib/handlers'; export * from './lib/handlers';
export * from './lib/models'; export * from './lib/models';
export * from './lib/pipes';
export * from './lib/providers'; export * from './lib/providers';
export * from './lib/theme-basic.module'; export * from './lib/theme-basic.module';
export * from './lib/tokens'; export * from './lib/tokens';

Loading…
Cancel
Save