easy_globalize3_accessors 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +25 -7
- data/lib/easy_globalize3_accessors.rb +4 -4
- data/lib/easy_globalize3_accessors/version.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
=
|
1
|
+
= EasyGlobalize3Accessors
|
2
2
|
|
3
3
|
== Introduction
|
4
4
|
|
5
|
-
Generator of easy accessor methods for models using
|
5
|
+
Generator of easy accessor methods for models using Globalize3.
|
6
6
|
|
7
7
|
Use globalize_accessors with list of translated fields you want easy access to and extra :locales array listing locales for which you want the accessors to be generated.
|
8
8
|
|
@@ -11,7 +11,7 @@ This way a single form can be used to edit given model fields with all anticipat
|
|
11
11
|
|
12
12
|
== Installation
|
13
13
|
|
14
|
-
|
14
|
+
gem install easy_globalize3_accessors
|
15
15
|
|
16
16
|
== Example
|
17
17
|
|
@@ -19,14 +19,32 @@ Definition like this:
|
|
19
19
|
|
20
20
|
class Product
|
21
21
|
translates :title, :description
|
22
|
-
globalize_accessors :
|
22
|
+
globalize_accessors :locales => [:en, :pl], :attributes => [:title]
|
23
23
|
end
|
24
24
|
|
25
|
-
Gives you access to methods: title_pl, title_en,
|
25
|
+
Gives you access to methods: title_pl, title_en, title_pl=, title_en= (and similar set of description_* methods). And they work seamlessly with Globalize3 (not even touching the "core" title, title= methods used by Globalize3 itself).
|
26
26
|
|
27
|
-
|
27
|
+
:locales and :attributes are optional. Default values are:
|
28
|
+
:locales => I18n.available_locales
|
29
|
+
:attributes => translated_attribute_names
|
28
30
|
|
29
|
-
|
31
|
+
which means that skipping all options will generate you accessor method for all translated fields and available languages
|
32
|
+
|
33
|
+
== Always define accessors
|
34
|
+
|
35
|
+
If you wish to always define accessors and don't want to write globalize_accessors in every class, you can extend ActiveRecord::Base with such module:
|
36
|
+
|
37
|
+
module TranslatesWithAccessors
|
38
|
+
|
39
|
+
def translates(*params)
|
40
|
+
options = params.extract_options!
|
41
|
+
options.reverse_merge!(:globalize_accessors => true)
|
42
|
+
accessors = options.delete(:globalize_accessors)
|
43
|
+
super
|
44
|
+
globalize_accessors if accessors
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
30
48
|
|
31
49
|
== blah blah
|
32
50
|
|
@@ -4,9 +4,9 @@ require 'globalize3'
|
|
4
4
|
module EasyGlobalize3Accessors
|
5
5
|
|
6
6
|
def globalize_accessors(options = {})
|
7
|
-
options.reverse_merge!(:
|
7
|
+
options.reverse_merge!(:locales => I18n.available_locales, :attributes => translated_attribute_names)
|
8
8
|
|
9
|
-
|
9
|
+
each_attribute_and_locale(options) do |attr_name, locale|
|
10
10
|
define_accessors(attr_name, locale)
|
11
11
|
end
|
12
12
|
end
|
@@ -33,9 +33,9 @@ module EasyGlobalize3Accessors
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
36
|
+
def each_attribute_and_locale(options)
|
37
37
|
options[:attributes].each do |attr_name|
|
38
|
-
options[:
|
38
|
+
options[:locales].each do |locale|
|
39
39
|
yield attr_name, locale
|
40
40
|
end
|
41
41
|
end
|