acts_as_translatable 0.1.7 → 0.1.8

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.
@@ -1,10 +1,16 @@
1
1
  class ActiveRecord::Base
2
2
  def self.acts_as_translatable_on(*fields)
3
+ field_symbols = fields.map { |f| ":#{f}" }.join(", ")
4
+
3
5
  eval "class ::#{name}
4
6
  after_initialize :translations
5
7
  after_save :save_translations
6
8
  after_destroy :destroy_record_translations
7
9
 
10
+ def self.translatable_fields
11
+ [#{field_symbols}]
12
+ end
13
+
8
14
  def translations
9
15
  unless @translations
10
16
  @translations = {}
@@ -57,6 +63,17 @@ class ActiveRecord::Base
57
63
 
58
64
  fields.each do |field|
59
65
  eval "class ::#{name}
66
+ def self.enable_locale_fallbacks
67
+ if @enable_locale_fallbacks_set
68
+ @enable_locale_fallbacks = true
69
+ end
70
+ @enable_locale_fallbacks
71
+ end
72
+
73
+ def self.enable_locale_fallbacks=(value)
74
+ @enable_locale_fallbacks = value
75
+ end
76
+
60
77
  def #{field}
61
78
  get_field_content(I18n.locale, \"#{field}\")
62
79
  end
@@ -73,7 +90,7 @@ class ActiveRecord::Base
73
90
 
74
91
  def get_field_content(locale, field)
75
92
  # get I18n fallbacks
76
- if I18n.respond_to?(:fallbacks)
93
+ if self.class.enable_locale_fallbacks && I18n.respond_to?(:fallbacks)
77
94
  locales = I18n.fallbacks[locale.to_sym]
78
95
  else
79
96
  locales = [locale.to_sym]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_translatable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 7
10
- version: 0.1.7
9
+ - 8
10
+ version: 0.1.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lasse Bunk
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-17 00:00:00 Z
18
+ date: 2012-05-18 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Ruby on Rails plugin for easy translation of database fields.