|
Lines 148-180
sub po_filename {
Link Here
|
| 148 |
} |
148 |
} |
| 149 |
|
149 |
|
| 150 |
sub get_trans_text { |
150 |
sub get_trans_text { |
| 151 |
my ($self, $msgid, $default) = @_; |
151 |
my ($self, $msgctxt, $msgid) = @_; |
| 152 |
|
152 |
|
| 153 |
my $po = $self->{po}->{Locale::PO->quote($msgid)}; |
153 |
my $key = ($msgctxt // '') . ";$msgid"; |
|
|
154 |
|
| 155 |
my $po = $self->{po}->{$key}; |
| 154 |
if ($po) { |
156 |
if ($po) { |
| 155 |
my $msgstr = Locale::PO->dequote($po->msgstr); |
157 |
my $msgstr = Locale::PO->dequote($po->msgstr); |
| 156 |
if ($msgstr and length($msgstr) > 0) { |
158 |
|
| 157 |
return $msgstr; |
159 |
return $msgstr || $msgid; |
| 158 |
} |
|
|
| 159 |
} |
160 |
} |
| 160 |
|
161 |
|
| 161 |
return $default; |
162 |
return $msgid; |
| 162 |
} |
163 |
} |
| 163 |
|
164 |
|
| 164 |
sub get_translated_tab_content { |
165 |
sub get_translated_tab_content { |
| 165 |
my ($self, $file, $tab_content) = @_; |
166 |
my ($self, $tab, $tab_content) = @_; |
| 166 |
|
167 |
|
| 167 |
if ( ref($tab_content) eq 'ARRAY' ) { |
168 |
if ( ref($tab_content) eq 'ARRAY' ) { |
| 168 |
return $self->get_translated_prefs($file, $tab_content); |
169 |
return $self->get_translated_prefs($tab, $tab_content); |
| 169 |
} |
170 |
} |
| 170 |
|
171 |
|
| 171 |
my $translated_tab_content = { |
172 |
my $translated_tab_content = { |
| 172 |
map { |
173 |
map { |
| 173 |
my $section = $_; |
174 |
my $section = $_; |
| 174 |
my $sysprefs = $tab_content->{$section}; |
175 |
my $sysprefs = $tab_content->{$section}; |
| 175 |
my $msgid = sprintf('%s %s', $file, $section); |
176 |
my $context = "$tab > $section"; |
| 176 |
|
177 |
|
| 177 |
$self->get_trans_text($msgid, $section) => $self->get_translated_prefs($file, $sysprefs); |
178 |
$self->get_trans_text($tab, $section) => $self->get_translated_prefs($context, $sysprefs); |
| 178 |
} keys %$tab_content |
179 |
} keys %$tab_content |
| 179 |
}; |
180 |
}; |
| 180 |
|
181 |
|
|
Lines 182-188
sub get_translated_tab_content {
Link Here
|
| 182 |
} |
183 |
} |
| 183 |
|
184 |
|
| 184 |
sub get_translated_prefs { |
185 |
sub get_translated_prefs { |
| 185 |
my ($self, $file, $sysprefs) = @_; |
186 |
my ($self, $context, $sysprefs) = @_; |
| 186 |
|
187 |
|
| 187 |
my $translated_prefs = [ |
188 |
my $translated_prefs = [ |
| 188 |
map { |
189 |
map { |
|
Lines 191-197
sub get_translated_prefs {
Link Here
|
| 191 |
|
192 |
|
| 192 |
my $translated_syspref = [ |
193 |
my $translated_syspref = [ |
| 193 |
map { |
194 |
map { |
| 194 |
$self->get_translated_pref($file, $pref_name, $_); |
195 |
$self->get_translated_pref("$context > $pref_name", $_ ); |
| 195 |
} @$_ |
196 |
} @$_ |
| 196 |
]; |
197 |
]; |
| 197 |
|
198 |
|
|
Lines 203-214
sub get_translated_prefs {
Link Here
|
| 203 |
} |
204 |
} |
| 204 |
|
205 |
|
| 205 |
sub get_translated_pref { |
206 |
sub get_translated_pref { |
| 206 |
my ($self, $file, $pref_name, $syspref) = @_; |
207 |
my ($self, $context, $syspref) = @_; |
| 207 |
|
208 |
|
| 208 |
unless (ref($syspref)) { |
209 |
unless (ref($syspref)) { |
| 209 |
$syspref //= ''; |
210 |
return $self->get_trans_text($context, $syspref // ''); |
| 210 |
my $msgid = sprintf('%s#%s# %s', $file, $pref_name, $syspref); |
|
|
| 211 |
return $self->get_trans_text($msgid, $syspref); |
| 212 |
} |
211 |
} |
| 213 |
|
212 |
|
| 214 |
my $translated_pref = { |
213 |
my $translated_pref = { |
|
Lines 220-227
sub get_translated_pref {
Link Here
|
| 220 |
if (($key eq 'choices' || $key eq 'multiple') && ref($value) eq 'HASH') { |
219 |
if (($key eq 'choices' || $key eq 'multiple') && ref($value) eq 'HASH') { |
| 221 |
$translated_value = { |
220 |
$translated_value = { |
| 222 |
map { |
221 |
map { |
| 223 |
my $msgid = sprintf('%s#%s# %s', $file, $pref_name, $value->{$_}); |
222 |
$_ => $self->get_trans_text($context, $value->{$_}) |
| 224 |
$_ => $self->get_trans_text($msgid, $value->{$_}) |
|
|
| 225 |
} keys %$value |
223 |
} keys %$value |
| 226 |
} |
224 |
} |
| 227 |
} |
225 |
} |
|
Lines 241-247
sub install_prefs {
Link Here
|
| 241 |
exit; |
239 |
exit; |
| 242 |
} |
240 |
} |
| 243 |
|
241 |
|
| 244 |
$self->{po} = Locale::PO->load_file_ashash($self->po_filename("-pref.po"), 'utf8'); |
242 |
my @po_entries = @{ Locale::PO->load_file_asarray($self->po_filename("-pref.po"), 'utf8') }; |
|
|
243 |
$self->{po} = { map { |
| 244 |
my $msgctxt = $_->msgctxt ? Locale::PO->dequote($_->msgctxt) : ''; |
| 245 |
my $msgid = Locale::PO->dequote($_->msgid); |
| 246 |
|
| 247 |
"$msgctxt;$msgid" => $_; |
| 248 |
} @po_entries }; |
| 245 |
|
249 |
|
| 246 |
for my $file ( @{$self->{pref_files}} ) { |
250 |
for my $file ( @{$self->{pref_files}} ) { |
| 247 |
my $pref = LoadFile( $self->{path_pref_en} . "/$file" ); |
251 |
my $pref = LoadFile( $self->{path_pref_en} . "/$file" ); |
|
Lines 251-257
sub install_prefs {
Link Here
|
| 251 |
my $tab = $_; |
255 |
my $tab = $_; |
| 252 |
my $tab_content = $pref->{$tab}; |
256 |
my $tab_content = $pref->{$tab}; |
| 253 |
|
257 |
|
| 254 |
$self->get_trans_text($file, $tab) => $self->get_translated_tab_content($file, $tab_content); |
258 |
$self->get_trans_text(undef, $tab) => $self->get_translated_tab_content($tab, $tab_content); |
| 255 |
} keys %$pref |
259 |
} keys %$pref |
| 256 |
}; |
260 |
}; |
| 257 |
|
261 |
|