activeadmin-translate 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # ActiveAdmin Translate Changelog
2
+
3
+ ## 0.1.0 - November 15, 2012
4
+
5
+ - Initial version
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,32 @@
1
+ Contribute to ActiveAdmin Translate
2
+ ===================================
3
+
4
+ File an issue
5
+ -------------
6
+
7
+ You can report bugs and feature requests to [GitHub Issues](https://github.com/netzpirat/activeadmin-globalize/issues).
8
+
9
+ **Please don't ask question in the issue tracker**, instead ask them at Stackoverflow and use the
10
+ [activeadmin](http://stackoverflow.com/questions/tagged/activeadmin) tag.
11
+
12
+ When you file a bug, please try to follow these simple rules if applicable:
13
+
14
+ * Make sure you've read the README carefully.
15
+ * Give as much information about your environment, like Ruby and ActiveAdmin version.
16
+ * Make sure that the issue is reproducible with your description.
17
+
18
+ **It's most likely that your bug gets resolved faster if you provide as much information as possible!**
19
+
20
+ Development
21
+ -----------
22
+
23
+ * Documentation hosted at [RubyDoc](http://rubydoc.info/github/netzpirat/activeadmin-globalize/master/frames).
24
+ * Source hosted at [GitHub](https://github.com/netzpirat/activeadmin-globalize).
25
+
26
+ Pull requests are very welcome! Please try to follow these simple rules if applicable:
27
+
28
+ * Please create a topic branch for every separate change you make.
29
+ * Update the [Yard](http://yardoc.org/) documentation.
30
+ * Update the [README](https://github.com/netzpirat/haml_coffee_assets/blob/master/README.md).
31
+ * Update the [CHANGELOG](https://github.com/netzpirat/haml_coffee_assets/blob/master/CHANGELOG.md) for noteworthy changes.
32
+ * Please **do not change** the version number.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Dmitrii Soltis, Michael Kessler
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # ActiveAdmin Translate
2
+
3
+ Translate your [Globalize3](https://github.com/svenfuchs/globalize3) ActiveModel translations in
4
+ [ActiveAdmin](https://github.com/gregbell/active_admin), using [jQueryUI tabs](http://jqueryui.com/tabs/) to switch
5
+ between the locales.
6
+
7
+ ## Installation
8
+
9
+ Add the gem to your `Gemfile`
10
+
11
+ ```ruby
12
+ gem 'activeadmin-translate`
13
+ ```
14
+
15
+ and install it with Bundler:
16
+
17
+ ```Bash
18
+ $ bundle
19
+ ```
20
+
21
+ ## Configuration
22
+
23
+ ### Set available languages
24
+
25
+ ActiveAdmin Translate takes the available languages from `I18n.available_locales`, so you want to configure them in
26
+ your `application.rb` like
27
+
28
+ ```ruby
29
+ config.i18n.available_locales = [:en, :de, :fr, :it]
30
+ ```
31
+
32
+ ### Include ActiveAdmin Translate
33
+
34
+ You need to include the ActiveAdmin JavaScript by adding it to your manifest in
35
+ `app/assets/javascripts/active_admin.js`:
36
+
37
+ ```javascript
38
+ //= require active_admin/translate
39
+ ```
40
+
41
+ Then you also need to import the SASS customizations in `app/assets/stylesheets/active_admin.css.scss`:
42
+
43
+ ```css
44
+ @import "active_admin/translate";
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ ### Make your translations accessible
50
+
51
+ In order to access the translations of your model and be able to write them on save, you need to make attributes
52
+ accessible in your model. Globalize3 stores the model translations in a separate table that is accessible as
53
+ `translations` in your model:
54
+
55
+ ```ruby
56
+ class GlobalizedModel < ActiveRecord::Base
57
+ attr_accessible :translations, :translations_attributes
58
+ accepts_nested_attributes_for :translations
59
+ end
60
+ ```
61
+
62
+ ### Translate your ActiveAdmin forms
63
+
64
+ To translate your form you need to use the `translate_inputs` form helper:
65
+
66
+ ```ruby
67
+ form do |f|
68
+ f.translate_inputs do |t|
69
+ t.input :title
70
+ t.input :description
71
+ end
72
+ end
73
+ ```
74
+
75
+ ### Translate your ActiveAdmin show action
76
+
77
+ To show the attributes for all locales, you use the `translate_attributes_table_for` view helper:
78
+
79
+ ```ruby
80
+ show do |model|
81
+ panel 'Globalized Model' do
82
+ translate_attributes_table_for model do
83
+ row :title
84
+ row :description do |p|
85
+ BlueCloth.new(p.teaser).to_html.html_safe
86
+ end
87
+ end
88
+ end
89
+ end
90
+ ```
91
+
92
+ ### Localize the languages
93
+
94
+ To localize your locale names, use the following I18n key structure per locale:
95
+
96
+ ```yml
97
+ en:
98
+ active_admin:
99
+ translate:
100
+ en: "English"
101
+ ```
102
+
103
+ and add more translations with the registered locale symbol.
104
+
105
+ ## Author
106
+
107
+ Developed by Michael Kessler, [mksoft.ch](https://mksoft.ch).
108
+
109
+ If you like ActiveAdmin Translate, you can watch the repository at
110
+ [GitHub](https://github.com/netzpirat/activeadmin-globalize) and follow [@netzpirat](https://twitter.com/#!/netzpirat)
111
+ on Twitter for project updates.
112
+
113
+ ## Contribute to ActiveAdmin Translate
114
+
115
+ ### File an issue
116
+
117
+ You can report bugs and feature requests to [GitHub Issues](https://github.com/netzpirat/activeadmin-globalize/issues).
118
+
119
+ **Please don't ask question in the issue tracker**, instead ask them at Stackoverflow and use the
120
+ [activeadmin](http://stackoverflow.com/questions/tagged/activeadmin) tag.
121
+
122
+ When you file a bug, please try to follow these simple rules if applicable:
123
+
124
+ * Make sure you've read the README carefully.
125
+ * Give as much information about your environment, like Ruby and ActiveAdmin version.
126
+ * Make sure that the issue is reproducible with your description.
127
+
128
+ **It's most likely that your bug gets resolved faster if you provide as much information as possible!**
129
+
130
+ ### Development
131
+
132
+ * Documentation hosted at [RubyDoc](http://rubydoc.info/github/netzpirat/activeadmin-globalize/master/frames).
133
+ * Source hosted at [GitHub](https://github.com/netzpirat/activeadmin-globalize).
134
+
135
+ Pull requests are very welcome! Please try to follow these simple rules if applicable:
136
+
137
+ * Please create a topic branch for every separate change you make.
138
+ * Update the [Yard](http://yardoc.org/) documentation.
139
+ * Update the [README](https://github.com/netzpirat/activeadmin-globalize/blob/master/README.md).
140
+ * Update the [CHANGELOG](https://github.com/netzpirat/activeadmin-globalize/blob/master/CHANGELOG.md) for noteworthy changes.
141
+ * Please **do not change** the version number.
142
+
143
+ ## Contributors
144
+
145
+ See the [CHANGELOG](https://github.com/netzpirat/activeadmin-globalize/blob/master/CHANGELOG.md) and the GitHub list of
146
+ [contributors](https://github.com/netzpirat/activeadmin-globalize/contributors).
147
+
148
+ ## Acknowledgment
149
+
150
+ This project has taken some ideas and code from the following projects:
151
+
152
+ - [activeadmin-globalize3](https://github.com/stefanoverna/activeadmin-globalize3) from [Stefano Verna](https://github.com/stefanoverna)
153
+ - [ActiveAdmin-Globalize3-inputs](https://github.com/mimimi/ActiveAdmin-Globalize3-inputs) from [Dmitrii Soltis](https://github.com/mimimi)
154
+
155
+ ## License
156
+
157
+ Copyright (c) 2012 Dmitrii Soltis, Michael Kessler
158
+
159
+ MIT License
160
+
161
+ Permission is hereby granted, free of charge, to any person obtaining
162
+ a copy of this software and associated documentation files (the
163
+ "Software"), to deal in the Software without restriction, including
164
+ without limitation the rights to use, copy, modify, merge, publish,
165
+ distribute, sublicense, and/or sell copies of the Software, and to
166
+ permit persons to whom the Software is furnished to do so, subject to
167
+ the following conditions:
168
+
169
+ The above copyright notice and this permission notice shall be
170
+ included in all copies or substantial portions of the Software.
171
+
172
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
173
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
174
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
175
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
176
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
177
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
178
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ $(function() {
2
+ $('.activeadmin-translate').tabs()
3
+ });
@@ -0,0 +1,81 @@
1
+ .active_admin {
2
+
3
+ .activeadmin-translate .locales {
4
+ overflow: auto;
5
+ margin-right: 10px;
6
+
7
+ li {
8
+ @include section-header;
9
+
10
+ border-top-left-radius: 10px;
11
+ border-top-right-radius: 10px;
12
+
13
+ float: right !important;
14
+
15
+ &.ui-state-active {
16
+ background: white;
17
+ }
18
+ }
19
+ }
20
+
21
+ .has_many_fields .activeadmin-translate .locales {
22
+ padding-top: 10px !important;
23
+ }
24
+
25
+ .activeadmin-translate .locale {
26
+ clear: left;
27
+ }
28
+
29
+ .activeadmin-translate .ui-tabs-hide {
30
+ display: none !important;
31
+ }
32
+
33
+ .ui-tabs {
34
+ position: relative;
35
+ padding: .2em;
36
+ zoom: 1;
37
+ }
38
+
39
+ .ui-tabs .ui-tabs-nav {
40
+ margin: 0;
41
+ padding: .2em .2em 0;
42
+ }
43
+
44
+ .ui-tabs .ui-tabs-nav li {
45
+ list-style: none;
46
+ float: left;
47
+ position: relative;
48
+ top: 0;
49
+ margin: 1px .2em 0 0;
50
+ border-bottom: 0;
51
+ padding: 0;
52
+ white-space: nowrap;
53
+ }
54
+
55
+ .ui-tabs .ui-tabs-nav li a {
56
+ float: left;
57
+ padding: .5em 1em;
58
+ text-decoration: none;
59
+ }
60
+
61
+ .ui-tabs .ui-tabs-nav li.ui-tabs-active {
62
+ margin-bottom: -1px;
63
+ padding-bottom: 1px;
64
+ }
65
+
66
+ .ui-tabs .ui-tabs-nav li.ui-tabs-active a, .ui-tabs .ui-tabs-nav li.ui-state-disabled a, .ui-tabs .ui-tabs-nav li.ui-tabs-loading a {
67
+ cursor: text;
68
+ }
69
+
70
+ .ui-tabs .ui-tabs-nav li a, .ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-active a {
71
+ cursor: pointer;
72
+ }
73
+
74
+ .ui-tabs .ui-tabs-panel {
75
+ display: block;
76
+ border-width: 0;
77
+ padding: 1em 1.4em;
78
+ background: none;
79
+ }
80
+
81
+ }
@@ -0,0 +1,4 @@
1
+ en:
2
+ active_admin:
3
+ translate:
4
+ en: "English"
@@ -0,0 +1,14 @@
1
+ module ActiveAdmin
2
+ module Translate
3
+
4
+ # ActiveAdmin Translate engine to provide the needed assets.
5
+ #
6
+ class Engine < ::Rails::Engine
7
+
8
+ initializer 'ActiveAdmin Translate precompile' do |app|
9
+ app.config.assets.precompile += %w(active_admin/translate.css active_admin/translate.js)
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,71 @@
1
+ module ActiveAdmin
2
+ module Translate
3
+
4
+ # Form builder to build input fields that are arranged by locale in tabs.
5
+ #
6
+ module FormBuilder
7
+
8
+ # Create the local field sets to enter the inputs per locale
9
+ #
10
+ # @param [Symbol] name the name of the translation association
11
+ # @param [Proc] block the block for the additional inputs
12
+ #
13
+ def translate_inputs(name = :translations, &block)
14
+ form_buffers.last << template.content_tag(:div, :class => "activeadmin-translate #{ translate_id }") do
15
+ locale_tabs << locale_fields(name, block)
16
+ end
17
+ end
18
+
19
+ protected
20
+
21
+ # Create the local field sets to enter the inputs per locale.
22
+ #
23
+ # @param [Symbol] name the name of the translation association
24
+ # @param [Proc] block the block for the additional inputs
25
+ #
26
+ def locale_fields(name, block)
27
+ ::I18n.available_locales.map do |locale|
28
+ translation = object.method(name).call.find_or_initialize_by_locale(locale)
29
+ translation.instance_variable_set(:@errors, object.errors) if locale == I18n.default_locale
30
+
31
+ fields = proc do |form|
32
+ form.input(:locale, :as => :hidden)
33
+ block.call(form)
34
+ end
35
+
36
+ inputs_for_nested_attributes(:for => [name, translation], :id => field_id(locale), :class => "inputs locale locale-#{ locale }", &fields)
37
+ end.join.html_safe
38
+ end
39
+
40
+
41
+ # Create the locale tab to switch the translations.
42
+ #
43
+ # @return [String] the HTML for the locale tabs
44
+ #
45
+ def locale_tabs
46
+ template.content_tag(:ul, :class => 'locales') do
47
+ ::I18n.available_locales.map do |locale|
48
+ template.content_tag(:li) do
49
+ template.content_tag(:a, ::I18n.t("active_admin.translate.#{ locale }"), :href => "##{ field_id(locale) }")
50
+ end
51
+ end.join.html_safe
52
+ end
53
+ end
54
+
55
+ # Get the unique id for the translation field
56
+ #
57
+ def field_id(locale)
58
+ "locale-#{ locale }-#{ translate_id }"
59
+ end
60
+
61
+ # Get the unique id for the translation
62
+ #
63
+ # @return [String] the id
64
+ #
65
+ def translate_id
66
+ "#{ self.object.class.to_s.underscore.dasherize }-#{ self.object.object_id }"
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,6 @@
1
+ module ActiveAdmin
2
+ module Translate
3
+ # The current released version
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
@@ -0,0 +1,41 @@
1
+ module ActiveAdmin
2
+ module Translate
3
+
4
+ # Adds a builder method `translate_attributes_table_for` to build a
5
+ # table with translations for a model that has been localized with
6
+ # Globalize3.
7
+ #
8
+ class TranslateAttributesTable < ::ActiveAdmin::Views::AttributesTable
9
+
10
+ builder_method :translate_attributes_table_for
11
+
12
+ def row(attr, &block)
13
+ ::I18n.available_locales.each_with_index do |locale, index|
14
+ @table << tr do
15
+ if index == 0
16
+ th :rowspan => ::I18n.available_locales.length do
17
+ header_content_for(attr)
18
+ end
19
+ end
20
+ td do
21
+ ::I18n.with_locale locale do
22
+ content_for(block || attr)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ protected
30
+
31
+ def default_id_for_prefix
32
+ 'attributes_table'
33
+ end
34
+
35
+ def default_class_name
36
+ 'attributes_table'
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,9 @@
1
+ require 'active_admin'
2
+ require 'globalize3'
3
+
4
+ require 'active_admin/version'
5
+ require 'active_admin/translate/engine'
6
+ require 'active_admin/translate/form_builder'
7
+ require 'active_admin/views/translate_attributes_table'
8
+
9
+ ActiveAdmin::FormBuilder.send(:include, ::ActiveAdmin::Translate::FormBuilder)
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeadmin-translate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Kessler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activeadmin
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: globalize3
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: railties
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Translate your models in ActiveAdmin with Globalize3.
63
+ email:
64
+ - michi@netzpiraten.ch
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - app/assets/javascripts/active_admin/translate.js
70
+ - app/assets/stylesheets/active_admin/translate.css.scss
71
+ - lib/active_admin/translate/engine.rb
72
+ - lib/active_admin/translate/form_builder.rb
73
+ - lib/active_admin/translate/version.rb
74
+ - lib/active_admin/views/translate_attributes_table.rb
75
+ - lib/activeadmin-translate.rb
76
+ - config/locales/en.yml
77
+ - LICENSE
78
+ - README.md
79
+ - CHANGELOG.md
80
+ - CONTRIBUTING.md
81
+ homepage: https://github.com/netzpirat/activeadmin-translate
82
+ licenses: []
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.23
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Translate models with ActiveAdmin.
105
+ test_files: []
106
+ has_rdoc: