将i18n与导轨上的许多html标签一起使用的正确或最佳方法是哪一种?

问题描述

我有一个需要添加到i18n的代码,我想知道哪种方法是最好/最安全的方法,现在我将其放在i18n上,并在带有变量的ruby代码调用它和html_safe,但我不知道这是否意味着任何安全隐患,我还考虑过将html标记作为这些i18n变量的参数传递

<p>Através dos princípios da<strong> economia colaborativa </strong> e do <strong>
      <span id="yellow">poder da tecnologia</span></strong> nosso modelo de negócio
alia a <strong> <span id="green"> expertise do executive search </span></strong>
 <strong><span id="red">,a </span></strong>importância das relações humanas <strong> e o<span id="blue">alcance das redes</span>

解决方法

您可能希望整个内容都具有本地化的摘要(Rails Guides: Localized views):

西班牙语版本在自己的文件中

# marketing.es.erb
<p>Através dos princípios da<strong> economia colaborativa </strong> e do <strong>
      <span id="yellow">poder da tecnologia</span></strong> nosso modelo de negócio
alia a <strong> <span id="green"> expertise do executive search </span></strong>
 <strong><span id="red">,a </span></strong>importância das relações humanas <strong> e o<span id="blue">alcance das redes</span>

然后英文

# marketing.en.erb
<p>Something<strong> in english</strong>...  <strong>
      <span id="yellow">... </span></strong>

并自动包含正确的部分

(other content)
<%= render :marketing %>