@@ -3,12 +3,16 @@ module Globalize3
3
3
module FormBuilderExtension
4
4
extend ActiveSupport ::Concern
5
5
6
- def translated_inputs ( name = "Translations" , &block )
6
+ def translated_inputs ( name = "Translations" , options = { } , &block )
7
+ options . symbolize_keys!
8
+ switch_locale = options . fetch ( :switch_locale , false )
7
9
form_buffers . last << template . content_tag ( :div , class : "activeadmin-translations" ) do
8
10
template . content_tag ( :ul , class : "available-locales" ) do
9
11
I18n . available_locales . map do |locale |
10
12
template . content_tag ( :li ) do
11
- template . content_tag ( :a , I18n . t ( :"active_admin.globalize3.language.#{ locale } " ) , href :".locale-#{ locale } " )
13
+ I18n . with_locale ( switch_locale ? locale : I18n . locale ) do
14
+ template . content_tag ( :a , I18n . t ( :"active_admin.globalize3.language.#{ locale } " ) , href :".locale-#{ locale } " )
15
+ end
12
16
end
13
17
end . join . html_safe
14
18
end <<
@@ -18,7 +22,9 @@ def translated_inputs(name = "Translations", &block)
18
22
fields = proc do |form |
19
23
form . input ( :locale , as : :hidden )
20
24
form . input ( :id , as : :hidden )
21
- block . call ( form )
25
+ I18n . with_locale ( switch_locale ? locale : I18n . locale ) do
26
+ block . call ( form )
27
+ end
22
28
end
23
29
inputs_for_nested_attributes (
24
30
for : [ :translations , translation ] ,
0 commit comments