# db/migrate/20081115224456_create_posts.rbclass 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: 发布时间
class String def t(locale="zh-CN") I18n.t self.to_sym, :locale => locale endend"hello".t"hello".t "en"
vi config/environment.rbconfig.i18n.default_locale = :"zh-CN"
vi config/environment.rb config.i18n.load_path += Dir[File.join("#{RAILS_ROOT}/config/", 'locales', 'admin', '*.{rb,yml}')]
rails 02_i18n_demo && cd 02_i18n_demo vi config/environment.rb # config.i18n.load_path << Dir[File.join(RAILS_ROOT, 'my', 'locales', '*.{rb,yml}')] # config.i18n.default_locale = :de config.i18n.default_locale = :"zh-CN" config.i18n.load_path += Dir[File.join("#{RAILS_ROOT}/config/", 'locales', 'admin', '*.{rb,yml}')] mkdir config/locales/admin vi config/locales/admin/zh-CN.ymlzh-CN: # I18n.translate :hello hello: "世界,你好!"
localhost:demo gudao$ ./script/consoleLoading development environment (Rails 2.2.2)>> I18n.load_path=> ["/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/locale/en.yml", "/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/locale/en.yml", "/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/locale/en.yml", "/Users/gudao/Documents/railsspace/open-projects/i18n/demo/config/locales/admin/en.yml", "/Users/gudao/Documents/railsspace/open-projects/i18n/demo/config/locales/admin/zh-CN.yml"]>> I18n.t :hello=> "世界,你好!" >> exit
<% if @issue.new_record? %><p><%#= f.select :tracker_id, @project.trackers.collect {|t| [t.name, t.id]}, :required => true %><%= f.select :tracker_id, Tracker.all.collect {|t| [t.name, t.id]}, :required => true %></p>
【实 × 新 × 奇】http://www.lycom.de/ 最新报道Ruby语言、Rails框架、Ubuntu、MacOSX和软件技术信息 Aardvark RSS
道喜技术日记
订阅 full-text RSS 或者 comments RSS.
Interesting links can be found at del.icio.us or by subscribing to my del.icio.us feed
Powered by SimpleLog