0.0
No commit activity in last 3 years
No release in over 3 years
A generate model attributes I18n locale files plugin for Rails3.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

#I18nAttributes

I18nAttributes is a generate model attributes I18n locale files plugin for Rails3.

it support active_model active_record and mongoid.

##Supported versions

  • Ruby 1.8.7, 1.9.2, 1.9.3

  • Rails 3.0.x, 3.1

##Installation

In your app's Gemfile, add:

gem "i18n_attributes", :group => [:development]

Then run:

> bundle
> rails generate i18n_attributes:install

If your want to configure, see config/initializers/i18n_attributes.rb

##Uninstallation

Run:

> rails destroy i18n_attributes:install

##Usage Example

###Basic Usage

When your generate post model, then hook invoke, create config/locales/model_zh-CN/post.yml file

> rails g model post title:string
    invoke  active_record
    create    db/migrate/20111119121327_create_posts.rb
    create    app/models/post.rb
    invoke    test_unit
    create      test/unit/post_test.rb
    create      test/fixtures/posts.yml
    invoke  i18n_attributes
    create    config/locales/model_en/post.yml
    create    config/locales/model_zh-CN/post.yml

If your models has been created, you want generate model attributes i18n locale file,very easy also, run

> rails g i18n_attributes:revise_model
    create  config/locales/model_en/post.yml
    create  config/locales/model_zh-CN/post.yml

###Translate attribute

If you want translate attribute or model name

First, edit config/initializers/i18n_attributes.rb file, like this

if Rails.env.development?
  I18nAttributes.configure do |config|
    config.locales = [:en, :"zh-CN"]
    config.translator = {
      ##if use this, you mast install youdao_fanyi, see https://github.com/vkill/youdao_fanyi
      :"zh-CN" => Proc.new{|str| YoudaoFanyi.t(str).first}
    }
  end
end

Then, install youdao_fanyi, see https://github.com/vkill/youdao_fanyi. you also use to_lang and other.

Last, run rails g i18n_attributes:revise_model, results like this

> rails g i18n_attributes:revise_model
  create  config/locales/model_en/user.yml
  INFO  translated attribute/model_name id
  INFO  translated attribute/model_name username
  INFO  translated attribute/model_name created_at
  INFO  translated attribute/model_name updated_at
  INFO  translated attribute/model_name User
  create  config/locales/model_zh-CN/user.yml

> cat config/locales/model_zh-CN/user.yml
  ---
  zh-CN:
    activerecord:
      models:
        user: 用户
      attributes:
        user:
          id: id
          username: 用户名
          created_at: 创建在
          updated_at: 及时更新,

##Notes

If your config/locales/**/*.yml have following code, because YAML::ENGINE.yamler= 'syck'

name: "\xE5\x90\x8D\xE5\xAD\x97"

solve it, please setting YAML::ENGINE.yamler= 'psych', example

# config/boot.rb
require 'yaml'
YAML::ENGINE.yamler= 'psych'

##Copyright

Copyright (c) 2011 vkill.net .