5d945566f486cf1021de294627a35a0b932edacf
[kivitendo-erp.git] / bin / mozilla / generictranslations.pl
1 use SL::Auth;
2 use SL::Form;
3 use SL::GenericTranslations;
4 use SL::Locale::String qw(t8);
5
6 use strict;
7
8 sub edit_greetings {
9   $main::lxdebug->enter_sub();
10
11   $main::auth->assert('config');
12
13   my $form     = $main::form;
14   my $locale   = $main::locale;
15
16   $form->get_lists('languages' => 'LANGUAGES');
17
18   my $translation_list = GenericTranslations->list();
19   my %translations     = ();
20
21   my @types            = qw(male female);
22
23   foreach my $translation (@{ $translation_list }) {
24     $translation->{language_id}                                                          ||= 'default';
25     $translations{$translation->{language_id} . '::' . $translation->{translation_type}}   = $translation;
26   }
27
28   unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
29
30   foreach my $language (@{ $form->{LANGUAGES} }) {
31     foreach my $type (@types) {
32       $language->{$type} = { };
33       my $translation    = $translations{"$language->{id}::greetings::${type}"} || { };
34       $language->{$type} = $translation->{translation};
35     }
36   }
37
38   setup_generictranslations_edit_greetings_action_bar();
39
40   $form->{title} = $locale->text('Edit greetings');
41   $form->header();
42   print $form->parse_html_template('generictranslations/edit_greetings');
43
44   $main::lxdebug->leave_sub();
45 }
46
47 sub save_greetings {
48   $main::lxdebug->enter_sub();
49
50   $main::auth->assert('config');
51
52   my $form     = $main::form;
53   my $locale   = $main::locale;
54
55   $form->get_lists('languages' => 'LANGUAGES');
56
57   unshift @{ $form->{LANGUAGES} }, { };
58
59   my @types  = qw(male female);
60
61   foreach my $language (@{ $form->{LANGUAGES} }) {
62     foreach my $type (@types) {
63       GenericTranslations->save('translation_type' => "greetings::${type}",
64                                 'translation_id'   => undef,
65                                 'language_id'      => $language->{id},
66                                 'translation'      => $form->{"translation__" . ($language->{id} || 'default') . "__${type}"},);
67     }
68   }
69
70   $form->{message} = $locale->text('The greetings have been saved.');
71
72   edit_greetings();
73
74   $main::lxdebug->leave_sub();
75 }
76
77 sub edit_sepa_strings {
78   $main::lxdebug->enter_sub();
79
80   $main::auth->assert('config');
81
82   my $form     = $main::form;
83   my $locale   = $main::locale;
84
85   $form->get_lists('languages' => 'LANGUAGES');
86
87   my $translation_list = GenericTranslations->list(translation_type => 'sepa_remittance_info_pfx');
88   my %translations     = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
89
90   my $translation_list_vc = GenericTranslations->list(translation_type => 'sepa_remittance_vc_no_pfx');
91   my %translations_vc     =  map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list_vc };
92
93   unshift @{ $form->{LANGUAGES} }, { 'id' => 'default', };
94
95   foreach my $language (@{ $form->{LANGUAGES} }) {
96     $language->{translation}    = $translations{$language->{id}};
97     $language->{translation_vc} = $translations_vc{$language->{id}};
98   }
99
100   setup_generictranslations_edit_sepa_strings_action_bar();
101
102   $form->{title} = $locale->text('Edit SEPA strings');
103   $form->header();
104   print $form->parse_html_template('generictranslations/edit_sepa_strings');
105
106   $main::lxdebug->leave_sub();
107 }
108
109 sub save_sepa_strings {
110   $main::lxdebug->enter_sub();
111
112   $main::auth->assert('config');
113
114   my $form     = $main::form;
115   my $locale   = $main::locale;
116
117   $form->get_lists('languages' => 'LANGUAGES');
118
119   unshift @{ $form->{LANGUAGES} }, { };
120
121   foreach my $language (@{ $form->{LANGUAGES} }) {
122     GenericTranslations->save('translation_type' => 'sepa_remittance_info_pfx',
123                               'translation_id'   => undef,
124                               'language_id'      => $language->{id},
125                               'translation'      => $form->{"translation__" . ($language->{id} || 'default')},);
126     GenericTranslations->save('translation_type' => 'sepa_remittance_vc_no_pfx',
127                               'translation_id'   => undef,
128                               'language_id'      => $language->{id},
129                               'translation'      => $form->{"translation__" . ($language->{id} || 'default') . "__vc" },);
130   }
131
132   $form->{message} = $locale->text('The SEPA strings have been saved.');
133
134   edit_sepa_strings();
135
136   $main::lxdebug->leave_sub();
137 }
138
139 sub setup_generictranslations_edit_greetings_action_bar {
140   my %params = @_;
141
142   for my $bar ($::request->layout->get('actionbar')) {
143     $bar->add(
144       action => [
145         t8('Save'),
146         submit    => [ '#form', { action => "save_greetings" } ],
147         accesskey => 'enter',
148       ],
149     );
150   }
151 }
152
153 sub setup_generictranslations_edit_sepa_strings_action_bar {
154   my %params = @_;
155
156   for my $bar ($::request->layout->get('actionbar')) {
157     $bar->add(
158       action => [
159         t8('Save'),
160         submit    => [ '#form', { action => "save_sepa_strings" } ],
161         accesskey => 'enter',
162       ],
163     );
164   }
165 }
166
167 1;