如何使用 Makara 模块为 Express 和 Kraken.js "pull out" 样式化来自 I18N 属性文件的 HTML 标签?

How to "pull out" styled HTML tags from I18N properties files with Makara module for Express and Kraken.js?

我正在使用 Makara, an I18N module for Kraken.js and Express.js

假设我有一个句子,因为每种语言的语法,我想为恰好处于随机位置的特定单词设置样式,并且我想在呈现之前使用 I18N 属性文件以不同的语言轻松处理它阶段,例如:

我的属性文件是:

//en-GB.properties
sentence=I want to eat an <span style="font-weight: bold;">apple</span>

//de-DE.properties
sentence=Ich möchte einen <span style="font-weight: bold;">Apfel</span> zu essen

CSS 内联样式只是为了简单起见,粗体样式只是一个例子。

但是,属性文件只包含简单的单词。如何在不在属性文件中强制使用 HTML 标记的情况下获得相同的结果?

" I want to highlight a specific word"

在这种情况下,我会推荐一个特定的元素 <mark>

<mark>MDN

The HTML Mark Element (<mark>) represents highlighted text, i.e., a run of text marked for reference purpose, due to its relevance in a particular context.

<p>I want to eat an
  <mark>apple</mark> for my lunch</p>

处理配置参数的一种方法是使用占位符而不是标签,并在构建代码的阶段使用工具替换它们,例如 "Grunt":我发现这个 Grunt 任务叫做 "grunt-placeholder".这是资源的link。

https://www.npmjs.com/package/grunt-placeholder

配置基于 json 对象而不是属性,您可以在其中创建自定义属性并在编译前将它们用于您的文件中的配置目的。

  • app/ui/componentA/de.json

    { "componentA": { "title": "Titel der Komponente A" } }

  • app/ui/componentA/en.json

    { "componentA": { "title": "Title of component A" } }

  • app/ui/componentA/componentA.html

    <markup id="componentA"> <div class="componentA"> <div data-i18n="componentA.title;[title]componentA.title"></div> </div> </markup>

  • app/ui/componentA/componentA.less

    .componentA { background: grey; color: red; }