simple_model_translations 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,11 @@ module SimpleModelTranslations
6
6
  end
7
7
 
8
8
  def find_translation_by_locale(locale)
9
- translations.detect { |t| t.locale.to_sym == locale }
9
+ if translations.loaded? || @record.new_record?
10
+ translations.detect { |t| t.locale.to_sym == locale }
11
+ else
12
+ translations.find_by_locale(locale)
13
+ end
10
14
  end
11
15
 
12
16
  def find_or_build_translation_by_locale(locale)
@@ -26,7 +30,7 @@ module SimpleModelTranslations
26
30
  end
27
31
 
28
32
  def current_translation
29
- find_translation_by_locale(current_locale_for_translation) || find_translation_by_locale(default_locale_for_translation)
33
+ cached_translations[current_locale_for_translation] ||= find_translation_by_locale(current_locale_for_translation) || find_translation_by_locale(default_locale_for_translation)
30
34
  end
31
35
 
32
36
  def find_or_build_current_translation
@@ -38,6 +42,10 @@ module SimpleModelTranslations
38
42
  @record.class.name.underscore.to_sym
39
43
  end
40
44
 
45
+ def cached_translations
46
+ @cached_translations ||= {}
47
+ end
48
+
41
49
  def translations
42
50
  @record.send(@translation_association)
43
51
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleModelTranslations
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.5'
3
3
  end
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: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 4
10
- version: 0.2.4
9
+ - 5
10
+ version: 0.2.5
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: 2011-03-13 00:00:00 +02:00
18
+ date: 2011-03-17 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency