Change rule translation interface to display english name and populate empty translations (#35170)
This commit is contained in:
		@@ -17,6 +17,9 @@ module Admin
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def edit
 | 
					    def edit
 | 
				
			||||||
      authorize @rule, :update?
 | 
					      authorize @rule, :update?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      missing_languages = RuleTranslation.languages - @rule.translations.pluck(:language)
 | 
				
			||||||
 | 
					      missing_languages.each { |lang| @rule.translations.build(language: lang) }
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def create
 | 
					    def create
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@ class Rule < ApplicationRecord
 | 
				
			|||||||
  self.discard_column = :deleted_at
 | 
					  self.discard_column = :deleted_at
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  has_many :translations, inverse_of: :rule, class_name: 'RuleTranslation', dependent: :destroy
 | 
					  has_many :translations, inverse_of: :rule, class_name: 'RuleTranslation', dependent: :destroy
 | 
				
			||||||
  accepts_nested_attributes_for :translations, reject_if: :all_blank, allow_destroy: true
 | 
					  accepts_nested_attributes_for :translations, reject_if: ->(attributes) { attributes['text'].blank? }, allow_destroy: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  validates :text, presence: true, length: { maximum: TEXT_SIZE_LIMIT }
 | 
					  validates :text, presence: true, length: { maximum: TEXT_SIZE_LIMIT }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,4 +20,8 @@ class RuleTranslation < ApplicationRecord
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  scope :for_locale, ->(locale) { where(language: I18n::Locale::Tag.tag(locale).to_a.first) }
 | 
					  scope :for_locale, ->(locale) { where(language: I18n::Locale::Tag.tag(locale).to_a.first) }
 | 
				
			||||||
  scope :by_language_length, -> { order(Arel.sql('LENGTH(LANGUAGE)').desc) }
 | 
					  scope :by_language_length, -> { order(Arel.sql('LENGTH(LANGUAGE)').desc) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def self.languages
 | 
				
			||||||
 | 
					    RuleTranslation.joins(:rule).merge(Rule.kept).select(:language).distinct.pluck(:language).sort
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@
 | 
				
			|||||||
        = f.input :language,
 | 
					        = f.input :language,
 | 
				
			||||||
                  collection: ui_languages,
 | 
					                  collection: ui_languages,
 | 
				
			||||||
                  include_blank: false,
 | 
					                  include_blank: false,
 | 
				
			||||||
                  label_method: ->(locale) { native_locale_name(locale) }
 | 
					                  label_method: ->(locale) { "#{native_locale_name(locale)} (#{standard_locale_name(locale)})" }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      .fields-row__column.fields-group
 | 
					      .fields-row__column.fields-group
 | 
				
			||||||
        = f.hidden_field :id if f.object&.persisted? # Required so Rails doesn't put the field outside of the <tr/>
 | 
					        = f.hidden_field :id if f.object&.persisted? # Required so Rails doesn't put the field outside of the <tr/>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user