navbar.component.html
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li routerLinkActive="active" *ngFor="let menuItem of menuItems" class="{{menuItem.class}} nav-item">
<a [routerLink]="[menuItem.path]" class="nav-link">{{menuItem.title}}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="" data-toggle="modal" data-target="#myModal" (click)="showModal()"><i class="icon-search"></i></a>
</li>
</ul>
</div>
字符串
navbar.comomponent.ts
import { Component, OnInit } from '@angular/core';
import {TranslateService} from '@ngx-translate/core';
declare interface RouteInfo {
path: string;
title: string;
class: string;
}
export const ROUTES: RouteInfo[] = [
{ path: '/home', title: 'Home', class: '' },
{ path: '/buyer_registration', title: 'Buyer Registration', class: '' },
{ path: '/rate_contract', title: 'Rate Contract', class: '' },
{ path: '/login', title: 'Login', class: '' },
];
@Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html',
styleUrls: ['./navbar.component.css']
})
export class NavbarComponent implements OnInit {
menuItems: any[];
constructor(translate: TranslateService) {
translate.setDefaultLang('English');
translate.use('English');
}
ngOnInit() {
this.menuItems = ROUTES.filter(menuItem => menuItem);
}
}
型
如何翻译本地JSON数据?
我已经有一个en和fr JSON文件在我的本地
2条答案
按热度按时间dgenwo3n1#
我也遇到过这个问题。
我最后做的是使用ngx-translate。它很容易使用!
Here is working example.的
j13ufse22#
有了ngx-translate,你可以做到这一点。你会发现一步一步的介绍在这里:
ngx-translate Documentation