simple_model_translations 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -0
- data/VERSION +1 -1
- data/lib/simple_model_translations/base.rb +0 -4
- data/lib/simple_model_translations/class_methods.rb +7 -1
- data/simple_model_translations.gemspec +1 -1
- data/spec/data/models.rb +4 -0
- data/spec/simple_model_translations_spec.rb +5 -0
- data/spec/spec_helper.rb +0 -1
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -16,6 +16,15 @@ So, you'll need the following models to achieve this behaviour:
|
|
16
16
|
translation_for :article
|
17
17
|
end
|
18
18
|
|
19
|
+
or, if you are not going to add some additional behavior to translation class (for example, validations),
|
20
|
+
you can use translation class, created for you by default:
|
21
|
+
|
22
|
+
class Article < ActiveRecord::Base
|
23
|
+
translates :name, :content
|
24
|
+
end
|
25
|
+
|
26
|
+
ArticleTranslation will be generated automagically :)
|
27
|
+
|
19
28
|
Also, you'll need a migration:
|
20
29
|
|
21
30
|
create_table(:article_translations) do |t|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -50,10 +50,6 @@ module SimpleModelTranslations
|
|
50
50
|
include SimpleModelTranslations::Attributes
|
51
51
|
extend SimpleModelTranslations::ClassMethods
|
52
52
|
|
53
|
-
# unless Kernel.const_get(class_name)
|
54
|
-
# klass = Kernel.const_set(class_name.to_sym, Class.new(ActiveRecord::Base))
|
55
|
-
# klass.translation_for(self.name.underscore.to_sym)
|
56
|
-
# end
|
57
53
|
has_many :translations, :class_name => translation_class_name, :dependent => :destroy, :autosave => true
|
58
54
|
|
59
55
|
if options[:accepts_nested_attributes]
|
@@ -5,7 +5,13 @@ module SimpleModelTranslations
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def translation_class
|
8
|
-
|
8
|
+
begin
|
9
|
+
klass = Module.const_get(translation_class_name.to_sym)
|
10
|
+
rescue NameError => e
|
11
|
+
klass = Module.const_set(translation_class_name.to_sym, Class.new(ActiveRecord::Base))
|
12
|
+
klass.translation_for(self.name.underscore.to_sym)
|
13
|
+
end
|
14
|
+
klass
|
9
15
|
end
|
10
16
|
|
11
17
|
def translation_class_name
|
data/spec/data/models.rb
CHANGED
@@ -24,6 +24,11 @@ describe Article do
|
|
24
24
|
I18n.locale = :de
|
25
25
|
article.name.should == 'Hello'
|
26
26
|
end
|
27
|
+
|
28
|
+
it "should create translation class automatically if it doesn't exists" do
|
29
|
+
Tag.translation_class.should_not be_nil
|
30
|
+
Tag.translation_class.table_name.should == 'tag_translations'
|
31
|
+
end
|
27
32
|
end
|
28
33
|
|
29
34
|
describe ArticleTranslation do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_model_translations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pavel Forkert
|