attribute_localizer 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/attribute_localizer.rb +8 -4
- metadata +3 -3
data/lib/attribute_localizer.rb
CHANGED
@@ -7,17 +7,21 @@ module AttributeLocalizer
|
|
7
7
|
module ClassMethods
|
8
8
|
|
9
9
|
def localize_attributes(*attributes)
|
10
|
+
options = attributes.extract_options!
|
10
11
|
|
11
12
|
klass = class << self; self end
|
12
13
|
|
13
14
|
class_eval 'after_save :serialize_localizations'
|
14
|
-
class_eval 'attr_accessor :locale'
|
15
|
+
class_eval 'attr_accessor :locale' if options[:locale_virtual]
|
15
16
|
attributes.each { |attribute| class_eval "attr_accessor :#{attribute}" }
|
16
17
|
|
17
18
|
src = attributes.map do |attribute|
|
18
19
|
str = "def #{attribute}\n"
|
19
|
-
str << "@#{attribute}
|
20
|
-
str << "
|
20
|
+
str << " return @#{attribute} if @#{attribute}\n"
|
21
|
+
str << " @#{attribute} = I18n.t(\"\#{self.class.send :localization_namespace}.\#{localization_hash_key}.#{attribute}\", :locale => locale, :default => '')\n"
|
22
|
+
str << " @#{attribute} = nil unless @#{attribute}.present?\n"
|
23
|
+
str << " @#{attribute}\n"
|
24
|
+
str << "end\n"
|
21
25
|
str
|
22
26
|
end.join("\n")
|
23
27
|
|
@@ -26,7 +30,7 @@ module AttributeLocalizer
|
|
26
30
|
src = <<-end_src
|
27
31
|
|
28
32
|
def locale
|
29
|
-
@locale || I18n.locale
|
33
|
+
#{options[:locale_virtual] ? '@locale' : 'super'} || I18n.locale
|
30
34
|
end
|
31
35
|
|
32
36
|
end_src
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Deering
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-28 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|