简体   繁体   English

<strong>使用angular-translate在翻译的字符串中</strong>添加<strong>/加粗文本</strong>

[英]Adding <strong>/bold text in translated string using angular-translate

I am currently look for a solution to put ONE bold word in a string being translated by the angular-translate filter. 我目前正在寻找一种解决方案,将一个粗体字放入由angular-translate过滤器翻译的字符串中。 Sample code below: (I'm sure the solution is simple... I just can't seem to figure this one out!) 下面的示例代码:(我确定解决方案很简单......我似乎无法想象这一个!)

my language JSON file looks like so: 我的语言JSON文件如下所示:

"AUTHENTICATE-ENTER-CODE": "blah blah blah"

In my html file I have this (which translates correctly according to key:value): 在我的html文件中,我有这个(根据键:值正确翻译):

{{'AUTHENTICATE-ENTER-CODE' | translate}}

RESULT: "blah blah blah" 结果:“等等等等”

The result I am look for is "blah blah blah" 我要找的结果是“ 等等等等”

I could split this into multiple translation keys but the particular translation consists of multiple bold words in a few sentences... and I was told to attempt to keep the translations keys to a minimum since we have a couple hundred in this project. 我可以将它分成多个翻译键,但特定翻译由几个句子中的多个粗体词组成......我被告知要尽量将翻译键保持在最低限度,因为我们在这个项目中有几百个。

I have tried putting the bold HTML tags surrounding the font I want to be bold (knowing it wouldn't work anyways) and no... it does not work! 我已经尝试将粗体HTML标签放在我想要粗体的字体周围(知道它不会起作用)并且没有......它不起作用! I also browsed through the angular-translate API and couldn't find exactly what I was looking for either. 我还浏览了angular-translate API,但也找不到我想要的内容。

Any input would be great! 任何输入都会很棒!

If you using i18n or any other JSON file for content in Angular 2+ versions.Use this 如果您使用i18n或任何其他JSON文件获取Angular 2+版本中的内容。请使用此选项

Json File Json文件

"TextWithHtmlExample": "blah <b>blah</b> blah"

Html File (Angular Template) Html文件(角度模板)

<p [innerHTML]="'TextWithHtmlExample' | translate"></p>

Output Will be- 输出将 -

blah blah blah 等等等等

translate-compile 翻译编译

Here is sample, I have tried to use html tags and as well as using directives in the translated string. 这是示例,我试图使用html标签,以及在翻译的字符串中使用指令。

http://jsfiddle.net/walvekarnikhil/0j7pd40b/ http://jsfiddle.net/walvekarnikhil/0j7pd40b/

<span translate="FOO" translate-compile></span>

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

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