Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'form_buffers' has been removed from ActiveAdmin::FormBuilder #4

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# ActiveAdmin Translate Changelog

## 0.2.7 - December 23, 2015

- Fixed problem when block f.translate_inputs called before f.inputs and only one input field rendered (Thanks Pavel Borsky)

## 0.2.6 - November 24, 2015

- Support for has_many translates (Thanks Pavel Borsky)

## 0.2.5 - March 27, 2015

- Updates content_for block to accept record object (Thanks David Stump)
- Add more locales

## 0.2.4 - January 14, 2015

- Add form_buffers backward compatibility


## 0.2.3 - December 6, 2014

- Remove Globalize3 dependency.
- Fix UI tab issues.
- Fix compatibility with current ActiveAdmin.

## 0.2.2 - November 16, 2012

- Include SCSS mixins.
Expand Down
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contribute to ActiveAdmin Translate
File an issue
-------------

You can report bugs and feature requests to [GitHub Issues](https://github.com/netzpirat/activeadmin-globalize/issues).
You can report bugs and feature requests to [GitHub Issues](https://github.com/netzpirat/activeadmin-translate/issues).

**Please don't ask question in the issue tracker**, instead ask them at Stackoverflow and use the
[activeadmin](http://stackoverflow.com/questions/tagged/activeadmin) tag.
Expand All @@ -20,8 +20,7 @@ When you file a bug, please try to follow these simple rules if applicable:
Development
-----------

* Documentation hosted at [RubyDoc](http://rubydoc.info/github/netzpirat/activeadmin-globalize/master/frames).
* Source hosted at [GitHub](https://github.com/netzpirat/activeadmin-globalize).
* Source hosted at [GitHub](https://github.com/netzpirat/activeadmin-translate).

Pull requests are very welcome! Please try to follow these simple rules if applicable:

Expand Down
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# ActiveAdmin Translate

Translate your [Globalize3](https://github.com/svenfuchs/globalize3) ActiveModel translations in
[ActiveAdmin](https://github.com/gregbell/active_admin), using [jQueryUI tabs](http://jqueryui.com/tabs/) to switch
Translate your [Globalize](https://github.com/globalize/globalize) ActiveModel translations in
[ActiveAdmin](https://github.com/activeadmin/activeadmin), using [jQueryUI tabs](http://jqueryui.com/tabs/) to switch
between the locales.

## Installation

Add the gem to your `Gemfile`

```ruby
gem 'activeadmin-translate'
gem 'activeadmin-translate', github: 'twintags/activeadmin-translate'
```

and install it with Bundler:
Expand All @@ -26,7 +26,7 @@ ActiveAdmin Translate takes the available languages from `I18n.available_locales
your `application.rb` like

```ruby
config.i18n.available_locales = [:en, :de, :fr, :it]
config.i18n.available_locales = [:en, :de, :fr, :it, :es, :ca]
```

### Include ActiveAdmin Translate
Expand All @@ -42,7 +42,7 @@ You need to import the SASS for styling the tabs to `app/assets/stylesheets/acti
### Make your translations accessible

In order to access the translations of your model and be able to write them on save, you need to make attributes
accessible in your model. Globalize3 stores the model translations in a separate table that is accessible as
accessible in your model. Globalize stores the model translations in a separate table that is accessible as
`translations` in your model:

```ruby
Expand Down Expand Up @@ -100,14 +100,14 @@ and add more translations with the registered locale symbol.
Developed by Michael Kessler, [FlinkFinger GmbH](http://www.flinkfinger.com).

If you like ActiveAdmin Translate, you can watch the repository at
[GitHub](https://github.com/netzpirat/activeadmin-globalize) and follow [@netzpirat](https://twitter.com/#!/netzpirat)
[GitHub](https://github.com/netzpirat/activeadmin-translate) and follow [@netzpirat](https://twitter.com/netzpirat)
on Twitter for project updates.

## Contribute to ActiveAdmin Translate

### File an issue

You can report bugs and feature requests to [GitHub Issues](https://github.com/netzpirat/activeadmin-globalize/issues).
You can report bugs and feature requests to [GitHub Issues](https://github.com/netzpirat/activeadmin-translate/issues).

**Please don't ask question in the issue tracker**, instead ask them at Stackoverflow and use the
[activeadmin](http://stackoverflow.com/questions/tagged/activeadmin) tag.
Expand All @@ -122,27 +122,26 @@ When you file a bug, please try to follow these simple rules if applicable:

### Development

* Documentation hosted at [RubyDoc](http://rubydoc.info/github/netzpirat/activeadmin-globalize/master/frames).
* Source hosted at [GitHub](https://github.com/netzpirat/activeadmin-globalize).
* Source hosted at [GitHub](https://github.com/netzpirat/activeadmin-translate).

Pull requests are very welcome! Please try to follow these simple rules if applicable:

* Please create a topic branch for every separate change you make.
* Update the [Yard](http://yardoc.org/) documentation.
* Update the [README](https://github.com/netzpirat/activeadmin-globalize/blob/master/README.md).
* Update the [CHANGELOG](https://github.com/netzpirat/activeadmin-globalize/blob/master/CHANGELOG.md) for noteworthy changes.
* Update the [README](https://github.com/netzpirat/activeadmin-translate/blob/master/README.md).
* Update the [CHANGELOG](https://github.com/netzpirat/activeadmin-translate/blob/master/CHANGELOG.md) for noteworthy changes.
* Please **do not change** the version number.

## Contributors

See the [CHANGELOG](https://github.com/netzpirat/activeadmin-globalize/blob/master/CHANGELOG.md) and the GitHub list of
[contributors](https://github.com/netzpirat/activeadmin-globalize/contributors).
See the [CHANGELOG](https://github.com/netzpirat/activeadmin-translate/blob/master/CHANGELOG.md) and the GitHub list of
[contributors](https://github.com/netzpirat/activeadmin-translate/contributors).

## Acknowledgment

This project has taken some ideas and code from the following projects:

- [activeadmin-globalize3](https://github.com/stefanoverna/activeadmin-globalize3) from [Stefano Verna](https://github.com/stefanoverna)
- [activeadmin-globalize](https://github.com/stefanoverna/activeadmin-globalize) from [Stefano Verna](https://github.com/stefanoverna)
- [ActiveAdmin-Globalize3-inputs](https://github.com/mimimi/ActiveAdmin-Globalize3-inputs) from [Dmitrii Soltis](https://github.com/mimimi)

## License
Expand Down
9 changes: 5 additions & 4 deletions activeadmin-translate.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
require File.expand_path('../lib/active_admin/translate/version', __FILE__)

Gem::Specification.new do |gem|
gem.authors = ['Michael Kessler']
gem.authors = ['Michael Kessler', 'Twintags']
gem.email = %w([email protected])
gem.summary = %q{Translate models with ActiveAdmin.}
gem.description = %q{Translate your models in ActiveAdmin with Globalize3.}
gem.homepage = 'https://github.com/netzpirat/activeadmin-translate'
gem.description = %q{Translate your models in ActiveAdmin with Globalize.}
gem.homepage = 'https://github.com/twintags/activeadmin-translate'

gem.files = Dir['{app,lib,config}/**/*'] + %w(LICENSE README.md CHANGELOG.md CONTRIBUTING.md)
gem.name = 'activeadmin-translate'
gem.require_paths = %w(lib)
gem.version = ActiveAdmin::Translate::VERSION
gem.license = 'MIT'

gem.add_dependency 'activeadmin'
gem.add_dependency 'globalize3'
gem.add_dependency 'globalize'
gem.add_dependency 'railties'
end
77 changes: 26 additions & 51 deletions app/assets/stylesheets/active_admin/translate.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,41 @@
.activeadmin-translate .locales {
overflow: auto;
margin-right: 10px;
margin-bottom: -1px;

li {
@include section-header;

border-top-left-radius: 10px;
border-top-right-radius: 10px;

float: right !important;
float: right;

margin-bottom: 0;
padding-left: 0;
padding-right: 0;

a {
padding: .5em 1em;
text-decoration: none;

&:hover,&:active {
text-decoration: underline;
}
box-shadow: none;
border-style: none;
background: inherit;
}

&.ui-state-active {
background: white;
border-bottom-color: white;

a {
color: $section-header-text-color;
cursor: default;
text-decoration: none;
}
}
}
}
Expand All @@ -31,53 +55,4 @@
.activeadmin-translate .ui-tabs-hide {
display: none !important;
}

.ui-tabs {
position: relative;
padding: .2em;
zoom: 1;
}

.ui-tabs .ui-tabs-nav {
margin: 0;
padding: .2em .2em 0;
}

.ui-tabs .ui-tabs-nav li {
list-style: none;
float: left;
position: relative;
top: 0;
margin: 1px .2em 0 0;
border-bottom: 0;
padding: 0;
white-space: nowrap;
}

.ui-tabs .ui-tabs-nav li a {
float: left;
padding: .5em 1em;
text-decoration: none;
}

.ui-tabs .ui-tabs-nav li.ui-tabs-active {
margin-bottom: -1px;
padding-bottom: 1px;
}

.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 {
cursor: text;
}

.ui-tabs .ui-tabs-nav li a, .ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-active a {
cursor: pointer;
}

.ui-tabs .ui-tabs-panel {
display: block;
border-width: 0;
padding: 1em 1.4em;
background: none;
}

}
}
9 changes: 9 additions & 0 deletions config/locales/ca.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ca:
active_admin:
translate:
en: 'Anglès'
de: 'Alemany'
fr: 'Francès'
it: 'Italià'
es: 'Espanyol'
ca: 'Català'
2 changes: 2 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ de:
de: 'Deutsch'
fr: 'Französich'
it: 'Italienisch'
es: 'Spanisch'
ca: 'Katalanisch'
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ en:
de: 'German'
fr: 'French'
it: 'Italian'
es: 'Spanish'
ca: 'Catalan'
9 changes: 9 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
en:
active_admin:
translate:
en: 'English'
de: 'German'
fr: 'French'
it: 'Italian'
es: 'Español'
ca: 'Catalán'
2 changes: 2 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ fr:
de: 'Allemand'
fr: 'Français'
it: 'Italien'
es: 'Espagnol'
ca: 'Catalan'
6 changes: 4 additions & 2 deletions config/locales/it.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
it:
active_admin:
translate:
en: 'Inglese '
en: 'Inglese'
de: 'Alemanno'
fr: 'Francese '
fr: 'Francese'
it: 'Italiano'
es: 'Spagnolo'
ca: 'Catalano'
15 changes: 13 additions & 2 deletions lib/active_admin/translate/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@ module FormBuilder
# @param [Proc] block the block for the additional inputs
#
def translate_inputs(name = :translations, &block)
form_buffers.last << template.content_tag(:div, :class => "activeadmin-translate #{ translate_id }") do
if self.respond_to?(:form_buffers)
html = form_buffers.last
else
html = "".html_safe
end

template.assign(has_many_block: true)

html << template.content_tag(:div, :class => "activeadmin-translate #{ translate_id }") do
locale_tabs << locale_fields(name, block) << tab_script
end

template.concat(html) if template.output_buffer
html
end

protected
Expand All @@ -38,7 +49,7 @@ def locale_fields(name, block)

fields = proc do |form|
form.input(:locale, :as => :hidden)
block.call(form)
block.call form
end

inputs_for_nested_attributes(:for => [name, translation], :id => field_id(locale), :class => "inputs locale locale-#{ locale }", &fields)
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/translate/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ActiveAdmin
module Translate
# The current released version
VERSION = '0.2.2'
VERSION = '0.2.7'
end
end
10 changes: 6 additions & 4 deletions lib/active_admin/views/translate_attributes_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Translate

# Adds a builder method `translate_attributes_table_for` to build a
# table with translations for a model that has been localized with
# Globalize3.
# Globalize.
#
class TranslateAttributesTable < ::ActiveAdmin::Views::AttributesTable

Expand All @@ -17,9 +17,11 @@ def row(attr, &block)
header_content_for(attr)
end
end
td do
::I18n.with_locale locale do
content_for(block || attr)
@collection.each do |record|
td do
::I18n.with_locale locale do
content_for(record, block || attr)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/activeadmin-translate.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'active_admin'
require 'globalize3'
require 'globalize'

require 'active_admin/version'
require 'active_admin/translate/engine'
Expand Down