forked from jerrod/radiant-globalize2-extension
-
Notifications
You must be signed in to change notification settings - Fork 6
/
globalize2_extension.rb
70 lines (54 loc) · 2.77 KB
/
globalize2_extension.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Uncomment this if you reference any of your controllers in activate
# require_dependency 'application'
class Globalize2Extension < Radiant::Extension
version "0.1"
description "Translate content in Radiant CMS using the Globalize2 Rails plugin."
url "http://blog.aissac.ro/radiant/globalize2-extension/"
GLOBALIZABLE_CONTENT = {
Page => [:title, :slug, :breadcrumb, :description, :keywords],
PagePart => [:content],
Layout => [:content],
Snippet => [:content]
}
def self.default_language
@@default_language ||= Radiant::Config['globalize.default_language'].blank? ? "en" : Radiant::Config['globalize.default_language']
end
def self.languages
@@languages ||= Radiant::Config['globalize.languages'].blank? ? [] : Radiant::Config['globalize.languages'].split(",").map(&:to_s)
end
def self.locales
@@locales ||= [default_language, *languages].map(&:to_s)
end
def activate
require 'i18n/backend/fallbacks'
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
admin.page.edit.add :form, 'admin/shared/change_locale', :before => 'edit_page_parts'
admin.snippet.edit.add :form, 'admin/shared/change_locale', :before => 'edit_content'
admin.layout.edit.add :form, 'admin/shared/change_locale', :before => 'edit_content'
admin.page.index.add :top, 'admin/shared/change_locale_admin'
admin.layout.index.add :top, 'admin/shared/change_locale_admin'
admin.snippet.index.add :top, 'admin/shared/change_locale_admin'
admin.page.index.add :sitemap_head, 'admin/shared/globalize_th'
admin.page.index.add :node, 'admin/shared/globalize_td'
I18n.default_locale = Globalize2Extension.default_language
ApplicationController.send(:include, Globalize2::ApplicationControllerExtensions)
Admin::PagesController.send(:include, Globalize2::PagesControllerExtensions)
Admin::PagesController.send(:include, Globalize2::ApplicationControllerExtensions)
SiteController.send(:include, Globalize2::SiteControllerExtensions)
GLOBALIZABLE_CONTENT.each do |model, columns|
model.send(:translates, *columns)
end
Page.send(:include, Globalize2::GlobalizeTags)
Page.send(:include, Globalize2::PageExtensions)
PagePart.send(:include, Globalize2::PagePartExtensions)
#compatibility
CopyMove::Model.send(:include, Globalize2::Compatibility::CopyMove::CopyMoveModelExtensions) if defined?(CopyMoveExtension)
ArchivePage.send(:include, Globalize2::Compatibility::Archive::ArchivePageExtensions) if defined?(ArchiveExtension)
if defined?(PaginateExtension)
Page.send(:include, Globalize2::Compatibility::Paginate::GlobalizeTags)
Page.send(:include, Globalize2::Compatibility::Paginate::PageExtensions)
end
end
def deactivate
end
end