diff --git a/app/helpers/translatable_form_helper.rb b/app/helpers/translatable_form_helper.rb index 304340ed3..bedd0fe19 100644 --- a/app/helpers/translatable_form_helper.rb +++ b/app/helpers/translatable_form_helper.rb @@ -11,6 +11,19 @@ module TranslatableFormHelper yield(f) end end + + def merge_translatable_field_options(options, locale) + options.merge( + class: (options.fetch(:class, "") + " js-globalize-attribute"), + style: display_translation?(locale), + data: options.fetch(:data, {}).merge(locale: locale), + label_options: { + class: (options.fetch(:class, "") + " js-globalize-attribute"), + style: display_translation?(locale), + data: (options.dig(:label_options, :data) || {}) .merge(locale: locale) + } + ) + end end class TranslatableFormBuilder < FoundationRailsHelper::FormBuilder @@ -28,17 +41,7 @@ class TranslatableFormBuilder < FoundationRailsHelper::FormBuilder @template.capture do @object.globalize_locales.each do |locale| Globalize.with_locale(locale) do - final_options = options.merge( - class: (options.fetch(:class, "") + " js-globalize-attribute"), - style: @template.display_translation?(locale), - data: options.fetch(:data, {}).merge(locale: locale), - label_options: { - class: (options.fetch(:class, "") + " js-globalize-attribute"), - style: @template.display_translation?(locale), - data: (options.dig(:label_options, :data) || {}) .merge(locale: locale) - } - ) - + final_options = @template.merge_translatable_field_options(options, locale) @template.concat send(field_type, "#{method}_#{locale}", final_options) end end diff --git a/app/views/admin/site_customization/information_texts/_form_field.html.erb b/app/views/admin/site_customization/information_texts/_form_field.html.erb index 54945dfb6..11dc02b20 100644 --- a/app/views/admin/site_customization/information_texts/_form_field.html.erb +++ b/app/views/admin/site_customization/information_texts/_form_field.html.erb @@ -11,9 +11,5 @@ <%= text_area_tag "contents[content_#{content.key}]values[value_#{locale}]", i18n_content_translation || t(content.key, locale: locale), - { rows: 5, - class: "js-globalize-attribute", - style: display_translation?(locale), - data: { locale: locale } - } %> + merge_translatable_field_options({rows: 5}, locale) %> <% end %>