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

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


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

Gudao Luo2008-11-28 at 23:50发表的

国际化功能问与答(二)
  • 国际化功能问与答(二):用户定义本地化文件
1. 如何确定自己软件的本地化默认语言?
vi config/environment.rb
config.i18n.default_locale = :"zh-CN"
2. 如何确定自己软件的本地化默认文件路径?
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.yml
zh-CN:
# I18n.translate :hello
hello: "世界,你好!"
用户定义本地化文件的操作方法命令
localhost:demo gudao$ ./script/console
Loading 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
Hierarchy: previous, next

Comments

There are 0 comments on this post. Post yours →

Post a comment

Required fields in bold.