[WiP] Add admin interface to edit rule translations

This commit is contained in:
Claire 2025-04-18 15:37:23 +02:00
parent 7d58c23c0e
commit 7f0b5478e6
5 changed files with 54 additions and 1 deletions

View File

@ -54,7 +54,7 @@ module Admin
def resource_params def resource_params
params params
.expect(rule: [:text, :hint, :priority]) .expect(rule: [:text, :hint, :priority, translations_attributes: [[:id, :language, :text, :hint, :_destroy]]])
end end
end end
end end

View File

@ -20,6 +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
validates :text, presence: true, length: { maximum: TEXT_SIZE_LIMIT } validates :text, presence: true, length: { maximum: TEXT_SIZE_LIMIT }

View File

@ -0,0 +1,27 @@
%tr.nested-fields
%td
.fields-row
.fields-row__column.fields-group
= f.input :language,
collection: ui_languages,
include_blank: false,
label_method: ->(locale) { native_locale_name(locale) }
.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/>
= link_to_remove_association(f, class: 'table-action-link') do
= safe_join([material_symbol('close'), t('filters.index.delete')])
.fields-group
= f.input :text,
label: I18n.t('simple_form.labels.rule.text'),
hint: I18n.t('simple_form.hints.rule.text'),
input_html: { lang: f.object&.language },
wrapper: :with_block_label
.fields-group
= f.input :hint,
label: I18n.t('simple_form.labels.rule.hint'),
hint: I18n.t('simple_form.hints.rule.hint'),
input_html: { lang: f.object&.language },
wrapper: :with_block_label

View File

@ -6,5 +6,26 @@
= render form = render form
%hr.spacer/
%h4= t('admin.rules.translations')
%p.hint= t('admin.rules.translations_explanation')
.table-wrapper
%table.table.keywords-table
%thead
%tr
%th= t('admin.rules.translation')
%th
%tbody
= form.simple_fields_for :translations do |translation|
= render 'translation_fields', f: translation
%tfoot
%tr
%td{ colspan: 3 }
= link_to_add_association form, :translations, class: 'table-action-link', partial: 'translation_fields', 'data-association-insertion-node': '.keywords-table tbody', 'data-association-insertion-method': 'append' do
= safe_join([material_symbol('add'), t('admin.rules.add_translation')])
.actions .actions
= form.button :button, t('generic.save_changes'), type: :submit = form.button :button, t('generic.save_changes'), type: :submit

View File

@ -786,11 +786,15 @@ en:
title: Roles title: Roles
rules: rules:
add_new: Add rule add_new: Add rule
add_translation: Add translation
delete: Delete delete: Delete
description_html: While most claim to have read and agree to the terms of service, usually people do not read through until after a problem arises. <strong>Make it easier to see your server's rules at a glance by providing them in a flat bullet point list.</strong> Try to keep individual rules short and simple, but try not to split them up into many separate items either. description_html: While most claim to have read and agree to the terms of service, usually people do not read through until after a problem arises. <strong>Make it easier to see your server's rules at a glance by providing them in a flat bullet point list.</strong> Try to keep individual rules short and simple, but try not to split them up into many separate items either.
edit: Edit rule edit: Edit rule
empty: No server rules have been defined yet. empty: No server rules have been defined yet.
title: Server rules title: Server rules
translation: Translation
translations: Translations
translations_explanation: You can optionally add translations for the rules. The default value will be shown if no translated version is available. Please always ensure any provided translation is in sync with the default value.
settings: settings:
about: about:
manage_rules: Manage server rules manage_rules: Manage server rules