simple_model_translations 0.2.1 → 0.2.2
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.
data/Rakefile
CHANGED
@@ -16,12 +16,14 @@ Rake::RDocTask.new do |rdoc|
|
|
16
16
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
17
|
end
|
18
18
|
|
19
|
+
desc 'Build gem'
|
19
20
|
task :build do
|
20
21
|
system 'gem build simple_model_translations.gemspec'
|
21
22
|
system 'mkdir pkg' unless File.exists?('pkg')
|
22
23
|
system "mv simple_model_translations-#{SimpleModelTranslations::VERSION}.gem pkg"
|
23
24
|
end
|
24
|
-
|
25
|
+
|
26
|
+
desc 'Build and push gem to rubygems.org'
|
25
27
|
task :release => :build do
|
26
28
|
system "gem push pkg/simple_model_translations-#{SimpleModelTranslations::VERSION}.gem"
|
27
29
|
end
|
@@ -30,10 +30,7 @@ module SimpleModelTranslations
|
|
30
30
|
|
31
31
|
# attribute getter
|
32
32
|
define_method attribute do
|
33
|
-
|
34
|
-
find_translation_by_locale(default_locale_for_translation)
|
35
|
-
|
36
|
-
translation ? translation.send(attribute) : nil
|
33
|
+
current_translation ? current_translation.send(attribute) : nil
|
37
34
|
end
|
38
35
|
end
|
39
36
|
end
|
@@ -20,6 +20,10 @@ module SimpleModelTranslations
|
|
20
20
|
I18n.default_locale
|
21
21
|
end
|
22
22
|
|
23
|
+
def current_translation
|
24
|
+
find_translation_by_locale(current_locale_for_translation) || find_translation_by_locale(default_locale_for_translation)
|
25
|
+
end
|
26
|
+
|
23
27
|
private
|
24
28
|
def foreign_object_key
|
25
29
|
self.class.name.underscore.to_sym
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe Article do
|
4
|
+
after { I18n.locale = I18n.default_locale }
|
5
|
+
|
4
6
|
it { should have_many :translations }
|
5
7
|
|
6
8
|
it "should have empty translations for a new record" do
|
@@ -9,9 +11,7 @@ describe Article do
|
|
9
11
|
|
10
12
|
it 'should destroy dependent locales' do
|
11
13
|
article = Article.create!(:slug => '__hello__', :name => 'Hello', :content => 'World')
|
12
|
-
expect
|
13
|
-
article.destroy
|
14
|
-
end.to change(ArticleTranslation, :count).by(-1)
|
14
|
+
expect { article.destroy }.to change(ArticleTranslation, :count).by(-1)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should use I18n fallbacks' do
|
@@ -24,6 +24,24 @@ describe Article do
|
|
24
24
|
I18n.locale = :de
|
25
25
|
article.name.should == 'Hello'
|
26
26
|
end
|
27
|
+
|
28
|
+
describe '#current_translation' do
|
29
|
+
it 'should return translation for current locale if it exists' do
|
30
|
+
article = Article.create!(:slug => '__hello__', :name => 'Hello', :content => 'World')
|
31
|
+
article.current_translation.should == article.translations.find_by_locale(I18n.locale)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should return translation for default locale if translation for current locale does not exist' do
|
35
|
+
article = Article.create!(:slug => '__hello__', :name => 'Hello', :content => 'World')
|
36
|
+
I18n.locale = :de
|
37
|
+
article.current_translation.should == article.translations.find_by_locale(I18n.default_locale)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should return nil if translations for current and default locales do not exist' do
|
41
|
+
article = Article.create!(:slug => '__hello__')
|
42
|
+
article.current_translation.should be_nil
|
43
|
+
end
|
44
|
+
end
|
27
45
|
end
|
28
46
|
|
29
47
|
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:
|
5
|
-
prerelease:
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pavel Forkert
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-20 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
163
|
requirements: []
|
164
164
|
|
165
165
|
rubyforge_project:
|
166
|
-
rubygems_version: 1.
|
166
|
+
rubygems_version: 1.4.1
|
167
167
|
signing_key:
|
168
168
|
specification_version: 3
|
169
169
|
summary: Simple ActiveRecord translations for Rails 3
|