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_request_quotation => t8('Preset email text for requests (rfq)'),
22 preset_text_purchase_order => t8('Preset email text for purchase orders'),
23 preset_text_periodic_invoices_email_body => t8('Preset email body for periodic invoices'),
24 preset_text_periodic_invoices_email_subject => t8('Preset email subject for periodic invoices'),
28 $main::lxdebug->enter_sub();
30 $main::auth->assert('config');
32 my $form = $main::form;
33 my $locale = $main::locale;
35 $form->get_lists('languages' => 'LANGUAGES');
37 my $translation_list = GenericTranslations->list();
38 my %translations = ();
40 my @types = qw(male female);
42 foreach my $translation (@{ $translation_list }) {
43 $translation->{language_id} ||= 'default';
44 $translations{$translation->{language_id} . '::' . $translation->{translation_type}} = $translation;
47 unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
49 foreach my $language (@{ $form->{LANGUAGES} }) {
50 foreach my $type (@types) {
51 $language->{$type} = { };
52 my $translation = $translations{"$language->{id}::greetings::${type}"} || { };
53 $language->{$type} = $translation->{translation};
57 setup_generictranslations_edit_greetings_action_bar();
59 $form->{title} = $locale->text('Edit greetings');
61 print $form->parse_html_template('generictranslations/edit_greetings');
63 $main::lxdebug->leave_sub();
67 $main::lxdebug->enter_sub();
69 $main::auth->assert('config');
71 my $form = $main::form;
72 my $locale = $main::locale;
74 $form->get_lists('languages' => 'LANGUAGES');
76 unshift @{ $form->{LANGUAGES} }, { };
78 my @types = qw(male female);
80 foreach my $language (@{ $form->{LANGUAGES} }) {
81 foreach my $type (@types) {
82 GenericTranslations->save('translation_type' => "greetings::${type}",
83 'translation_id' => undef,
84 'language_id' => $language->{id},
85 'translation' => $form->{"translation__" . ($language->{id} || 'default') . "__${type}"},);
89 $form->{message} = $locale->text('The greetings have been saved.');
93 $main::lxdebug->leave_sub();
96 sub edit_sepa_strings {
97 $main::lxdebug->enter_sub();
99 $main::auth->assert('config');
101 my $form = $main::form;
102 my $locale = $main::locale;
104 $form->get_lists('languages' => 'LANGUAGES');
106 my $translation_list = GenericTranslations->list(translation_type => 'sepa_remittance_info_pfx');
107 my %translations = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
109 my $translation_list_vc = GenericTranslations->list(translation_type => 'sepa_remittance_vc_no_pfx');
110 my %translations_vc = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list_vc };
112 unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
114 foreach my $language (@{ $form->{LANGUAGES} }) {
115 $language->{translation} = $translations{$language->{id}};
116 $language->{translation_vc} = $translations_vc{$language->{id}};
119 setup_generictranslations_edit_sepa_strings_action_bar();
121 $form->{title} = $locale->text('Edit SEPA strings');
123 print $form->parse_html_template('generictranslations/edit_sepa_strings');
125 $main::lxdebug->leave_sub();
128 sub save_sepa_strings {
129 $main::lxdebug->enter_sub();
131 $main::auth->assert('config');
133 my $form = $main::form;
134 my $locale = $main::locale;
136 $form->get_lists('languages' => 'LANGUAGES');
138 unshift @{ $form->{LANGUAGES} }, { };
140 foreach my $language (@{ $form->{LANGUAGES} }) {
141 GenericTranslations->save('translation_type' => 'sepa_remittance_info_pfx',
142 'translation_id' => undef,
143 'language_id' => $language->{id},
144 'translation' => $form->{"translation__" . ($language->{id} || 'default')},);
145 GenericTranslations->save('translation_type' => 'sepa_remittance_vc_no_pfx',
146 'translation_id' => undef,
147 'language_id' => $language->{id},
148 'translation' => $form->{"translation__" . ($language->{id} || 'default') . "__vc" },);
151 $form->{message} = $locale->text('The SEPA strings have been saved.');
155 $main::lxdebug->leave_sub();
157 sub edit_email_strings {
158 $main::lxdebug->enter_sub();
160 $main::auth->assert('config');
162 my $form = $main::form;
163 my $locale = $main::locale;
165 $form->get_lists('languages' => 'LANGUAGES');
166 unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
168 my (%translations, $translation_list);
169 foreach (keys %mail_strings) {
170 $translation_list = GenericTranslations->list(translation_type => $_);
171 %translations = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
173 foreach my $language (@{ $form->{LANGUAGES} }) {
174 $language->{$_} = $translations{$language->{id}};
177 setup_generictranslations_edit_email_strings_action_bar();
179 $form->{title} = $locale->text('Edit preset email strings');
181 print $form->parse_html_template('generictranslations/edit_email_strings',{ 'MAIL_STRINGS' => \%mail_strings });
183 $main::lxdebug->leave_sub();
186 sub save_email_strings {
187 $main::lxdebug->enter_sub();
189 $main::auth->assert('config');
191 my $form = $main::form;
192 my $locale = $main::locale;
194 $form->get_lists('languages' => 'LANGUAGES');
196 unshift @{ $form->{LANGUAGES} }, { };
197 foreach my $language (@{ $form->{LANGUAGES} }) {
198 foreach (keys %mail_strings) {
199 GenericTranslations->save('translation_type' => $_,
200 'translation_id' => undef,
201 'language_id' => $language->{id},
202 'translation' => $form->{"translation__" . ($language->{id} || 'default') . "__" . $_},
206 $form->{message} = $locale->text('The Mail strings have been saved.');
208 edit_email_strings();
210 $main::lxdebug->leave_sub();
213 sub setup_generictranslations_edit_greetings_action_bar {
216 for my $bar ($::request->layout->get('actionbar')) {
220 submit => [ '#form', { action => "save_greetings" } ],
221 accesskey => 'enter',
227 sub setup_generictranslations_edit_sepa_strings_action_bar {
230 for my $bar ($::request->layout->get('actionbar')) {
234 submit => [ '#form', { action => "save_sepa_strings" } ],
235 accesskey => 'enter',
240 sub setup_generictranslations_edit_email_strings_action_bar {
243 for my $bar ($::request->layout->get('actionbar')) {
247 submit => [ '#form', { action => "save_email_strings" } ],
248 accesskey => 'enter',