Angular 9:TypeScript 中的 i18n [英] Angular 9: i18n in TypeScript
本文介绍了Angular 9:TypeScript 中的 i18n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我研究了 Angular 9 中的新 i18n 特性.https://angular.io/guide/i18n
I studied the new i18n feature in Angular 9. https://angular.io/guide/i18n
如何翻译 TypeScript 中的文本,例如SnackBar 消息?
How to translate text in TypeScript, e.g. SnackBar messages?
推荐答案
查看此博客 https://blog.ninja-squad.com/2019/12/10/angular-localize/
来自官方文档:https://angular.io/api/localize/init/$localize
@Component({
template: '{{ title }}'
})
export class HomeComponent {
title = $localize`You have 10 users`;
}
和
您必须手动将其添加到您的 messages.fr.xlf
You have to manually add it to your messages.fr.xlf
<trans-unit id="6480943972743237078">
<source>You have 10 users</source>
<target>Vous avez 10 utilisateurs</target>
</trans-unit>
不要忘记重新提供您的 Angular 应用程序.
don't forgot re serve your angular application.
ID 更新
@Component({
template: '{{ title }}'
})
export class HomeComponent {
title = $localize`:@@6480943972743237078:`;
}
这篇关于Angular 9:TypeScript 中的 i18n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文