【问题标题】:Which is the proper or best way to use i18n with many html tags on rails?在 Rails 上使用带有许多 html 标签的 i18n 的正确或最佳方式是什么?
【发布时间】:2020-10-23 15:02:50
【问题描述】:

我有一个类似的代码需要添加到 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>

【问题讨论】:

  • 我建议有不同语言的单独营销页面。并将 i18n 用于 rails 的东西,而不是 HTML。
  • 这个有问题的页面只有那个 HTML 的 sn-p,页面的其余部分在 ruby​​ 上,但我不希望有一个利用点并将所有页面重写为另一种语言会也很麻烦

标签: html ruby-on-rails internationalization rails-i18n


【解决方案1】:

您可能希望为整个事情本地化 sn-ps (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 %>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-01
    • 2010-09-11
    • 1970-01-01
    • 2021-05-20
    • 2012-02-04
    • 1970-01-01
    相关资源
    最近更新 更多