|
Lines 150-182
sub po_filename {
Link Here
|
| 150 |
} |
150 |
} |
| 151 |
|
151 |
|
| 152 |
sub get_trans_text { |
152 |
sub get_trans_text { |
| 153 |
my ( $self, $msgid, $default ) = @_; |
153 |
my ( $self, $msgctxt, $msgid ) = @_; |
| 154 |
|
154 |
|
| 155 |
my $po = $self->{po}->{ Locale::PO->quote($msgid) }; |
155 |
my $key = ($msgctxt // '') . ";$msgid"; |
|
|
156 |
|
| 157 |
my $po = $self->{po}->{$key}; |
| 156 |
if ( $po and not defined( $po->fuzzy() ) ) { |
158 |
if ( $po and not defined( $po->fuzzy() ) ) { |
| 157 |
my $msgstr = Locale::PO->dequote( $po->msgstr ); |
159 |
my $msgstr = Locale::PO->dequote( $po->msgstr ); |
| 158 |
if ( $msgstr and length($msgstr) > 0 ) { |
160 |
|
| 159 |
return $msgstr; |
161 |
return $msgstr || $msgid; |
| 160 |
} |
|
|
| 161 |
} |
162 |
} |
| 162 |
|
163 |
|
| 163 |
return $default; |
164 |
return $msgid; |
| 164 |
} |
165 |
} |
| 165 |
|
166 |
|
| 166 |
sub get_translated_tab_content { |
167 |
sub get_translated_tab_content { |
| 167 |
my ( $self, $file, $tab_content ) = @_; |
168 |
my ( $self, $tab, $tab_content ) = @_; |
| 168 |
|
169 |
|
| 169 |
if ( ref($tab_content) eq 'ARRAY' ) { |
170 |
if ( ref($tab_content) eq 'ARRAY' ) { |
| 170 |
return $self->get_translated_prefs( $file, $tab_content ); |
171 |
return $self->get_translated_prefs( $tab, $tab_content ); |
| 171 |
} |
172 |
} |
| 172 |
|
173 |
|
| 173 |
my $translated_tab_content = { |
174 |
my $translated_tab_content = { |
| 174 |
map { |
175 |
map { |
| 175 |
my $section = $_; |
176 |
my $section = $_; |
| 176 |
my $sysprefs = $tab_content->{$section}; |
177 |
my $sysprefs = $tab_content->{$section}; |
| 177 |
my $msgid = sprintf( '%s %s', $file, $section ); |
178 |
my $context = "$tab > $section"; |
| 178 |
|
179 |
|
| 179 |
$self->get_trans_text( $msgid, $section ) => $self->get_translated_prefs( $file, $sysprefs ); |
180 |
$self->get_trans_text( $tab, $section ) => $self->get_translated_prefs( $context, $sysprefs ); |
| 180 |
} keys %$tab_content |
181 |
} keys %$tab_content |
| 181 |
}; |
182 |
}; |
| 182 |
|
183 |
|
|
Lines 197-210
sub get_translated_tab_content {
Link Here
|
| 197 |
} |
198 |
} |
| 198 |
|
199 |
|
| 199 |
sub get_translated_prefs { |
200 |
sub get_translated_prefs { |
| 200 |
my ( $self, $file, $sysprefs ) = @_; |
201 |
my ( $self, $context, $sysprefs ) = @_; |
| 201 |
|
202 |
|
| 202 |
my $translated_prefs = [ |
203 |
my $translated_prefs = [ |
| 203 |
map { |
204 |
map { |
| 204 |
my ($pref_elt) = grep { ref($_) eq 'HASH' && exists $_->{pref} } @$_; |
205 |
my ($pref_elt) = grep { ref($_) eq 'HASH' && exists $_->{pref} } @$_; |
| 205 |
my $pref_name = $pref_elt ? $pref_elt->{pref} : ''; |
206 |
my $pref_name = $pref_elt ? $pref_elt->{pref} : ''; |
| 206 |
|
207 |
|
| 207 |
my $translated_syspref = [ map { $self->get_translated_pref( $file, $pref_name, $_ ); } @$_ ]; |
208 |
my $translated_syspref = [ map { $self->get_translated_pref( "$context > $pref_name", $_ ); } @$_ ]; |
| 208 |
|
209 |
|
| 209 |
$translated_syspref; |
210 |
$translated_syspref; |
| 210 |
} @$sysprefs |
211 |
} @$sysprefs |
|
Lines 214-225
sub get_translated_prefs {
Link Here
|
| 214 |
} |
215 |
} |
| 215 |
|
216 |
|
| 216 |
sub get_translated_pref { |
217 |
sub get_translated_pref { |
| 217 |
my ( $self, $file, $pref_name, $syspref ) = @_; |
218 |
my ( $self, $context, $syspref ) = @_; |
| 218 |
|
219 |
|
| 219 |
unless ( ref($syspref) ) { |
220 |
unless ( ref($syspref) ) { |
| 220 |
$syspref //= ''; |
221 |
return $self->get_trans_text( $context, $syspref // '' ); |
| 221 |
my $msgid = sprintf( '%s#%s# %s', $file, $pref_name, $syspref ); |
|
|
| 222 |
return $self->get_trans_text( $msgid, $syspref ); |
| 223 |
} |
222 |
} |
| 224 |
|
223 |
|
| 225 |
my $translated_pref = { |
224 |
my $translated_pref = { |
|
Lines 229-240
sub get_translated_pref {
Link Here
|
| 229 |
|
228 |
|
| 230 |
my $translated_value = $value; |
229 |
my $translated_value = $value; |
| 231 |
if ( ( $key eq 'choices' || $key eq 'multiple' || $key eq 'multiple_sortable' ) && ref($value) eq 'HASH' ) { |
230 |
if ( ( $key eq 'choices' || $key eq 'multiple' || $key eq 'multiple_sortable' ) && ref($value) eq 'HASH' ) { |
| 232 |
$translated_value = { |
231 |
$translated_value = { map { $_ => $self->get_trans_text( $context, $value->{$_} ) } keys %$value }; |
| 233 |
map { |
|
|
| 234 |
my $msgid = sprintf( '%s#%s# %s', $file, $pref_name, $value->{$_} ); |
| 235 |
$_ => $self->get_trans_text( $msgid, $value->{$_} ) |
| 236 |
} keys %$value |
| 237 |
}; |
| 238 |
} |
232 |
} |
| 239 |
|
233 |
|
| 240 |
$key => $translated_value |
234 |
$key => $translated_value |
|
Lines 252-258
sub install_prefs {
Link Here
|
| 252 |
exit; |
246 |
exit; |
| 253 |
} |
247 |
} |
| 254 |
|
248 |
|
| 255 |
$self->{po} = Locale::PO->load_file_ashash( $self->po_filename("-pref.po"), 'utf8' ); |
249 |
my @po_entries = @{ Locale::PO->load_file_asarray( $self->po_filename("-pref.po"), 'utf8' ) }; |
|
|
250 |
$self->{po} = { |
| 251 |
map { |
| 252 |
my $msgctxt = $_->msgctxt ? Locale::PO->dequote( $_->msgctxt ) : ''; |
| 253 |
my $msgid = Locale::PO->dequote( $_->msgid ); |
| 254 |
|
| 255 |
"$msgctxt;$msgid" => $_; |
| 256 |
} @po_entries |
| 257 |
}; |
| 256 |
|
258 |
|
| 257 |
for my $file ( @{ $self->{pref_files} } ) { |
259 |
for my $file ( @{ $self->{pref_files} } ) { |
| 258 |
my $pref = YAML::XS::LoadFile( $self->{path_pref_en} . "/$file" ); |
260 |
my $pref = YAML::XS::LoadFile( $self->{path_pref_en} . "/$file" ); |
|
Lines 262-268
sub install_prefs {
Link Here
|
| 262 |
my $tab = $_; |
264 |
my $tab = $_; |
| 263 |
my $tab_content = $pref->{$tab}; |
265 |
my $tab_content = $pref->{$tab}; |
| 264 |
|
266 |
|
| 265 |
$self->get_trans_text( $file, $tab ) => $self->get_translated_tab_content( $file, $tab_content ); |
267 |
$self->get_trans_text( undef, $tab ) => $self->get_translated_tab_content( $tab, $tab_content ); |
| 266 |
} keys %$pref |
268 |
} keys %$pref |
| 267 |
}; |
269 |
}; |
| 268 |
|
270 |
|