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

Commit 7be435c

Browse files
committed
Merge pull request unmantained-activeadmin-plugins#10 from raihan2006i/develop
Give freedom to set default_locale and available_locales instead of forcing
2 parents ec73a8b + 44001c4 commit 7be435c

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ 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)
89
switch_locale = options.fetch(:switch_locale, false)
9-
auto_sort = options.fetch(:auto_sort, true)
10+
default_locale = options.fetch(:default_locale, I18n.default_locale)
1011
template.content_tag(:div, class: "activeadmin-translations") do
1112
template.content_tag(:ul, class: "available-locales") do
12-
(auto_sort ? I18n.available_locales.sort : I18n.available_locales).map do |locale|
13-
default = 'default' if locale == I18n.default_locale
13+
available_locales.map do |locale|
14+
default = 'default' if locale == default_locale
1415
template.content_tag(:li) do
1516
I18n.with_locale(switch_locale ? locale : I18n.locale) do
1617
template.content_tag(:a, I18n.t(:"active_admin.globalize.language.#{locale}"), href:".locale-#{locale}", :class => default)
1718
end
1819
end
1920
end.join.html_safe
2021
end <<
21-
(auto_sort ? I18n.available_locales.sort : I18n.available_locales).map do |locale|
22+
available_locales.map do |locale|
2223
translation = object.translations.find { |t| t.locale.to_s == locale.to_s }
2324
translation ||= object.translations.build(locale: locale)
2425
fields = proc do |form|
@@ -42,4 +43,3 @@ module ClassMethods
4243
end
4344
end
4445
end
45-

0 commit comments

Comments
 (0)