Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Commit 44001c4

Browse files
committed
Removed auto_sort option from translated_inputs form builder helper
Updated readme
1 parent 1bffdb9 commit 44001c4

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,37 @@ form do |f|
6767
# ...
6868
end
6969

70+
# You can also set locales to show in tabs
71+
# For example we want to show English translation fields without tab, and want to show other languages within tabs
72+
form do |f|
73+
# ...
74+
f.inputs do
75+
Globalize.with_locale(:en) do
76+
f.input :title
77+
end
78+
end
79+
f.inputs "Translated fields" do
80+
f.translated_inputs 'ignored title', switch_locale: false, available_locales: (I18n.available_locales - [:en]) do |t|
81+
t.input :title
82+
t.input :content
83+
end
84+
end
85+
# ...
86+
end
87+
88+
# You can also set default language tab
89+
# For example we want to make Bengali translation tab as default
90+
form do |f|
91+
# ...
92+
f.inputs "Translated fields" do
93+
f.translated_inputs 'ignored title', switch_locale: false, default_locale: :bn do |t|
94+
t.input :title
95+
t.input :content
96+
end
97+
end
98+
# ...
99+
end
100+
70101
```
71102
If `switch_locale` is set, each tab will be rendered switching locale.
72103

lib/active_admin/globalize/form_builder_extension.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ module FormBuilderExtension
55

66
def translated_inputs(name = "Translations", options = {}, &block)
77
options.symbolize_keys!
8-
available_locales = options.fetch(:available_locales, I18n.available_locales.sort)
8+
available_locales = options.fetch(:available_locales, I18n.available_locales)
99
switch_locale = options.fetch(:switch_locale, false)
10-
auto_sort = options.fetch(:auto_sort, true)
1110
default_locale = options.fetch(:default_locale, I18n.default_locale)
1211
template.content_tag(:div, class: "activeadmin-translations") do
1312
template.content_tag(:ul, class: "available-locales") do
14-
(auto_sort ? available_locales.sort : available_locales).map do |locale|
13+
available_locales.map do |locale|
1514
default = 'default' if locale == default_locale
1615
template.content_tag(:li) do
1716
I18n.with_locale(switch_locale ? locale : I18n.locale) do
@@ -20,7 +19,7 @@ def translated_inputs(name = "Translations", options = {}, &block)
2019
end
2120
end.join.html_safe
2221
end <<
23-
(auto_sort ? available_locales.sort : available_locales).map do |locale|
22+
available_locales.map do |locale|
2423
translation = object.translations.find { |t| t.locale.to_s == locale.to_s }
2524
translation ||= object.translations.build(locale: locale)
2625
fields = proc do |form|

0 commit comments

Comments
 (0)