未执行菜单项标签翻译

问题描述 投票:0回答:2

给定以下组件

@Component({
  selector: 'sidebar-menu',
  templateUrl: './sidebar-menu.component.html',
  styleUrls: ['./sidebar-menu.component.scss'],
})
export class SidebarMenuComponent implements OnInit {
  userMenuItems: MenuItem[] = [];

  constructor(private readonly service: TranslateService) {}

  ngOnInit() {
    this.userMenuItems = [
      {
        label: this.service.instant('menu.sidebar.user.global-user-management'),
        routerLink: 'admin-users',
      },
      {
        label: this.service.instant('menu.sidebar.user.centre-user-management'),
        routerLink: '/',
      },
    ];
  }
}

我正在尝试获取要翻译的菜单项的标签。但上面的方法失败了。应用此翻译的正确方法是什么?

提前致谢

angular primeng ngx-translate primeng-menu
2个回答
0
投票

此问题的答案已在本出版物中得到充分解答。总之。 instant 是同步的,翻译不可用。解决了

.get

ngOnInit() {
    this.service
      .get([
        'menu.sidebar.user.global-user-management',
        'menu.sidebar.user.centre-user-management',
      ])
      .subscribe({
        next: () => {
          this.userMenuItems = [
            {
              label: this.service.instant(
                'menu.sidebar.user.global-user-management'
              ),
              routerLink: 'admin-users',
            },
            {
              label: this.service.instant(
                'menu.sidebar.user.centre-user-management'
              ),
              routerLink: '/',
            },
          ];
        },
      });
  }

0
投票

一种选择是使用

stream

globalusermanagement: string = "";

    ngOnInit() {

        this.service.stream('global-user-management').subscribe((res: string) => {
            this.globalusermanagement = res;
        });

        this.userMenuItems = [
          {
            label: this.service.stream('menu.sidebar.user.global-user-management'),
            routerLink: 'admin-users',
          }
        ];
© www.soinside.com 2019 - 2024. All rights reserved.