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