1+ # frozen_string_literal: true
12
23module BetterTogether
4+ # Helps with rendering content for translatable fields
35 module TranslatableFieldsHelper
46 # Helper to render a translation tab button
5- def translation_tab_button ( attribute :, locale :, temp_id :, model :)
7+ def translation_tab_button ( attribute :, locale :, temp_id :, model :) # rubocop:todo Metrics/MethodLength
68 locale_attribute = "#{ attribute } _#{ locale } "
79 unique_locale_attribute = "#{ locale_attribute } _#{ temp_id } "
810 translation_present = model . public_send ( locale_attribute ) . present?
9-
11+
1012 content_tag ( :li , class : 'nav-item' , role : 'presentation' ,
11- data : { attribute : attribute , translation_target : 'tab' , locale : locale } ) do
13+ data : { attribute :, translation_target : 'tab' , locale : } ) do
1214 content_tag ( :button ,
1315 id : "#{ unique_locale_attribute } -tab" ,
14- class : [ 'nav-link' , ( 'active' if locale . to_s == I18n . locale . to_s ) ,
16+ class : [ 'nav-link' , ( 'active' if locale . to_s == I18n . locale . to_s ) ,
1517 ( 'text-success' if translation_present ) ] ,
1618 data : { bs_toggle : 'tab' ,
1719 bs_target : "##{ unique_locale_attribute } -field" ,
1820 action : 'click->translation#syncLocaleAcrossFields' ,
19- locale : locale ,
21+ locale :,
2022 translation_target : 'tabButton' } ,
2123 role : 'tab' ,
2224 type : 'button' ,
@@ -33,9 +35,10 @@ def translation_indicator(translation_present)
3335 tag . i ( class : 'fas fa-check-circle ms-2' , aria_hidden : 'true' , title : 'Translation available' ) +
3436 content_tag ( :span , 'Translation available' , class : 'visually-hidden' )
3537 else
36- tag . i ( class : 'fas fa-exclamation-circle text-muted ms-2' , aria_hidden : 'true' , title : 'No translation available' ) +
38+ tag . i ( class : 'fas fa-exclamation-circle text-muted ms-2' , aria_hidden : 'true' ,
39+ title : 'No translation available' ) +
3740 content_tag ( :span , 'No translation available' , class : 'visually-hidden' )
3841 end
3942 end
4043 end
41- end
44+ end
0 commit comments