简体   繁体   English

使用 i18n 为文本的特定部分添加样式

[英]Add styling to specific part of text using i18n

I have a text that is translated to 12 languages.我有一个被翻译成 12 种语言的文本。 But I would like a specific part of the text to be underlined somehow - preferably inside the json-file where all my translations are.但我希望文本的特定部分以某种方式加下划线 - 最好在我所有翻译所在的 json 文件中。

To take an example the text in English goes like this:举个例子,英文文本是这样的:

"You've entered the wrong password 3 times. Click here to login again" “您输入了 3 次错误密码,点击此处重新登录”

I wish to only underline the 'Click here'-part, but have tried (from what I can see was the answer in another SO-question)我只想强调“单击此处”部分,但已经尝试过(据我所知,这是另一个 SO-question 中的答案)

"wrong": {
    "password": "You've entered the wrong password 3 times. <u>Click here to login again</u>"

but that doesn't work.但这不起作用。 It just shows the text with the actual它只显示带有实际的文本

< u >Click here < /u > <u>点击这里</u>

showing..显示..

The HTML goes as following: HTML 如下:

// left out code
<ng-content></ng-content>
<span ng-if="wrongpassword" class="wrongpassword" (click)="wrongpasswordClicked()"> {{ wrongpassword$ | async }} </span>

I suspect it shouldn't have anything to do with css, but I've tagged it anyways, since I might be missing something?我怀疑它不应该与 css 有任何关系,但无论如何我已经标记了它,因为我可能遗漏了什么?

update: what I've tried based on ErBu's answer:更新:我根据 ErBu 的回答尝试过什么:

<div>
  <ng-content {{ wrongpassword$ | async as trythis }} ></ng-content>
  <span *ngIf="wrongpassword" class="wrongpassword" (click)="wrongpasswordClicked()" 
[innerHTML]="trythis">
  </span>
</div>

but that doesn't show the text at all... maybe some async operation is missing?但这根本不显示文本......也许缺少一些异步操作?

All text will be treated as regular text (for security reasons) unless explicitly specified otherwise.除非另有明确说明,否则所有文本都将被视为常规文本(出于安全原因)。 To allow injection of html you can use要允许注入 html,您可以使用

<div [innerHTML]="your text"></div> 

For more details check out angular documentation有关更多详细信息,请查看 angular文档

In your particular case it should be:在您的特定情况下,它应该是:

  <div>
      <ng-content *ngIf="{{ wrongpassword$ | async as trythis }}" >
         <span class="wrongpassword (click)="wrongpasswordClicked()" 
    [innerHTML]="trythis">
      </span>
    </ng-content>
    </div>

Ps I'm adding this as an answer instead of comment for formatting:) Ps 我将此添加为答案,而不是格式化评论:)

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

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