kivitendo/bin/mozilla/generictranslations.pl @ b775c378
98e3e577 | Geoffrey Richardson | use SL::Auth;
|
||
use SL::Form;
|
||||
use SL::GenericTranslations;
|
||||
5781315d | Moritz Bunkus | use SL::Locale::String qw(t8);
|
||
98e3e577 | Geoffrey Richardson | |||
429203bf | Sven Schöling | use strict;
|
||
ee056f23 | Jan Büren | # convention:
|
||
# preset_text_$formname will generate a input textarea
|
||||
# and will be preset in $form email dialog if the form name matches
|
||||
my %mail_strings = (
|
||||
ee8cd38f | Jan Büren | salutation_male => t8('Salutation male'),
|
||
salutation_female => t8('Salutation female'),
|
||||
salutation_general => t8('Salutation general'),
|
||||
salutation_punctuation_mark => t8('Salutation punctuation mark'),
|
||||
preset_text_sales_quotation => t8('Preset email text for sales quotations'),
|
||||
preset_text_sales_order => t8('Preset email text for sales orders'),
|
||||
preset_text_sales_delivery_order => t8('Preset email text for sales delivery orders'),
|
||||
preset_text_invoice => t8('Preset email text for sales invoices'),
|
||||
d9ff130d | Moritz Bunkus | preset_text_invoice_direct_debit => t8('Preset email text for sales invoices with direct debit'),
|
||
ee8cd38f | Jan Büren | preset_text_request_quotation => t8('Preset email text for requests (rfq)'),
|
||
preset_text_purchase_order => t8('Preset email text for purchase orders'),
|
||||
preset_text_periodic_invoices_email_body => t8('Preset email body for periodic invoices'),
|
||||
preset_text_periodic_invoices_email_subject => t8('Preset email subject for periodic invoices'),
|
||||
ee056f23 | Jan Büren | );
|
||
98e3e577 | Geoffrey Richardson | sub edit_greetings {
|
||
429203bf | Sven Schöling | $main::lxdebug->enter_sub();
|
||
$main::auth->assert('config');
|
||||
98e3e577 | Geoffrey Richardson | |||
429203bf | Sven Schöling | my $form = $main::form;
|
||
my $locale = $main::locale;
|
||||
98e3e577 | Geoffrey Richardson | |||
$form->get_lists('languages' => 'LANGUAGES');
|
||||
my $translation_list = GenericTranslations->list();
|
||||
my %translations = ();
|
||||
my @types = qw(male female);
|
||||
foreach my $translation (@{ $translation_list }) {
|
||||
$translation->{language_id} ||= 'default';
|
||||
$translations{$translation->{language_id} . '::' . $translation->{translation_type}} = $translation;
|
||||
}
|
||||
unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
|
||||
foreach my $language (@{ $form->{LANGUAGES} }) {
|
||||
foreach my $type (@types) {
|
||||
$language->{$type} = { };
|
||||
my $translation = $translations{"$language->{id}::greetings::${type}"} || { };
|
||||
$language->{$type} = $translation->{translation};
|
||||
}
|
||||
}
|
||||
5781315d | Moritz Bunkus | setup_generictranslations_edit_greetings_action_bar();
|
||
98e3e577 | Geoffrey Richardson | $form->{title} = $locale->text('Edit greetings');
|
||
$form->header();
|
||||
print $form->parse_html_template('generictranslations/edit_greetings');
|
||||
429203bf | Sven Schöling | $main::lxdebug->leave_sub();
|
||
98e3e577 | Geoffrey Richardson | }
|
||
sub save_greetings {
|
||||
429203bf | Sven Schöling | $main::lxdebug->enter_sub();
|
||
$main::auth->assert('config');
|
||||
98e3e577 | Geoffrey Richardson | |||
429203bf | Sven Schöling | my $form = $main::form;
|
||
my $locale = $main::locale;
|
||||
98e3e577 | Geoffrey Richardson | |||
$form->get_lists('languages' => 'LANGUAGES');
|
||||
unshift @{ $form->{LANGUAGES} }, { };
|
||||
my @types = qw(male female);
|
||||
foreach my $language (@{ $form->{LANGUAGES} }) {
|
||||
foreach my $type (@types) {
|
||||
GenericTranslations->save('translation_type' => "greetings::${type}",
|
||||
'translation_id' => undef,
|
||||
'language_id' => $language->{id},
|
||||
'translation' => $form->{"translation__" . ($language->{id} || 'default') . "__${type}"},);
|
||||
}
|
||||
}
|
||||
$form->{message} = $locale->text('The greetings have been saved.');
|
||||
edit_greetings();
|
||||
429203bf | Sven Schöling | $main::lxdebug->leave_sub();
|
||
98e3e577 | Geoffrey Richardson | }
|
||
36c9b4e8 | Moritz Bunkus | sub edit_sepa_strings {
|
||
$main::lxdebug->enter_sub();
|
||||
$main::auth->assert('config');
|
||||
my $form = $main::form;
|
||||
my $locale = $main::locale;
|
||||
$form->get_lists('languages' => 'LANGUAGES');
|
||||
my $translation_list = GenericTranslations->list(translation_type => 'sepa_remittance_info_pfx');
|
||||
my %translations = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
|
||||
fc4e6199 | Jan Büren | my $translation_list_vc = GenericTranslations->list(translation_type => 'sepa_remittance_vc_no_pfx');
|
||
my %translations_vc = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list_vc };
|
||||
36c9b4e8 | Moritz Bunkus | unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
|
||
foreach my $language (@{ $form->{LANGUAGES} }) {
|
||||
fc4e6199 | Jan Büren | $language->{translation} = $translations{$language->{id}};
|
||
$language->{translation_vc} = $translations_vc{$language->{id}};
|
||||
36c9b4e8 | Moritz Bunkus | }
|
||
97c075f9 | Moritz Bunkus | setup_generictranslations_edit_sepa_strings_action_bar();
|
||
36c9b4e8 | Moritz Bunkus | $form->{title} = $locale->text('Edit SEPA strings');
|
||
$form->header();
|
||||
print $form->parse_html_template('generictranslations/edit_sepa_strings');
|
||||
$main::lxdebug->leave_sub();
|
||||
}
|
||||
sub save_sepa_strings {
|
||||
$main::lxdebug->enter_sub();
|
||||
$main::auth->assert('config');
|
||||
my $form = $main::form;
|
||||
my $locale = $main::locale;
|
||||
$form->get_lists('languages' => 'LANGUAGES');
|
||||
unshift @{ $form->{LANGUAGES} }, { };
|
||||
foreach my $language (@{ $form->{LANGUAGES} }) {
|
||||
GenericTranslations->save('translation_type' => 'sepa_remittance_info_pfx',
|
||||
'translation_id' => undef,
|
||||
'language_id' => $language->{id},
|
||||
'translation' => $form->{"translation__" . ($language->{id} || 'default')},);
|
||||
fc4e6199 | Jan Büren | GenericTranslations->save('translation_type' => 'sepa_remittance_vc_no_pfx',
|
||
'translation_id' => undef,
|
||||
'language_id' => $language->{id},
|
||||
'translation' => $form->{"translation__" . ($language->{id} || 'default') . "__vc" },);
|
||||
36c9b4e8 | Moritz Bunkus | }
|
||
$form->{message} = $locale->text('The SEPA strings have been saved.');
|
||||
edit_sepa_strings();
|
||||
$main::lxdebug->leave_sub();
|
||||
}
|
||||
ee056f23 | Jan Büren | sub edit_email_strings {
|
||
$main::lxdebug->enter_sub();
|
||||
$main::auth->assert('config');
|
||||
my $form = $main::form;
|
||||
my $locale = $main::locale;
|
||||
$form->get_lists('languages' => 'LANGUAGES');
|
||||
unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
|
||||
my (%translations, $translation_list);
|
||||
foreach (keys %mail_strings) {
|
||||
$translation_list = GenericTranslations->list(translation_type => $_);
|
||||
%translations = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
|
||||
foreach my $language (@{ $form->{LANGUAGES} }) {
|
||||
$language->{$_} = $translations{$language->{id}};
|
||||
}
|
||||
}
|
||||
setup_generictranslations_edit_email_strings_action_bar();
|
||||
$form->{title} = $locale->text('Edit preset email strings');
|
||||
e4d533e6 | Moritz Bunkus | $::request->{layout}->use_javascript(map { "${_}.js" } qw(ckeditor/ckeditor ckeditor/adapters/jquery));
|
||
ee056f23 | Jan Büren | $form->header();
|
||
print $form->parse_html_template('generictranslations/edit_email_strings',{ 'MAIL_STRINGS' => \%mail_strings });
|
||||
$main::lxdebug->leave_sub();
|
||||
}
|
||||
sub save_email_strings {
|
||||
$main::lxdebug->enter_sub();
|
||||
$main::auth->assert('config');
|
||||
my $form = $main::form;
|
||||
my $locale = $main::locale;
|
||||
$form->get_lists('languages' => 'LANGUAGES');
|
||||
unshift @{ $form->{LANGUAGES} }, { };
|
||||
foreach my $language (@{ $form->{LANGUAGES} }) {
|
||||
foreach (keys %mail_strings) {
|
||||
GenericTranslations->save('translation_type' => $_,
|
||||
'translation_id' => undef,
|
||||
'language_id' => $language->{id},
|
||||
'translation' => $form->{"translation__" . ($language->{id} || 'default') . "__" . $_},
|
||||
);
|
||||
}
|
||||
}
|
||||
$form->{message} = $locale->text('The Mail strings have been saved.');
|
||||
edit_email_strings();
|
||||
$main::lxdebug->leave_sub();
|
||||
}
|
||||
36c9b4e8 | Moritz Bunkus | |||
e5f53eb5 | Moritz Bunkus | sub edit_zugferd_notes {
|
||
$::auth->assert('config');
|
||||
$::form->get_lists('languages' => 'LANGUAGES');
|
||||
my $translation_list = GenericTranslations->list(translation_type => 'ZUGFeRD/notes');
|
||||
my %translations = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
|
||||
unshift @{ $::form->{LANGUAGES} }, { 'id' => 'default', };
|
||||
foreach my $language (@{ $::form->{LANGUAGES} }) {
|
||||
$language->{translation} = $translations{$language->{id}};
|
||||
}
|
||||
setup_generictranslations_edit_zugferd_notes_action_bar();
|
||||
ba40069b | Moritz Bunkus | $::form->{title} = $::locale->text('Edit Factur-X/ZUGFeRD notes');
|
||
e5f53eb5 | Moritz Bunkus | $::form->header;
|
||
print $::form->parse_html_template('generictranslations/edit_zugferd_notes');
|
||||
}
|
||||
sub save_zugferd_notes {
|
||||
$::auth->assert('config');
|
||||
$::form->get_lists('languages' => 'LANGUAGES');
|
||||
unshift @{ $::form->{LANGUAGES} }, { };
|
||||
foreach my $language (@{ $::form->{LANGUAGES} }) {
|
||||
GenericTranslations->save(
|
||||
translation_type => 'ZUGFeRD/notes',
|
||||
translation_id => undef,
|
||||
language_id => $language->{id},
|
||||
translation => $::form->{"translation__" . ($language->{id} || 'default')},
|
||||
);
|
||||
}
|
||||
ba40069b | Moritz Bunkus | $::form->{message} = $::locale->text('The Factur-X/ZUGFeRD notes have been saved.');
|
||
e5f53eb5 | Moritz Bunkus | |||
edit_zugferd_notes();
|
||||
}
|
||||
5781315d | Moritz Bunkus | sub setup_generictranslations_edit_greetings_action_bar {
|
||
my %params = @_;
|
||||
for my $bar ($::request->layout->get('actionbar')) {
|
||||
$bar->add(
|
||||
action => [
|
||||
t8('Save'),
|
||||
submit => [ '#form', { action => "save_greetings" } ],
|
||||
accesskey => 'enter',
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
97c075f9 | Moritz Bunkus | sub setup_generictranslations_edit_sepa_strings_action_bar {
|
||
my %params = @_;
|
||||
for my $bar ($::request->layout->get('actionbar')) {
|
||||
$bar->add(
|
||||
action => [
|
||||
t8('Save'),
|
||||
submit => [ '#form', { action => "save_sepa_strings" } ],
|
||||
accesskey => 'enter',
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
e5f53eb5 | Moritz Bunkus | |||
ee056f23 | Jan Büren | sub setup_generictranslations_edit_email_strings_action_bar {
|
||
my %params = @_;
|
||||
for my $bar ($::request->layout->get('actionbar')) {
|
||||
$bar->add(
|
||||
action => [
|
||||
t8('Save'),
|
||||
submit => [ '#form', { action => "save_email_strings" } ],
|
||||
accesskey => 'enter',
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
97c075f9 | Moritz Bunkus | |||
e5f53eb5 | Moritz Bunkus | sub setup_generictranslations_edit_zugferd_notes_action_bar {
|
||
my %params = @_;
|
||||
for my $bar ($::request->layout->get('actionbar')) {
|
||||
$bar->add(
|
||||
action => [
|
||||
t8('Save'),
|
||||
submit => [ '#form', { action => "save_zugferd_notes" } ],
|
||||
accesskey => 'enter',
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
98e3e577 | Geoffrey Richardson | 1;
|