翻译Ts文件中的文本-Angular Ngx翻译

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

我想翻译我的打字稿文件中存在的文本,因此每次我在使用应用程序时要更改语言时,文本都应该更改(例如,将语言从英语更改为frensh)。我尝试了以下代码,但没有用

this.translate.get('example').subscribe(res => { this.title = res.title }

[我也尝试过这种方法,并且效果很好,但是当我从语言转换为另一种语言时,我不想每次在打字稿文件中翻译某些内容时,都不想在不同的组件中添加相同的代码

this.translate.onLangChange.subscribe(() => {
                this.translate.get('example').subscribe(res => { this.title = res.title }
        });
angular typescript ngx-translate
1个回答
0
投票

您应该将翻译服务放在您的app.component中,并在其中进行所有翻译,因此您无需在其他任何地方进行复制

© www.soinside.com 2019 - 2024. All rights reserved.