Middleman-本地化数据/yaml文件



如何本地化来自存储在数据文件夹中的yaml文件的数据字符串

想知道我是否错过了一些技巧。

我知道的一种方法是在数据中使用符号(指向翻译项目):

/data/product.yml

title: :product_title

/config.rb

set :lang, :de
activate :i18n, :langs => [:de, :en]

这些符号可以翻译成(Middleman)常用的。。。

/locates/de.yml

---
de:
  product_title: "Mein deutscher Produktname"

/locates/en.yml

---
en:
  product_title: "My english product title"

并在您的模板中使用:

/source/localizable/i18n.html.erb

<h1><%= I18n.t(data.product.title) %></h1>

http://0.0.0.0:4567/i18n.html

德国生产商

http://0.0.0.0:4567/en/i18n.html

我的英文产品名称

您可以使用.send方法。

In/data/en/production.yml

---
title: "My english product title"

In/data/ja/production.yml

---
title: "私の日本語の商品名"

然后在你的模板中。。。

<h1><%= I18n.t(data.send(I18n.locale.to_sym).product.title) %></h1>

最新更新