简体   繁体   English

带有动态值的span标签的Angular i18n

[英]Angular i18n for span tag with dynamic value

I am setting up internationalization for my Angular project and I am facing the following problem: 我正在为我的Angular项目设置国际化,并且面临以下问题:

I have a form page where a user can enter a base URL and an API key to perform REST requests with a provider. 我有一个表单页面,用户可以在其中输入基本URL和API密钥以与提供程序执行REST请求。 I have a button which tests the connection to that provider with the API key and base URL entered by the user by doing an http get call. 我有一个按钮,用于通过用户通过http get调用输入的API密钥和基本URL测试与该提供程序的连接。 I am not sure how I can localize a span tag which displays a message whether the provider was successfully pinged. 我不确定如何本地化显示广告提供者是否成功ping通的消息的span标记。 Here's the code for my span tag: 这是我的span标签的代码:

<span class="fd-badge" [class.fd-badge--success]="data?.authenticated" [class.fd-badge--error]="!data?.authenticated">{{data?.authenticated
                    ? 'Connected Successfully': 'Connection Failed'}}</span>

Found the solution to my problem. 找到了解决我问题的方法。 Instead of using the i18n tags it is better to use the https://www.npmjs.com/package/@ngx-translate/core library. 与其使用i18n标签,不如使用https://www.npmjs.com/package/@ngx-translate/core库。 Much more flexible and easier to apply in various html elements. 更加灵活,更容易应用于各种html元素。

As for the span tag itself: 至于span标签本身:

<span>{{(data?.authenticated ? 'successConnection' : 'failConnection') | 
translate}}
</span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM