簡體   English   中英

如何在 Angular 8 i18n 中使用 API 響應消息?

[英]How to use API response messages in Angular 8 i18n?

我需要使用 API 響應的翻譯(尤其是錯誤消息)

前任:

1) User name invalid for test@test.com
2) Password is incorrect for test@test.com
3) Login Success for test@test.com

為此,我使用了 i18n select。 我的示例代碼如下:

<span i18n="@@common_error">{respError, select, User name invalid for {User name invalid for} Password is incorrect for { Password is incorrect for}}</span>

respError - 是一個保存后端響應的變量

在這里,我正在解析字符串,然后使用 i18n select 進行比較,這工作正常。 但我需要在消息中添加動態 email。 我試着像這樣添加

{User name invalid for {Email}} ,但沒有運氣。

有沒有其他方法可以在 {} 中使用變量 - 大括號。

文檔中有一個示例可能會有所幫助

<span i18n>Updated {minutes, plural, =0 {just now} =1 {one minute ago} other {{{minutes}} minutes ago}}</span>

從上面的示例中,您可以嘗試使用雙大括號而不是單括號:

{User name invalid for {{Email}}}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM