translatable 0.3.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWMzNWU3MzZlNmUxNzViZmM4ZmU3ODAxNGEzZTdkMDRkMzZkNjI1Nw==
5
+ data.tar.gz: !binary |-
6
+ N2I5NTk0MTA3YTBlMjIwMDRhMjcxZGVhYjExYWU5YjQwZWY1MDA0NA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OWE5NzU5YzhlYmJjZDRkYTBiOGZkNTJlOGQwNmViODY1NTliYjc2ZTBhMGJm
10
+ NGQ1YjEwZWY4MzEyNmVlNzNlZTBkNTc0ZmUyMGQzNTFmNjg0Y2M5M2Q1YTcy
11
+ YmQ3YjdlYmU1MzAyNWU5NGJjYjU4MDUzMjgzZDk3ZGEyNTI4OGM=
12
+ data.tar.gz: !binary |-
13
+ ZWY2YzQwNjcwNTlmY2IzN2I5MjllZWNiYjAyZWQxNDU3MzhlMmQyOWRjYTg1
14
+ ZWVhNGY5NjAxMmM0N2FlNGYzMzFlMmYwMzczYzEwODAyMDVjNTAzYzBmMTRm
15
+ ZGYzOGY4MjdkZDhmNjg0Yjg5YzkyNjc3NDRmODg1ZjEzZTU1NWI=
@@ -0,0 +1 @@
1
+ translatable
@@ -0,0 +1 @@
1
+ ruby-2.0.0
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
3
  - 1.9.3
4
+ - 2.0.0
5
5
  bundler_args: --without=debug development
data/Gemfile CHANGED
@@ -1,33 +1,31 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "activerecord"
3
+ gem "activerecord", ">= 4.0.0"
4
4
  gem "activesupport", :require => false
5
5
  gem "i18n"
6
6
 
7
7
  group :debug do
8
- gem "debugger", "~> 1.2.2", :platform => :ruby_19
9
- gem "ruby-debug", :platform => :ruby_18
8
+ gem "byebug", :platform => :ruby_20
9
+ #gem "debugger", "~> 1.2.2", :platform => :ruby_19
10
+ #gem "ruby-debug", :platform => :ruby_18
10
11
  end
11
12
 
12
- group :development do
13
+ group :development, :test do
13
14
  gem "jeweler", "~> 1.8.0"
14
15
  end
15
16
 
16
17
  group :debug, :test do
17
18
  gem "yard"
18
19
  gem "redcarpet"
19
-
20
- gem "simplecov", "~> 0.7.1", :require => false, :platform => :ruby_19
21
- gem "rcov", "~> 1.0.0", :require => false, :platform => :ruby_18
22
20
  end
23
21
 
24
22
  group :test do
25
23
  gem "sqlite3"
26
24
  gem "database_cleaner"
25
+ gem "protected_attributes", "~> 1.0.5"
27
26
 
28
27
  gem "rails"
29
28
 
30
- gem 'minitest'
31
29
  gem "test-unit"
32
30
  gem "shoulda"
33
31
 
@@ -1,144 +1,151 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- actionmailer (3.1.8)
5
- actionpack (= 3.1.8)
6
- mail (~> 2.3.3)
7
- actionpack (3.1.8)
8
- activemodel (= 3.1.8)
9
- activesupport (= 3.1.8)
10
- builder (~> 3.0.0)
4
+ actionmailer (4.0.2)
5
+ actionpack (= 4.0.2)
6
+ mail (~> 2.5.4)
7
+ actionpack (4.0.2)
8
+ activesupport (= 4.0.2)
9
+ builder (~> 3.1.0)
11
10
  erubis (~> 2.7.0)
12
- i18n (~> 0.6)
13
- rack (~> 1.3.6)
14
- rack-cache (~> 1.2)
15
- rack-mount (~> 0.8.2)
16
- rack-test (~> 0.6.1)
17
- sprockets (~> 2.0.4)
18
- activemodel (3.1.8)
19
- activesupport (= 3.1.8)
20
- builder (~> 3.0.0)
21
- i18n (~> 0.6)
22
- activerecord (3.1.8)
23
- activemodel (= 3.1.8)
24
- activesupport (= 3.1.8)
25
- arel (~> 2.2.3)
26
- tzinfo (~> 0.3.29)
27
- activeresource (3.1.8)
28
- activemodel (= 3.1.8)
29
- activesupport (= 3.1.8)
30
- activesupport (3.1.8)
31
- multi_json (>= 1.0, < 1.3)
11
+ rack (~> 1.5.2)
12
+ rack-test (~> 0.6.2)
13
+ activemodel (4.0.2)
14
+ activesupport (= 4.0.2)
15
+ builder (~> 3.1.0)
16
+ activerecord (4.0.2)
17
+ activemodel (= 4.0.2)
18
+ activerecord-deprecated_finders (~> 1.0.2)
19
+ activesupport (= 4.0.2)
20
+ arel (~> 4.0.0)
21
+ activerecord-deprecated_finders (1.0.3)
22
+ activesupport (4.0.2)
23
+ i18n (~> 0.6, >= 0.6.4)
24
+ minitest (~> 4.2)
25
+ multi_json (~> 1.3)
26
+ thread_safe (~> 0.1)
27
+ tzinfo (~> 0.3.37)
28
+ addressable (2.3.5)
32
29
  ansi (1.4.3)
33
- arel (2.2.3)
34
- builder (3.0.0)
30
+ arel (4.0.1)
31
+ atomic (1.1.14)
32
+ builder (3.1.4)
33
+ byebug (2.5.0)
34
+ columnize (~> 0.3.6)
35
+ debugger-linecache (~> 1.2.0)
35
36
  columnize (0.3.6)
36
- database_cleaner (0.7.2)
37
- debugger (1.2.4)
38
- columnize (>= 0.3.1)
39
- debugger-linecache (~> 1.1.1)
40
- debugger-ruby_core_source (~> 1.1.7)
41
- debugger-linecache (1.1.2)
42
- debugger-ruby_core_source (>= 1.1.1)
43
- debugger-ruby_core_source (1.1.9)
37
+ database_cleaner (1.2.0)
38
+ debugger-linecache (1.2.0)
44
39
  erubis (2.7.0)
45
- git (1.2.5)
46
- hike (1.2.1)
47
- i18n (0.6.0)
48
- jeweler (1.8.4)
40
+ faraday (0.8.8)
41
+ multipart-post (~> 1.2.0)
42
+ git (1.2.6)
43
+ github_api (0.10.1)
44
+ addressable
45
+ faraday (~> 0.8.1)
46
+ hashie (>= 1.2)
47
+ multi_json (~> 1.4)
48
+ nokogiri (~> 1.5.2)
49
+ oauth2
50
+ hashie (2.0.5)
51
+ highline (1.6.20)
52
+ hike (1.2.3)
53
+ httpauth (0.2.0)
54
+ i18n (0.6.9)
55
+ jeweler (1.8.8)
56
+ builder
49
57
  bundler (~> 1.0)
50
58
  git (>= 1.2.5)
59
+ github_api (= 0.10.1)
60
+ highline (>= 1.6.15)
61
+ nokogiri (= 1.5.10)
51
62
  rake
52
63
  rdoc
53
- json (1.7.5)
54
- linecache (0.46)
55
- rbx-require-relative (> 0.0.4)
56
- mail (2.3.3)
57
- i18n (>= 0.4.0)
64
+ json (1.8.1)
65
+ jwt (0.1.8)
66
+ multi_json (>= 1.5)
67
+ mail (2.5.4)
58
68
  mime-types (~> 1.16)
59
69
  treetop (~> 1.4.8)
60
- mime-types (1.19)
61
- minitest (4.6.2)
62
- multi_json (1.2.0)
70
+ mime-types (1.25.1)
71
+ minitest (4.7.5)
72
+ multi_json (1.8.2)
73
+ multi_xml (0.5.5)
74
+ multipart-post (1.2.0)
75
+ nokogiri (1.5.10)
76
+ oauth2 (0.9.2)
77
+ faraday (~> 0.8)
78
+ httpauth (~> 0.2)
79
+ jwt (~> 0.1.4)
80
+ multi_json (~> 1.0)
81
+ multi_xml (~> 0.5)
82
+ rack (~> 1.2)
63
83
  polyglot (0.3.3)
64
- rack (1.3.6)
65
- rack-cache (1.2)
66
- rack (>= 0.4)
67
- rack-mount (0.8.3)
68
- rack (>= 1.0.0)
69
- rack-ssl (1.3.2)
70
- rack
84
+ protected_attributes (1.0.5)
85
+ activemodel (>= 4.0.1, < 5.0)
86
+ rack (1.5.2)
71
87
  rack-test (0.6.2)
72
88
  rack (>= 1.0)
73
- rails (3.1.8)
74
- actionmailer (= 3.1.8)
75
- actionpack (= 3.1.8)
76
- activerecord (= 3.1.8)
77
- activeresource (= 3.1.8)
78
- activesupport (= 3.1.8)
79
- bundler (~> 1.0)
80
- railties (= 3.1.8)
81
- railties (3.1.8)
82
- actionpack (= 3.1.8)
83
- activesupport (= 3.1.8)
84
- rack-ssl (~> 1.3.2)
89
+ rails (4.0.2)
90
+ actionmailer (= 4.0.2)
91
+ actionpack (= 4.0.2)
92
+ activerecord (= 4.0.2)
93
+ activesupport (= 4.0.2)
94
+ bundler (>= 1.3.0, < 2.0)
95
+ railties (= 4.0.2)
96
+ sprockets-rails (~> 2.0.0)
97
+ railties (4.0.2)
98
+ actionpack (= 4.0.2)
99
+ activesupport (= 4.0.2)
85
100
  rake (>= 0.8.7)
86
- rdoc (~> 3.4)
87
- thor (~> 0.14.6)
88
- rake (0.9.2.2)
89
- rbx-require-relative (0.0.9)
90
- rcov (1.0.0)
91
- rdoc (3.12)
101
+ thor (>= 0.18.1, < 2.0)
102
+ rake (10.1.0)
103
+ rdoc (4.0.1)
92
104
  json (~> 1.4)
93
- redcarpet (2.2.2)
94
- ruby-debug (0.10.4)
95
- columnize (>= 0.1)
96
- ruby-debug-base (~> 0.10.4.0)
97
- ruby-debug-base (0.10.4)
98
- linecache (>= 0.3)
99
- shoulda (3.3.2)
100
- shoulda-context (~> 1.0.1)
101
- shoulda-matchers (~> 1.4.1)
102
- shoulda-context (1.0.1)
103
- shoulda-matchers (1.4.1)
105
+ redcarpet (3.0.0)
106
+ shoulda (3.5.0)
107
+ shoulda-context (~> 1.0, >= 1.0.1)
108
+ shoulda-matchers (>= 1.4.1, < 3.0)
109
+ shoulda-context (1.1.6)
110
+ shoulda-matchers (2.4.0)
104
111
  activesupport (>= 3.0.0)
105
- simplecov (0.7.1)
106
- multi_json (~> 1.0)
107
- simplecov-html (~> 0.7.1)
108
- simplecov-html (0.7.1)
109
- sprockets (2.0.4)
112
+ sprockets (2.10.1)
110
113
  hike (~> 1.2)
114
+ multi_json (~> 1.0)
111
115
  rack (~> 1.0)
112
116
  tilt (~> 1.1, != 1.3.0)
113
- sqlite3 (1.3.6)
114
- test-unit (2.5.3)
115
- thor (0.14.6)
116
- tilt (1.3.3)
117
- treetop (1.4.12)
117
+ sprockets-rails (2.0.1)
118
+ actionpack (>= 3.0)
119
+ activesupport (>= 3.0)
120
+ sprockets (~> 2.8)
121
+ sqlite3 (1.3.8)
122
+ test-unit (2.5.5)
123
+ thor (0.18.1)
124
+ thread_safe (0.1.3)
125
+ atomic
126
+ tilt (1.4.1)
127
+ treetop (1.4.15)
118
128
  polyglot
119
129
  polyglot (>= 0.3.1)
120
130
  turn (0.9.6)
121
131
  ansi
122
- tzinfo (0.3.33)
123
- yard (0.6.8)
132
+ tzinfo (0.3.38)
133
+ yard (0.8.7.3)
124
134
 
125
135
  PLATFORMS
126
136
  ruby
127
137
 
128
138
  DEPENDENCIES
129
- activerecord
139
+ activerecord (>= 4.0.0)
130
140
  activesupport
141
+ byebug
131
142
  database_cleaner
132
- debugger (~> 1.2.2)
133
143
  i18n
134
144
  jeweler (~> 1.8.0)
135
- minitest
145
+ protected_attributes (~> 1.0.5)
136
146
  rails
137
- rcov (~> 1.0.0)
138
147
  redcarpet
139
- ruby-debug
140
148
  shoulda
141
- simplecov (~> 0.7.1)
142
149
  sqlite3
143
150
  test-unit
144
151
  turn
@@ -27,57 +27,48 @@ Check out the examples below.
27
27
  Just define inside of your model `translatable` with block.
28
28
  Block accepts following methods:
29
29
 
30
- translatable *args
30
+ field *args
31
31
  Params:
32
32
  first - Here should be specified an attribute that will be translated.
33
33
  second - Define here a hash that will be later provided for validation to model.
34
34
 
35
35
  This method may be called multiple times.
36
36
  Examples:
37
- translatable :title, :presence => true, :uniqueness => true
38
- translatable :content, :presence => true
39
- translatable :notes
37
+ field :title, :presence => true, :uniqueness => true
38
+ field :content, :presence => true
39
+ field :notes
40
40
 
41
- translatable_model model_name
41
+ class_name model_name
42
42
  Params:
43
43
  model_name - Define the model name here if it is different from following "Translatable<CURRENT_MODEL>".
44
44
  For News model, TranslatableNews will be used as the one that keeping translations. It can be defined
45
45
  in a three ways: as constant, string or symbol.
46
46
  Examples:
47
- translatable_model TranslatedNews
47
+ class_name "TranslatedNews"
48
48
  OR
49
- translatable_model "TranslatedNews"
50
- OR
51
- translatable_model :TranslatedNews
49
+ class_name :TranslatedNews
52
50
 
53
- translatable_origin origin_key
51
+ foreign_key origin_key
54
52
  Params:
55
53
  origin_key - This key will be used to define the the relations for translations model.
56
54
  By default it will be :origin. Translations model should also have such attribute defined.
57
55
 
58
56
  This value will also be used for validation, as its presence is compulsory for translations model.
59
57
  Examples:
60
- translatable_origin :message
58
+ foreign_key :message
61
59
  OR
62
- translatable_origin :post
60
+ foreign_key :post
63
61
 
64
- translatable_locale locale_attr
62
+ locale_key locale_attr
65
63
  Params:
66
64
  locale_attr - This key will be used to define the attribute that is keeping the locale of the translation.
67
65
  By default it will be :locale. Translations model should also have such attribute defined.
68
66
 
69
67
  This value will also be used for validation, as its presence is compulsory for translations model.
70
68
  Examples:
71
- translatable_locale :language
69
+ locale_key :language
72
70
  OR
73
- translatable_locale :lang
74
-
75
- translatable_attr_accessible
76
- translatable_attr_protected
77
- If this line is set then the attributes :locale and :origin will be allowed or protected
78
- from for mass-assigment.
79
-
80
- Note: Note sure that this is the best implementation. Would appreciate any better ideas.
71
+ locale_key :lang
81
72
 
82
73
  == Now to create the translations?
83
74
 
@@ -99,7 +90,7 @@ Migrations:
99
90
  t.timestamps
100
91
  end
101
92
 
102
- create_table(:translatable_news) do |t|
93
+ create_table(:translated_news) do |t|
103
94
  t.string :title, :null => false
104
95
  t.string :content, :null => false
105
96
  t.integer :origin_id, :null => false
@@ -124,26 +115,19 @@ Migrations:
124
115
 
125
116
  Models:
126
117
 
127
- class Author < ActiveRecord::Base
128
- validates :name, :presence => true
129
- end
130
-
131
- class TranslatableNews < ActiveRecord::Base
132
- attr_accessible :title, :content
133
- end
134
-
135
118
  class News < ActiveRecord::Base
136
-
119
+
137
120
  belongs_to :author
138
-
121
+
139
122
  translatable do
140
- translatable :title, :presence => true, :uniqueness => true
141
- translatable :content, :presence => true
142
- translatable_model "TranslatedNews"
143
- translatable_origin :origin_id
144
- translatable_attr_accessible
123
+ field :title, :presence => true, :uniqueness => true
124
+ field :content, :presence => true
125
+ class_name "TranslatedNews"
126
+ foreign_key :origin_id
145
127
  end
146
-
128
+
129
+ accepts_nested_attributes_for :translations, :current_translation
130
+ attr_accessible :translations_attributes, :current_translation_attributes
147
131
  attr_accessible :author_id, :author
148
132
  end
149
133
 
@@ -151,19 +135,19 @@ An example of application:
151
135
 
152
136
  news = News.create :translations_attributes => [{title: "Resent News", content: "That is where the text goes", locale: "en"}]
153
137
  news.translations.create title: "Заголовок", content: "Содержание",locale: "ru"
154
-
138
+
155
139
  news.content
156
140
  # => "That is where the text goes"
157
-
158
- ::I18n.locale = "ru"
141
+
142
+ news.set_current_translation :ru
159
143
  news.content
160
144
  # => "Сюди идет текст"
161
-
162
- ::I18n.locale = "de"
145
+
146
+ news.set_current_translation :de
163
147
  news.content
164
148
  # => nil
165
-
166
- ::I18n.locale = ::I18n.default_locale
149
+
150
+ news.set_current_translation
167
151
  news.content
168
152
  # => "That is where the text goes"
169
153