dbi18 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +102 -0
- data/Rakefile +10 -0
- data/dbi18.gemspec +27 -0
- data/lib/dbi18/active_record_support.rb +116 -0
- data/lib/dbi18/configure.rb +18 -0
- data/lib/dbi18/railtie.rb +13 -0
- data/lib/dbi18/version.rb +4 -0
- data/lib/dbi18.rb +9 -0
- data/lib/generators/active_record/dbi18_generator.rb +34 -0
- data/lib/generators/active_record/templates/migration.rb +17 -0
- data/lib/generators/dbi18/dbi18_generator.rb +24 -0
- data/lib/generators/dbi18/templates/initializer.rb +7 -0
- data/script.rb +7 -0
- data/spec/dbi18/dbi18_spec.rb +96 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/adapters/active_record.rb +31 -0
- data/spec/support/data.rb +17 -0
- data/spec/support/schema.rb +27 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 120b4ef1d46122c928ae22085b57da44961568fd
|
4
|
+
data.tar.gz: 9cda9bc0e1aeac2de31bff828b3acd091689e05e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 81f97c2c00921700385bd9fc2993f3321fa4d30e1914da5c85fd55c8bebb6c2ced8d07ac3ed7d7e5f5ab9c73c371f1011b899ae33d72ff5eeb92f1f28847b849
|
7
|
+
data.tar.gz: 4613086d3e3fc03e9e68b6ab7e39343c949286d738aced31d0cf2c7cb046b28fd78e6ff6f90e009bb18a8b75e90c1e3336258803c260b7b52a6863edfc4af196
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 pockycat
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# Dbi18
|
2
|
+
|
3
|
+
数据库中的dbi18
|
4
|
+
支持rails3 但不支持rails4
|
5
|
+
目前mysql与sqlite3数据库测试可用
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'dbi18'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install dbi18
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
rails g dbi18 table_name [option] #生成表名与model名字
|
24
|
+
|
25
|
+
rails g model language
|
26
|
+
|
27
|
+
Model/language.rb
|
28
|
+
|
29
|
+
db_i18n(:name,:des)
|
30
|
+
#设置需要多语种属性
|
31
|
+
validate :name_en, :presence => true
|
32
|
+
#支持验证回调函数
|
33
|
+
|
34
|
+
config/initialzer/dbi18.rb
|
35
|
+
|
36
|
+
config/initialzer/dbi18.rb
|
37
|
+
|
38
|
+
Dbi18.configure do |config|
|
39
|
+
|
40
|
+
# For the time being, maybe in the long term, it only support ActiveRecord...
|
41
|
+
|
42
|
+
# models and database tables
|
43
|
+
|
44
|
+
# config.language_type = [:en,:zh] #语种设置属性
|
45
|
+
|
46
|
+
config.model = model_name # model的名字 生成表名的情况下会自动生成model的名字 这个选项推荐不要修改
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
console
|
51
|
+
|
52
|
+
n = Name.new
|
53
|
+
|
54
|
+
n.name_en = "english"
|
55
|
+
|
56
|
+
n.name_zh = "china"
|
57
|
+
|
58
|
+
n.des_zh = "des_zh"
|
59
|
+
|
60
|
+
n.des_en = "des_en"
|
61
|
+
|
62
|
+
n.save
|
63
|
+
|
64
|
+
|
65
|
+
#i18n.locale = :en
|
66
|
+
|
67
|
+
n.name
|
68
|
+
|
69
|
+
#=> "english"
|
70
|
+
|
71
|
+
n.des
|
72
|
+
|
73
|
+
#=> "des_zh"
|
74
|
+
|
75
|
+
#如果model里添加了db_i18n的方法会根据I18n.locale的值来判断当前的值,
|
76
|
+
如果没加则会取出原有的name属性.否则就会提示未定义的方法
|
77
|
+
|
78
|
+
#如果想取出自定义的值可以用以下的方式
|
79
|
+
|
80
|
+
n.name_en
|
81
|
+
|
82
|
+
#=> "english"
|
83
|
+
|
84
|
+
n.name_zh
|
85
|
+
|
86
|
+
#=> "china"
|
87
|
+
|
88
|
+
n.des_en
|
89
|
+
|
90
|
+
#=> "des_en"
|
91
|
+
|
92
|
+
n.des_zh
|
93
|
+
|
94
|
+
#=> "des_zh"
|
95
|
+
|
96
|
+
## Contributing
|
97
|
+
|
98
|
+
1. Fork it
|
99
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
100
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
101
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
102
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/dbi18.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dbi18/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dbi18"
|
8
|
+
spec.version = Dbi18::VERSION
|
9
|
+
spec.authors = ["pockycat"]
|
10
|
+
spec.email = ["gaogao1130@gmail.com"]
|
11
|
+
spec.description = "i18n in Database"
|
12
|
+
spec.summary = "dbi18 gem"
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "activerecord", ">= 3.0.0"
|
24
|
+
spec.add_development_dependency "sqlite3"
|
25
|
+
spec.add_development_dependency 'rspec', ">= 2.0"
|
26
|
+
spec.add_development_dependency "rspec-rails", ">= 2.0"
|
27
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Dbi18
|
3
|
+
module ActiveRecordSupport
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
|
11
|
+
def db_i18n(*attributes)
|
12
|
+
include Del
|
13
|
+
language = Dbi18.locale
|
14
|
+
self.class_eval do
|
15
|
+
alias :old_save :save
|
16
|
+
attr_accessor :get_mark
|
17
|
+
end
|
18
|
+
self.send :define_method, "save" do
|
19
|
+
if self.old_save
|
20
|
+
language.each do |l_type|
|
21
|
+
locale = l_type.to_s
|
22
|
+
if ((Dbi18.model).where(:class_id => self.id, :class_name => self.class.name, :locale => locale).first).blank?
|
23
|
+
model = (Dbi18.model).new
|
24
|
+
model.hash_content = self.init_hash_content
|
25
|
+
else
|
26
|
+
model = (Dbi18.model).where(:class_id => self.id, :class_name => self.class.name, :locale => locale).first
|
27
|
+
end
|
28
|
+
hash_content = eval model.hash_content
|
29
|
+
attributes.each do |attrs|
|
30
|
+
attrs_locale = attrs.to_s + "_" + l_type.to_s
|
31
|
+
attrs_locale_sym = attrs_locale.to_sym
|
32
|
+
hash_content["#{attrs}"]= self.send attrs_locale_sym
|
33
|
+
end
|
34
|
+
model.class_id = self.id
|
35
|
+
model.class_name = self.class.name
|
36
|
+
model.locale = locale
|
37
|
+
model.hash_content = hash_content.to_s
|
38
|
+
model.save
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
init_attr_method = ("init_hash_content").to_sym
|
44
|
+
self.send :define_method, init_attr_method do #initial obeject.dbi18_type.hash_content
|
45
|
+
@count = 0
|
46
|
+
attributes.each do |attrs|
|
47
|
+
attrs = attrs.to_s
|
48
|
+
@count += 1
|
49
|
+
if @count == 1
|
50
|
+
@str = "{"
|
51
|
+
end
|
52
|
+
if @count < attributes.length
|
53
|
+
@str += "\"#{attrs}\"=>\"\","
|
54
|
+
else
|
55
|
+
@str += "\"#{attrs}\"=>\"\"}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
return @str
|
59
|
+
end
|
60
|
+
|
61
|
+
init_get_mark = "init_get_mark".to_sym
|
62
|
+
self.send :define_method,init_get_mark do
|
63
|
+
if (!(self.id).blank?)&&((self.get_mark).blank?)
|
64
|
+
self.get_mark = true
|
65
|
+
models = (Dbi18.model).where(:class_id => self.id, :class_name => self.class.name)
|
66
|
+
models.each do |model|
|
67
|
+
attributes.each do |attrs|
|
68
|
+
attrs_locale_set = attrs.to_s + "_" + model.locale+"="
|
69
|
+
attrs_locale_set = attrs_locale_set.to_sym
|
70
|
+
hash_content = eval model.hash_content
|
71
|
+
self.send attrs_locale_set,hash_content["#{attrs}"]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
return true
|
75
|
+
else
|
76
|
+
return false
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
attributes.each do |attrs|
|
81
|
+
language.each do |l_type|
|
82
|
+
attrs_locale = attrs.to_s + "_" + l_type.to_s
|
83
|
+
attrs_locale_set = attrs_locale + "="
|
84
|
+
locale = l_type.to_s
|
85
|
+
self.class_eval do
|
86
|
+
attr_accessor attrs_locale.to_sym
|
87
|
+
end
|
88
|
+
get_method = attrs.to_s+"_"+l_type.to_s
|
89
|
+
get_method = get_method.to_sym
|
90
|
+
self.send :define_method, get_method do #get_value
|
91
|
+
if !self.init_get_mark
|
92
|
+
self.send attrs_locale_set,"" if (eval "@#{get_method}").blank?
|
93
|
+
end
|
94
|
+
return (eval "@#{get_method}.to_s")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
self.send :define_method, attrs do #get_value_with_i18n.locale
|
98
|
+
locale = I18n.locale.to_s
|
99
|
+
self.send attrs.to_s+"_"+locale
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
module Del
|
107
|
+
def delete
|
108
|
+
if !(@s_result = (Dbi18.model).where(:class_id => self.id, :class_name => self.class.name)).blank?
|
109
|
+
@s_result.each do |result|
|
110
|
+
result.delete
|
111
|
+
end
|
112
|
+
end
|
113
|
+
super
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'rails'
|
3
|
+
require 'dbi18'
|
4
|
+
|
5
|
+
module Dbi18
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
initializer 'db_i18.initialize' do
|
8
|
+
ActiveSupport.on_load(:active_record) do
|
9
|
+
ActiveRecord::Base.send :include, Dbi18::ActiveRecordSupport
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/dbi18.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
|
5
|
+
module ActiveRecord
|
6
|
+
module Generators
|
7
|
+
class Dbi18Generator < ActiveRecord::Generators::Base
|
8
|
+
source_root File.expand_path("../templates", __FILE__)
|
9
|
+
argument :dbi18_class, type: :string, banner: "dbi18", desc: "dbi18", default: "dbi18"
|
10
|
+
|
11
|
+
# def show
|
12
|
+
# p "#{table_name}"
|
13
|
+
# p "#{class_name}"
|
14
|
+
# p "#{name}"
|
15
|
+
# end
|
16
|
+
|
17
|
+
def generate_auth_item_model
|
18
|
+
invoke "active_record:model", ["#{name}", "class_id", "class_name", "locale", "hash_content", "--no-migration"], :migration => false
|
19
|
+
# Rails::Generators.invoke("active_record:model", ["db_i18", "class_id", "class_name", "property", "hash_content", "--no-migration"], behavior: behavior)
|
20
|
+
end
|
21
|
+
|
22
|
+
def copy_dbi18_migration
|
23
|
+
migration_template "migration.rb", "db/migrate/create_" + "#{table_name}".singularize
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def model_path
|
29
|
+
File.join("app", "models", "#{table_name}".singularize + ".rb")
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
class Create<%= class_name %>< ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table(:<%= table_name %>) do |t|
|
5
|
+
t.integer :class_id
|
6
|
+
t.string :class_name
|
7
|
+
t.string :locale
|
8
|
+
t.text :hash_content
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index(:<%= table_name %>, :class_id)
|
13
|
+
add_index(:<%= table_name %>, :class_name)
|
14
|
+
add_index(:<%= table_name %>, :locale)
|
15
|
+
add_index(:<%= table_name %>, :hash_content)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
require 'rails/generators/migration'
|
5
|
+
|
6
|
+
module Dbi18
|
7
|
+
module Generators
|
8
|
+
class Dbi18Generator < Rails::Generators::NamedBase
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
10
|
+
# argument :dbi18_class, type: :string, banner: "dbi18", desc: "dbi18", default: "dbi18"
|
11
|
+
namespace :dbi18
|
12
|
+
desc "rails g dbi18 [parameters]"
|
13
|
+
|
14
|
+
|
15
|
+
hook_for :orm
|
16
|
+
|
17
|
+
|
18
|
+
def copy_initializer_file
|
19
|
+
template "initializer.rb", "config/initializers/dbi18.rb"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/script.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe I18n do
|
5
|
+
describe "i18n_test" do
|
6
|
+
context "when model can't use db_i18n" do
|
7
|
+
before(:each) do
|
8
|
+
@sub2 = Sub2.last
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should @sub2.name is @sub2.name " do
|
12
|
+
(@sub2.name == "normal").should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should @sub2.name_en isn't exist " do
|
16
|
+
(!@sub2.methods.include? "name_en").should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should @sub2.name_zh isn't exist " do
|
20
|
+
(!@sub2.methods.include? "name_zh").should be_true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when model use db_i18n" do
|
25
|
+
before(:each) do
|
26
|
+
@sub1 = Sub1.last
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should @sub1.name is equal @s.name_en when I18n.locale is :en " do
|
30
|
+
I18n.locale = :en
|
31
|
+
(@sub1.name == "english").should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should @sub1.name is equal @s.name_zh when I18n.locale is :zh " do
|
35
|
+
I18n.locale = :zh
|
36
|
+
(@sub1.name == "你好").should be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should @sub1.name is equal @s.name_jp when I18n.locale is :jp " do
|
40
|
+
I18n.locale = :jp
|
41
|
+
(@sub1.name == "").should be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should @sub1.des is equal @s.des_en when I18n.locale is :en " do
|
45
|
+
I18n.locale = :en
|
46
|
+
(@sub1.des == "des").should be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should @sub1.des is equal @s.des_zh when I18n.locale is :zh " do
|
50
|
+
I18n.locale = :zh
|
51
|
+
(@sub1.des == "描述").should be_true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should @sub1.des is equal @s.des_jp when I18n.locale is :jp " do
|
55
|
+
I18n.locale = :jp
|
56
|
+
(@sub1.des == "japan").should be_true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "when @sub1 is delete" do
|
60
|
+
id = @sub1.id
|
61
|
+
class_name = @sub1.class.name
|
62
|
+
@sub1.delete
|
63
|
+
Cimu.where(:class_id => id, :class_name => class_name).blank? .should be_true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when model use db_i18n with save" do
|
68
|
+
before(:each) do
|
69
|
+
@sub3 = Sub3.new
|
70
|
+
@sub3.name_en = "english"
|
71
|
+
@sub3.name_zh = "你好"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should @sub3.name is equal @sub3.name_en when I18n.locale is :en " do
|
75
|
+
I18n.locale = :en
|
76
|
+
(@sub3.name == "english").should be_true
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should @sub3.name is equal @sub3.name_zh when I18n.locale is :zh " do
|
80
|
+
I18n.locale = :zh
|
81
|
+
(@sub3.name == "你好").should be_true
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should falid when @sub3.name_jp is equal nil and @sub3.save with validates :name_jp, :presence => true " do
|
85
|
+
@sub3.save.should be_false
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should falid when @sub3.name_jp is equal nil and @sub3.save with validates :name_jp, :presence => true " do
|
89
|
+
@sub3.name_jp = "japan"
|
90
|
+
@sub3.save.should be_true
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'active_record'
|
3
|
+
RSpec::Matchers::OperatorMatcher.register(ActiveRecord::Relation, '=~', RSpec::Matchers::BuiltIn::MatchArray)
|
4
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
5
|
+
ActiveRecord::Base.send :include, Dbi18::ActiveRecordSupport
|
6
|
+
load File.dirname(__FILE__) + '/../schema.rb'
|
7
|
+
|
8
|
+
# ActiveRecord models
|
9
|
+
|
10
|
+
class Cimu < ActiveRecord::Base
|
11
|
+
Dbi18.model = Cimu
|
12
|
+
Dbi18.locale = [:en,:zh,:jp]
|
13
|
+
attr_accessible :class_id, :class_name, :hash_content, :locale
|
14
|
+
end
|
15
|
+
|
16
|
+
class Sub1 < ActiveRecord::Base
|
17
|
+
|
18
|
+
# attr_accessible :name
|
19
|
+
db_i18n(:name,:des)
|
20
|
+
end
|
21
|
+
|
22
|
+
class Sub2 < ActiveRecord::Base
|
23
|
+
# attr_accessible :name
|
24
|
+
# attr_accessible :name, :auth_type, :description, :bizrule, :data
|
25
|
+
end
|
26
|
+
|
27
|
+
class Sub3 < ActiveRecord::Base
|
28
|
+
db_i18n(:name)
|
29
|
+
validates :name_jp, :presence => true
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
Sub1.destroy_all
|
3
|
+
Sub2.destroy_all
|
4
|
+
|
5
|
+
#Sub1 with dbi18n method
|
6
|
+
sub1 = Sub1.new
|
7
|
+
sub1.name_en = "english"
|
8
|
+
sub1.name_zh = "你好"
|
9
|
+
sub1.des_en = "des"
|
10
|
+
sub1.des_zh = "描述"
|
11
|
+
sub1.des_jp = "japan"
|
12
|
+
sub1.save
|
13
|
+
|
14
|
+
#Sub2 without dbi18n method
|
15
|
+
sub2 = Sub2.new
|
16
|
+
sub2.name = "normal"
|
17
|
+
sub2.save
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
ActiveRecord::Schema.define do
|
3
|
+
|
4
|
+
create_table(:sub1s) do |t|
|
5
|
+
end
|
6
|
+
|
7
|
+
create_table(:sub2s) do |t|
|
8
|
+
t.string :name
|
9
|
+
end
|
10
|
+
|
11
|
+
create_table(:sub3s) do |t|
|
12
|
+
end
|
13
|
+
|
14
|
+
create_table(:cimus) do |t|
|
15
|
+
t.integer :class_id
|
16
|
+
t.string :class_name
|
17
|
+
t.string :locale
|
18
|
+
t.text :hash_content
|
19
|
+
t.timestamps
|
20
|
+
end
|
21
|
+
|
22
|
+
add_index(:cimus, :class_id)
|
23
|
+
add_index(:cimus, :class_name)
|
24
|
+
add_index(:cimus, :locale)
|
25
|
+
add_index(:cimus, :hash_content)
|
26
|
+
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dbi18
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pockycat
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activerecord
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.0'
|
97
|
+
description: i18n in Database
|
98
|
+
email:
|
99
|
+
- gaogao1130@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- dbi18.gemspec
|
110
|
+
- lib/dbi18.rb
|
111
|
+
- lib/dbi18/active_record_support.rb
|
112
|
+
- lib/dbi18/configure.rb
|
113
|
+
- lib/dbi18/railtie.rb
|
114
|
+
- lib/dbi18/version.rb
|
115
|
+
- lib/generators/active_record/dbi18_generator.rb
|
116
|
+
- lib/generators/active_record/templates/migration.rb
|
117
|
+
- lib/generators/dbi18/dbi18_generator.rb
|
118
|
+
- lib/generators/dbi18/templates/initializer.rb
|
119
|
+
- script.rb
|
120
|
+
- spec/dbi18/dbi18_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
- spec/support/adapters/active_record.rb
|
123
|
+
- spec/support/data.rb
|
124
|
+
- spec/support/schema.rb
|
125
|
+
homepage: ''
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.0.3
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: dbi18 gem
|
149
|
+
test_files:
|
150
|
+
- spec/dbi18/dbi18_spec.rb
|
151
|
+
- spec/spec_helper.rb
|
152
|
+
- spec/support/adapters/active_record.rb
|
153
|
+
- spec/support/data.rb
|
154
|
+
- spec/support/schema.rb
|
155
|
+
has_rdoc:
|