3 use SL::GenericTranslations;
4 use SL::Locale::String qw(t8);
9 # preset_text_$formname will generate a input textarea
10 # and will be preset in $form email dialog if the form name matches
13 salutation_male => t8('Salutation male'),
14 salutation_female => t8('Salutation female'),
15 salutation_general => t8('Salutation general'),
16 salutation_punctuation_mark => t8('Salutation punctuation mark'),
17 preset_text_sales_quotation => t8('Preset email text for sales quotations'),
18 preset_text_sales_order => t8('Preset email text for sales orders'),
19 preset_text_sales_delivery_order => t8('Preset email text for sales delivery orders'),
20 preset_text_invoice => t8('Preset email text for sales invoices'),
21 preset_text_invoice_direct_debit => t8('Preset email text for sales invoices with direct debit'),
22 preset_text_request_quotation => t8('Preset email text for requests (rfq)'),
23 preset_text_purchase_order => t8('Preset email text for purchase orders'),
24 preset_text_periodic_invoices_email_body => t8('Preset email body for periodic invoices'),
25 preset_text_periodic_invoices_email_subject => t8('Preset email subject for periodic invoices'),
29 $main::lxdebug->enter_sub();
31 $main::auth->assert('config');
33 my $form = $main::form;
34 my $locale = $main::locale;
36 $form->get_lists('languages' => 'LANGUAGES');
38 my $translation_list = GenericTranslations->list();
39 my %translations = ();
41 my @types = qw(male female);
43 foreach my $translation (@{ $translation_list }) {
44 $translation->{language_id} ||= 'default';
45 $translations{$translation->{language_id} . '::' . $translation->{translation_type}} = $translation;
48 unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
50 foreach my $language (@{ $form->{LANGUAGES} }) {
51 foreach my $type (@types) {
52 $language->{$type} = { };
53 my $translation = $translations{"$language->{id}::greetings::${type}"} || { };
54 $language->{$type} = $translation->{translation};
58 setup_generictranslations_edit_greetings_action_bar();
60 $form->{title} = $locale->text('Edit greetings');
62 print $form->parse_html_template('generictranslations/edit_greetings');
64 $main::lxdebug->leave_sub();
68 $main::lxdebug->enter_sub();
70 $main::auth->assert('config');
72 my $form = $main::form;
73 my $locale = $main::locale;
75 $form->get_lists('languages' => 'LANGUAGES');
77 unshift @{ $form->{LANGUAGES} }, { };
79 my @types = qw(male female);
81 foreach my $language (@{ $form->{LANGUAGES} }) {
82 foreach my $type (@types) {
83 GenericTranslations->save('translation_type' => "greetings::${type}",
84 'translation_id' => undef,
85 'language_id' => $language->{id},
86 'translation' => $form->{"translation__" . ($language->{id} || 'default') . "__${type}"},);
90 $form->{message} = $locale->text('The greetings have been saved.');
94 $main::lxdebug->leave_sub();
97 sub edit_sepa_strings {
98 $main::lxdebug->enter_sub();
100 $main::auth->assert('config');
102 my $form = $main::form;
103 my $locale = $main::locale;
105 $form->get_lists('languages' => 'LANGUAGES');
107 my $translation_list = GenericTranslations->list(translation_type => 'sepa_remittance_info_pfx');
108 my %translations = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
110 my $translation_list_vc = GenericTranslations->list(translation_type => 'sepa_remittance_vc_no_pfx');
111 my %translations_vc = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list_vc };
113 unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
115 foreach my $language (@{ $form->{LANGUAGES} }) {
116 $language->{translation} = $translations{$language->{id}};
117 $language->{translation_vc} = $translations_vc{$language->{id}};
120 setup_generictranslations_edit_sepa_strings_action_bar();
122 $form->{title} = $locale->text('Edit SEPA strings');
124 print $form->parse_html_template('generictranslations/edit_sepa_strings');
126 $main::lxdebug->leave_sub();
129 sub save_sepa_strings {
130 $main::lxdebug->enter_sub();
132 $main::auth->assert('config');
134 my $form = $main::form;
135 my $locale = $main::locale;
137 $form->get_lists('languages' => 'LANGUAGES');
139 unshift @{ $form->{LANGUAGES} }, { };
141 foreach my $language (@{ $form->{LANGUAGES} }) {
142 GenericTranslations->save('translation_type' => 'sepa_remittance_info_pfx',
143 'translation_id' => undef,
144 'language_id' => $language->{id},
145 'translation' => $form->{"translation__" . ($language->{id} || 'default')},);
146 GenericTranslations->save('translation_type' => 'sepa_remittance_vc_no_pfx',
147 'translation_id' => undef,
148 'language_id' => $language->{id},
149 'translation' => $form->{"translation__" . ($language->{id} || 'default') . "__vc" },);
152 $form->{message} = $locale->text('The SEPA strings have been saved.');
156 $main::lxdebug->leave_sub();
158 sub edit_email_strings {
159 $main::lxdebug->enter_sub();
161 $main::auth->assert('config');
163 my $form = $main::form;
164 my $locale = $main::locale;
166 $form->get_lists('languages' => 'LANGUAGES');
167 unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
169 my (%translations, $translation_list);
170 foreach (keys %mail_strings) {
171 $translation_list = GenericTranslations->list(translation_type => $_);
172 %translations = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
174 foreach my $language (@{ $form->{LANGUAGES} }) {
175 $language->{$_} = $translations{$language->{id}};
178 setup_generictranslations_edit_email_strings_action_bar();
180 $form->{title} = $locale->text('Edit preset email strings');
182 print $form->parse_html_template('generictranslations/edit_email_strings',{ 'MAIL_STRINGS' => \%mail_strings });
184 $main::lxdebug->leave_sub();
187 sub save_email_strings {
188 $main::lxdebug->enter_sub();
190 $main::auth->assert('config');
192 my $form = $main::form;
193 my $locale = $main::locale;
195 $form->get_lists('languages' => 'LANGUAGES');
197 unshift @{ $form->{LANGUAGES} }, { };
198 foreach my $language (@{ $form->{LANGUAGES} }) {
199 foreach (keys %mail_strings) {
200 GenericTranslations->save('translation_type' => $_,
201 'translation_id' => undef,
202 'language_id' => $language->{id},
203 'translation' => $form->{"translation__" . ($language->{id} || 'default') . "__" . $_},
207 $form->{message} = $locale->text('The Mail strings have been saved.');
209 edit_email_strings();
211 $main::lxdebug->leave_sub();
214 sub edit_zugferd_notes {
215 $::auth->assert('config');
217 $::form->get_lists('languages' => 'LANGUAGES');
219 my $translation_list = GenericTranslations->list(translation_type => 'ZUGFeRD/notes');
220 my %translations = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
222 unshift @{ $::form->{LANGUAGES} }, { 'id' => 'default', };
224 foreach my $language (@{ $::form->{LANGUAGES} }) {
225 $language->{translation} = $translations{$language->{id}};
228 setup_generictranslations_edit_zugferd_notes_action_bar();
230 $::form->{title} = $::locale->text('Edit ZUGFeRD notes');
232 print $::form->parse_html_template('generictranslations/edit_zugferd_notes');
235 sub save_zugferd_notes {
236 $::auth->assert('config');
238 $::form->get_lists('languages' => 'LANGUAGES');
240 unshift @{ $::form->{LANGUAGES} }, { };
242 foreach my $language (@{ $::form->{LANGUAGES} }) {
243 GenericTranslations->save(
244 translation_type => 'ZUGFeRD/notes',
245 translation_id => undef,
246 language_id => $language->{id},
247 translation => $::form->{"translation__" . ($language->{id} || 'default')},
251 $::form->{message} = $::locale->text('The ZUGFeRD notes have been saved.');
253 edit_zugferd_notes();
256 sub setup_generictranslations_edit_greetings_action_bar {
259 for my $bar ($::request->layout->get('actionbar')) {
263 submit => [ '#form', { action => "save_greetings" } ],
264 accesskey => 'enter',
270 sub setup_generictranslations_edit_sepa_strings_action_bar {
273 for my $bar ($::request->layout->get('actionbar')) {
277 submit => [ '#form', { action => "save_sepa_strings" } ],
278 accesskey => 'enter',
284 sub setup_generictranslations_edit_email_strings_action_bar {
287 for my $bar ($::request->layout->get('actionbar')) {
291 submit => [ '#form', { action => "save_email_strings" } ],
292 accesskey => 'enter',
298 sub setup_generictranslations_edit_zugferd_notes_action_bar {
301 for my $bar ($::request->layout->get('actionbar')) {
305 submit => [ '#form', { action => "save_zugferd_notes" } ],
306 accesskey => 'enter',