radiant-globalize2-extension 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -3,7 +3,7 @@
3
3
  require 'globalize2/form_builder_extensions'
4
4
 
5
5
  class Globalize2Extension < Radiant::Extension
6
- version "0.2.1"
6
+ version "0.2.2"
7
7
  description "Translate content in Radiant CMS using the Globalize2 Rails plugin."
8
8
  url "http://blog.aissac.ro/radiant/globalize2-extension/"
9
9
 
@@ -16,15 +16,15 @@ class Globalize2Extension < Radiant::Extension
16
16
  }
17
17
 
18
18
  def self.default_language
19
- @@default_language ||= Radiant::Config['globalize.default_language'].blank? ? "en" : Radiant::Config['globalize.default_language']
19
+ @@default_language ||= Radiant::Config['globalize.default_language']
20
20
  end
21
21
 
22
22
  def self.languages
23
- @@languages ||= Radiant::Config['globalize.languages'].blank? ? [] : Radiant::Config['globalize.languages'].split(",").map(&:to_s)
23
+ @@languages ||= Radiant::Config['globalize.languages'].split(",")
24
24
  end
25
25
 
26
26
  def self.locales
27
- @@locales ||= [default_language, *languages].map(&:to_s)
27
+ @@locales ||= ([default_language] | languages)
28
28
  end
29
29
 
30
30
  def self.content_locale
@@ -36,6 +36,9 @@ class Globalize2Extension < Radiant::Extension
36
36
  end
37
37
 
38
38
  def activate
39
+ Radiant::Config['globalize.default_language'] ||= 'en'
40
+ Radiant::Config['globalize.languages'] ||= 'en' # Hack: Config won't write empty settings to database.
41
+
39
42
  require 'i18n/backend/fallbacks'
40
43
  I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
41
44
 
@@ -7,12 +7,12 @@ module Globalize2
7
7
 
8
8
  def text_field_with_globalize(method, options = {})
9
9
  Rails.logger.debug "FormBuilder: text_field_with_globalize"
10
- options[:value] = options[:value] || I18n.with_locale(Globalize2Extension.content_locale) { object.send(method) }
10
+ options[:value] = options[:value] || I18n.with_locale(Globalize2Extension.content_locale) { object && object.send(method) }
11
11
  text_field_without_globalize(method, options)
12
12
  end
13
13
 
14
14
  def text_area_with_globalize(method, options = {})
15
- options[:value] = options[:value] || I18n.with_locale(Globalize2Extension.content_locale) { object.send(method) }
15
+ options[:value] = options[:value] || I18n.with_locale(Globalize2Extension.content_locale) { object && object.send(method) }
16
16
  text_area_without_globalize(method, options)
17
17
  end
18
18
  end
@@ -1,7 +1,7 @@
1
1
  module Globalize2
2
2
  module GlobalizedFieldsControllerExtension
3
3
  def self.included base
4
- base.before_filter :set_content_locale
4
+ base.prepend_before_filter :set_content_locale
5
5
  end
6
6
 
7
7
 
@@ -0,0 +1,15 @@
1
+ module Globalize2::LocalizedContent
2
+ def localized_content_for *fields
3
+ fields.each do |field|
4
+ class_eval %{
5
+ def #{field}_with_localized_content
6
+ I18n.with_locale(Globalize2Extension.content_locale) do
7
+ #{field}_without_localized_content
8
+ end
9
+ end
10
+ }
11
+
12
+ alias_method_chain field, :localized_content
13
+ end
14
+ end
15
+ end
@@ -8,13 +8,16 @@ module Globalize2
8
8
 
9
9
 
10
10
  base.class_eval do
11
-
11
+ extend Globalize2::LocalizedContent
12
+
12
13
  def self.locale
13
14
  I18n.locale
14
15
  end
15
16
  #eigenclass = class << self; self; end
16
17
 
17
18
  translates :title, :slug, :breadcrumb, :description, :keywords
19
+ localized_content_for :title, :slug, :breadcrumb
20
+
18
21
  attr_accessor :reset_translations
19
22
  alias_method_chain 'tag:link', :globalize
20
23
  alias_method_chain 'tag:children:each', :globalize
@@ -70,12 +73,12 @@ module Globalize2
70
73
 
71
74
  def path_with_globalize
72
75
  unless parent || Globalize2Extension.locales.size <= 1
73
- '/' + I18n.locale.to_s + path_without_globalize
76
+ '/' + Globalize2Extension.content_locale + path_without_globalize
74
77
  else
75
78
  path_without_globalize
76
79
  end
77
80
  end
78
-
81
+
79
82
  def clone
80
83
  new_page = super
81
84
  translations.each do |t|
@@ -1,7 +1,11 @@
1
1
  module Globalize2
2
2
  module PagePartExtensions
3
3
  def self.included(base)
4
- base.alias_method_chain :content, :globalize
4
+ base.class_eval do
5
+ extend Globalize2::LocalizedContent
6
+
7
+ localized_content_for :content
8
+ end
5
9
  end
6
10
 
7
11
  def clone
@@ -11,11 +15,5 @@ module Globalize2
11
15
  end
12
16
  new_page_part
13
17
  end
14
-
15
- def content_with_globalize
16
- I18n.with_locale(Globalize2Extension.content_locale) do
17
- content_without_globalize
18
- end
19
- end
20
18
  end
21
19
  end
@@ -7,8 +7,7 @@ module Globalize2
7
7
  end
8
8
 
9
9
  def reset_locale
10
- @locale = Globalize2Extension.default_language
11
- Globalize2Extension.content_locale = I18n.locale = @locale.to_sym
10
+ Globalize2Extension.content_locale = session[:content_locale] = Globalize2Extension.default_language unless params[:content_locale]
12
11
  end
13
12
  end
14
13
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-globalize2-extension
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Cristi Duma
@@ -21,7 +21,7 @@ autorequire:
21
21
  bindir: bin
22
22
  cert_chain: []
23
23
 
24
- date: 2011-03-30 00:00:00 +02:00
24
+ date: 2011-03-31 00:00:00 +02:00
25
25
  default_executable:
26
26
  dependencies:
27
27
  - !ruby/object:Gem::Dependency
@@ -76,6 +76,7 @@ files:
76
76
  - lib/globalize2/form_builder_extensions.rb
77
77
  - lib/globalize2/globalize_tags.rb
78
78
  - lib/globalize2/globalized_fields_controller_extension.rb
79
+ - lib/globalize2/localized_content.rb
79
80
  - lib/globalize2/page_extensions.rb
80
81
  - lib/globalize2/page_part_extensions.rb
81
82
  - lib/globalize2/pages_controller_extensions.rb