道喜技术日记 .^. 天天红玉世界

Rails Ruby MacOSX 。。。创新来自于刻苦的实践和勤奋的思考... www.hhtong.com


Rails2.2世界:国际化功能问与答(五)

Gudao Luo2008-12-28 at 15:02发表的

国际化功能问与答(五)
* 本地化问题(五):如何对模型进行本地化?
模型文件代码
# db/migrate/20081115224456_create_posts.rb
class CreatePosts < ActiveRecord::Migration
def self.up
create_table :posts do |t|
t.string :title
t.text :body
t.boolean :published t.timestamps
end
end
针对模型的本地化文件
# config/locales/zh-CN.yml
# I18n.locale="zh-CN"
# I18n.translate 'activerecord.models.post'
# I18n.translate 'activerecord.attributes'
# I18n.translate 'activerecord.attributes.post'
# I18n.translate 'activerecord.attributes.post.title'
zh-CN:
activerecord:
models:
post: 帖子
attributes:
post:
title: 标题
body: 内容
published: 发布时间
Hierarchy: previous, next

Comments

There are 0 comments on this post. Post yours →

Post a comment

Required fields in bold.