Rails:将翻译存储在数据库中 [英] Rails: store translations in database
问题描述
我在寻找一个plugin / gem解决方案来扩展native rails i18n,将我的翻译存储到我的数据库中。也许我使用了错误的搜索术语,但我发现的是信息,改变后端IS实际上是可能的,这博客条目,其中描述了如何写我自己的后端。
很难想象,所有那些rails应用程序有翻译存储在yml文件或每个开发人员写自己的后端!
你知道这个工作的解决方案吗?在yml中存储多行文本真的让我失望! ;)
感谢和问候,
Joe
i18n内置了对使用数据库作为翻译后端的支持。
使用此代码在迁移:
create_table:translations do | t |
t.string:locale
t.string:key
t.text:value
t.text:interpolations
t.boolean:is_proc,:default => ; false
end
然后在config / initializers / i18n.rb中添加一个初始化器,
I18n.backend = I18n :: Backend :: ActiveRecord.new
pre>
最后...将翻译放在表格中。例如:
区域金钥值
en Cool Cool
es Cool Frio
en nav 。Home home
es nav.Home casa
...
i18n 0.5.0我相信他们把这个代码移动到自己的gem ...我忘记了那个gem是什么。
I was searching for a plugin/gem solution to extend the native rails i18n for storing my translations into my database. Maybe I used the wrong search terms, but all I found was the information, that changing the backend IS actually possible and this blog entry which descripes how to write my own backend.
It's hard to imagine, that all those rails apps out there having their translations stored in yml-files or every developer wrote own backends!
Do you know working solutions for this? Storing multiline texts in yml really gets me down! ;)
Thanks and greets,
Joe
解决方案i18n has built-in support for using the database as a translation backend.
Create a table using this code in a migration:
create_table :translations do |t| t.string :locale t.string :key t.text :value t.text :interpolations t.boolean :is_proc, :default => false end
Then add an initializer in config/initializers/i18n.rb with contents:
I18n.backend = I18n::Backend::ActiveRecord.new
And last... put translations in the table. Something like:
locale key value en Cool Cool es Cool Frio en nav.Home home es nav.Home casa ...
As of i18n 0.5.0 I believe they moved this code out into it's own gem... I forget what that gem is called.
这篇关于Rails:将翻译存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!