Skip to content

Commit

Permalink
Removed auto_sort option from translated_inputs form builder helper
Browse files Browse the repository at this point in the history
Updated readme
  • Loading branch information
raihan2006i committed Aug 7, 2015
1 parent 1bffdb9 commit 44001c4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,37 @@ form do |f|
# ...
end

# You can also set locales to show in tabs
# For example we want to show English translation fields without tab, and want to show other languages within tabs
form do |f|
# ...
f.inputs do
Globalize.with_locale(:en) do
f.input :title
end
end
f.inputs "Translated fields" do
f.translated_inputs 'ignored title', switch_locale: false, available_locales: (I18n.available_locales - [:en]) do |t|
t.input :title
t.input :content
end
end
# ...
end

# You can also set default language tab
# For example we want to make Bengali translation tab as default
form do |f|
# ...
f.inputs "Translated fields" do
f.translated_inputs 'ignored title', switch_locale: false, default_locale: :bn do |t|
t.input :title
t.input :content
end
end
# ...
end

```
If `switch_locale` is set, each tab will be rendered switching locale.

Expand Down
7 changes: 3 additions & 4 deletions lib/active_admin/globalize/form_builder_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ module FormBuilderExtension

def translated_inputs(name = "Translations", options = {}, &block)
options.symbolize_keys!
available_locales = options.fetch(:available_locales, I18n.available_locales.sort)
available_locales = options.fetch(:available_locales, I18n.available_locales)
switch_locale = options.fetch(:switch_locale, false)
auto_sort = options.fetch(:auto_sort, true)
default_locale = options.fetch(:default_locale, I18n.default_locale)
template.content_tag(:div, class: "activeadmin-translations") do
template.content_tag(:ul, class: "available-locales") do
(auto_sort ? available_locales.sort : available_locales).map do |locale|
available_locales.map do |locale|
default = 'default' if locale == default_locale
template.content_tag(:li) do
I18n.with_locale(switch_locale ? locale : I18n.locale) do
Expand All @@ -20,7 +19,7 @@ def translated_inputs(name = "Translations", options = {}, &block)
end
end.join.html_safe
end <<
(auto_sort ? available_locales.sort : available_locales).map do |locale|
available_locales.map do |locale|
translation = object.translations.find { |t| t.locale.to_s == locale.to_s }
translation ||= object.translations.build(locale: locale)
fields = proc do |form|
Expand Down

0 comments on commit 44001c4

Please sign in to comment.