如何本地化来自存储在data文件夹中的yaml文件的数据字符串
我想知道是否有一些我在这方面错过的技巧。
发布于 2013-06-26 19:42:01
我知道的一种方式是在你的数据中使用符号(指向翻译项目):
/data/product.yml
title: :product_title/config.rb
set :lang, :de
activate :i18n, :langs => [:de, :en]这些符号可以翻译为(中间人)通常的.
/locales/de.yml
---
de:
product_title: "Mein deutscher Produktname"/locales/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
我的英文产品标题
发布于 2014-04-14 07:23:12
您可以使用.send方法。
在/data/en/production.yml中
---
title: "My english product title"在/data/ja/production.yml中
---
title: "私の日本語の商品名"然后在你的模板中..。
<h1><%= I18n.t(data.send(I18n.locale.to_sym).product.title) %></h1>https://stackoverflow.com/questions/17296225
复制相似问题