【发布时间】:2021-10-20 23:16:47
【问题描述】:
我正在使用 ngxtranslate 翻译应用程序。它就像魅力一样。
问题是我有 HttpInterceptor,它一开始就试图从本地存储中获取数据,并在询问您是否要加载最后的更改或关闭时显示一个对话框。
问题是对话框中的文本没有翻译,我不知道该怎么做,因为它在任何地方都有效。
HTTP拦截器文件
import { TranslateService } from '@ngx-translate/core';
@Injectable()
export class CacheInterceptor implements HttpInterceptor {
constructor(private cacheService: HttpCacheService, private dialog: MatDialog, private translate: TranslateService) {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return from(this.handle(req, next));
}
.......
const cachedResponse: HttpResponse<any> =
this.cacheService.get(reqId);
if (cachedResponse) {
console.log('cache hit');
const dialogResult = await this.openDialog();
if (dialogResult) {
console.log('Loading item from cache');
// return modifyied response
.........
async openDialog() {
const dialogData = new ConfirmationDialogModel(
await this.translate.instant('some.text'),
await this.translate.instant('some.anotherText')
);
....
输出只是some.text 和some.anotherText
请问我该怎么做才能让它工作?
【问题讨论】:
标签: javascript angular typescript translate ngx-translate