From 8e876179272ce79b0023f771be5f3842bf5ef679 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Sun, 17 Jan 2016 13:23:42 +0100 Subject: L10N: Intern blood_types/genders/(char|staff)_roles/discussion_boards I definitely needed the Tie::IxHash thing for these. --- lib/VNDB/Func.pm | 5 ----- lib/VNDB/Handler/Chars.pm | 24 ++++++++++++------------ lib/VNDB/Handler/Discussions.pm | 30 +++++++++++++++--------------- lib/VNDB/Handler/Misc.pm | 2 +- lib/VNDB/Handler/Staff.pm | 8 ++++---- lib/VNDB/Handler/VNEdit.pm | 2 +- lib/VNDB/Handler/VNPage.pm | 16 ++++++++-------- 7 files changed, 41 insertions(+), 46 deletions(-) (limited to 'lib') diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm index 936a12a6..64f087ae 100644 --- a/lib/VNDB/Func.pm +++ b/lib/VNDB/Func.pm @@ -12,7 +12,6 @@ our @EXPORT = (@VNDBUtil::EXPORT, qw| clearfloat cssicon tagscore mt minage fil_parse fil_serialize parenttags childtags charspoil imgpath imgurl fmtvote fmtmedia fmtvnlen json_encode json_decode script_json - mtbloodt form_compare |); @@ -247,10 +246,6 @@ sub script_json { } -# mt() wrappers for data-dependent translation strings that have a special -# value for 'unknown'. -sub mtbloodt { $_[0] eq 'unknown' ? mt '_unknown' : mt '_bloodt_'.$_[0]; } - # Compare the keys in %$old with the keys in %$new. Returns 1 if a difference was found, 0 otherwise. sub form_compare { diff --git a/lib/VNDB/Handler/Chars.pm b/lib/VNDB/Handler/Chars.pm index 74029e5c..086bb9c8 100644 --- a/lib/VNDB/Handler/Chars.pm +++ b/lib/VNDB/Handler/Chars.pm @@ -39,7 +39,7 @@ sub page { [ original => diff => 1 ], [ alias => diff => qr/[ ,\n\.]/ ], [ desc => diff => qr/[ ,\n\.]/ ], - [ gender => serialize => sub { mt "_gender_$_[0]" } ], + [ gender => serialize => sub { $self->{genders}{$_[0]} } ], [ b_month => serialize => sub { $_[0]||mt '_revision_empty' } ], [ b_day => serialize => sub { $_[0]||mt '_revision_empty' } ], [ s_bust => serialize => sub { $_[0]||mt '_revision_empty' } ], @@ -47,7 +47,7 @@ sub page { [ s_hip => serialize => sub { $_[0]||mt '_revision_empty' } ], [ height => serialize => sub { $_[0]||mt '_revision_empty' } ], [ weight => serialize => sub { $_[0]||mt '_revision_empty' } ], - [ bloodt => serialize => \&mtbloodt ], + [ bloodt => serialize => sub { $self->{blood_types}{$_[0]} } ], [ main => htmlize => sub { $_[0] ? sprintf 'c%d', $_[0], $_[0] : mt '_revision_empty' } ], [ main_spoil=> serialize => sub { mt "_spoil_$_[0]" } ], [ image => htmlize => sub { @@ -60,7 +60,7 @@ sub page { [ vns => join => '
', split => sub { map sprintf('v%d %s %s (%s)', $_->{vid}, $_->{vid}, $_->{rid}?sprintf('[r%d]', $_->{rid}, $_->{rid}):'', - mt("_charrole_$_->{role}", 1), mt("_spoil_$_->{spoil}")), @{$_[0]}; + $self->{char_roles}{$_->{role}}, mt("_spoil_$_->{spoil}")), @{$_[0]}; }], ); } @@ -130,8 +130,8 @@ sub charTable { b style => 'margin-right: 10px', $r->{name}; } b class => 'grayedout', style => 'margin-right: 10px', $r->{original} if $r->{original}; - cssicon "gen $r->{gender}", mt "_gender_$r->{gender}" if $r->{gender} ne 'unknown'; - span mtbloodt $r->{bloodt} if $r->{bloodt} ne 'unknown'; + cssicon "gen $r->{gender}", $self->{genders}{$r->{gender}} if $r->{gender} ne 'unknown'; + span $self->{blood_types}{$r->{bloodt}} if $r->{bloodt} ne 'unknown'; end; end; end; @@ -196,7 +196,7 @@ sub charTable { # special case: all releases, no exceptions if(!$vn && @r == 1 && !$r[0]{rid}) { span class => charspoil $r[0]{spoil}; - txt mt("_charrole_$r[0]{role}", 1).' - '; + txt $self->{char_roles}{$r[0]{role}}.' - '; a href => "/v$r[0]{vid}/chars", $r[0]{vntitle}; end; next; @@ -210,7 +210,7 @@ sub charTable { span class => charspoil $_->{spoil}; br if !$vn || $_ != $r[0]; b class => 'grayedout', '> '; - txt mt("_charrole_$_->{role}", 1).' - '; + txt $self->{char_roles}{$_->{role}}.' - '; if($_->{rid}) { b class => 'grayedout', "r$_->{rid}:"; a href => "/r$_->{rid}", $_->{rtitle}; @@ -290,7 +290,7 @@ sub edit { { post => 'original', required => 0, maxlength => 200, default => '' }, { post => 'alias', required => 0, maxlength => 500, default => '' }, { post => 'desc', required => 0, maxlength => 5000, default => '' }, - { post => 'gender', required => 0, default => 'unknown', enum => $self->{genders} }, + { post => 'gender', required => 0, default => 'unknown', enum => [ keys %{$self->{genders}} ] }, { post => 'image', required => 0, default => 0, template => 'id' }, { post => 'bday', required => 0, default => '', regex => [ qr/^\d{2}-\d{2}$/, mt('_chare_form_bday_err') ] }, { post => 's_bust', required => 0, default => 0, template => 'uint', max => 32767 }, @@ -298,7 +298,7 @@ sub edit { { post => 's_hip', required => 0, default => 0, template => 'uint', max => 32767 }, { post => 'height', required => 0, default => 0, template => 'uint', max => 32767 }, { post => 'weight', required => 0, default => 0, template => 'uint', max => 32767 }, - { post => 'bloodt', required => 0, default => 'unknown', enum => $self->{blood_types} }, + { post => 'bloodt', required => 0, default => 'unknown', enum => [ keys %{$self->{blood_types}} ] }, { post => 'main', required => 0, default => 0, template => 'id' }, { post => 'main_spoil', required => 0, default => 0, enum => [ 0..2 ] }, { post => 'traits', required => 0, default => '', regex => [ qr/^(?:[1-9]\d*-[0-2])(?: +[1-9]\d*-[0-2])*$/, 'Incorrect trait format.' ] }, @@ -370,7 +370,7 @@ sub edit { [ static => content => mt('_chare_form_alias_note') ], [ text => name => mt('_chare_form_desc').'
'.mt('_inenglish').'', short => 'desc', rows => 6 ], [ select => name => mt('_chare_form_gender'),short => 'gender', options => [ - map [ $_, mt("_gender_$_") ], @{$self->{genders}} ] ], + map [ $_, $self->{genders}{$_} ], keys %{$self->{genders}} ] ], [ input => name => mt('_chare_form_bday'), short => 'bday', width => 100, post => ' '.mt('_chare_form_bday_fmt') ], [ input => name => mt('_chare_form_bust'), short => 's_bust', width => 50, post => ' cm' ], [ input => name => mt('_chare_form_waist'), short => 's_waist',width => 50, post => ' cm' ], @@ -378,7 +378,7 @@ sub edit { [ input => name => mt('_chare_form_height'),short => 'height', width => 50, post => ' cm' ], [ input => name => mt('_chare_form_weight'),short => 'weight', width => 50, post => ' kg' ], [ select => name => mt('_chare_form_bloodt'),short => 'bloodt', options => [ - map [ $_, mtbloodt $_ ], @{$self->{blood_types}} ] ], + map [ $_, $self->{blood_types}{$_} ], keys %{$self->{blood_types}} ] ], [ static => content => '
' ], [ input => name => mt('_chare_form_main'), short => 'main', width => 50, post => ' '.mt('_chare_form_main_note') ], [ select => name => mt('_chare_form_main_spoil'), short => 'main_spoil', options => [ @@ -546,7 +546,7 @@ sub charBrowseTable { my($s, $n, $l) = @_; Tr; td class => 'tc1'; - cssicon "gen $l->{gender}", mt "_gender_$l->{gender}" if $l->{gender} ne 'unknown'; + cssicon "gen $l->{gender}", mt $self->{genders}{$l->{gender}} if $l->{gender} ne 'unknown'; end; td class => 'tc2'; a href => "/c$l->{id}", title => $l->{original}||$l->{name}, shorten $l->{name}, 50; diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm index 8c18a92c..b95bab92 100644 --- a/lib/VNDB/Handler/Discussions.pm +++ b/lib/VNDB/Handler/Discussions.pm @@ -46,7 +46,7 @@ sub thread { ul; for (sort { $a->{type}.$a->{iid} cmp $b->{type}.$b->{iid} } @{$t->{boards}}) { li; - a href => "/t/$_->{type}", mt "_dboard_$_->{type}"; + a href => "/t/$_->{type}", $self->{discussion_boards}{$_->{type}}; if($_->{iid}) { txt ' > '; a style => 'font-weight: bold', href => "/t/$_->{type}$_->{iid}", "$_->{type}$_->{iid}"; @@ -208,7 +208,7 @@ sub edit { my($ty, $id) = ($1, $2) if /^([a-z]{1,2})([0-9]*)$/; push @boards, [ $ty, $id ]; push @{$frm->{_err}}, [ 'boards', 'wrongboard', $_ ] if - !$ty || !grep($_ eq $ty, @{$self->{discussion_boards}}) + !$ty || !$self->{discussion_boards}{$ty} || $ty eq 'an' && ($id || !$self->authCan('boardmod')) || $ty eq 'db' && $id || $ty eq 'ge' && $id @@ -380,7 +380,7 @@ sub board { $self->dbVNGet(id => $iid)->[0]; return $self->resNotFound if $iid && !$obj; my $ititle = $obj && ($obj->{title}||$obj->{name}||$obj->{username}); - my $title = !$obj ? mt($type eq 'all' ? '_disboard_item_all' : "_dboard_$type") : mt '_disboard_item_title', $ititle; + my $title = !$obj ? $self->{discussion_boards}{$type} || 'All boards' : mt '_disboard_item_title', $ititle; my($list, $np) = $self->dbThreadGet( $type ne 'all' ? (type => $type) : (), @@ -400,7 +400,7 @@ sub board { p; a href => '/t', mt '_disboard_rootlink'; txt ' > '; - a href => "/t/$type", mt $type eq 'all' ? '_disboard_item_all' : "_dboard_$type"; + a href => "/t/$type", $self->{discussion_boards}{$type}||'All boards'; if($iid) { txt ' > '; a style => 'font-weight: bold', href => "/t/$type$iid", "$type$iid"; @@ -445,14 +445,14 @@ sub index { input type => 'submit', class => 'submit', value => mt '_searchbox_submit'; end 'fieldset'; p class => 'browseopts'; - a href => '/t/all', mt '_disboard_item_all'; - a href => '/t/'.$_, mt "_dboard_$_" - for (@{$self->{discussion_boards}}); + a href => '/t/all', 'All boards'; + a href => '/t/'.$_, $self->{discussion_boards}{$_} + for (keys %{$self->{discussion_boards}}); end; end; end; - for (@{$self->{discussion_boards}}) { + for (keys %{$self->{discussion_boards}}) { my $list = $self->dbThreadGet( type => $_, results => /^(db|v|ge)$/ ? 10 : 5, @@ -461,7 +461,7 @@ sub index { sort => 'lastpost', reverse => 1, ); h1 class => 'boxtitle'; - a href => "/t/$_", mt "_dboard_$_"; + a href => "/t/$_", $self->{discussion_boards}{$_}; end; _threadlist($self, $list, {p=>1}, 0, "/t", $_); } @@ -475,7 +475,7 @@ sub search { my $frm = $self->formValidate( { get => 'bq', required => 0, maxlength => 100 }, - { get => 'b', required => 0, multi => 1, enum => $self->{discussion_boards} }, + { get => 'b', required => 0, multi => 1, enum => [ keys %{$self->{discussion_boards}} ] }, { get => 't', required => 0 }, { get => 'p', required => 0, default => 1, template => 'page' }, ); @@ -485,8 +485,8 @@ sub search { $self->htmlForm({ frm => $frm, action => '/t/search', method => 'get', nosubmit => 1, noformcode => 1 }, 'boardsearch' => [mt('_dissearch_title'), [ input => short => 'bq', name => mt('_dissearch_query') ], [ check => short => 't', name => mt('_dissearch_titleonly') ], - [ select => short => 'b', name => mt('_dissearch_boards'), multi => 1, size => scalar @{$self->{discussion_boards}}, - options => [ map [$_,mt("_dboard_$_")], @{$self->{discussion_boards}} ] ], + [ select => short => 'b', name => mt('_dissearch_boards'), multi => 1, size => scalar keys %{$self->{discussion_boards}}, + options => [ map [$_,$self->{discussion_boards}{$_}], keys %{$self->{discussion_boards}} ] ], [ static => content => sub { input type => 'submit', class => 'submit', tabindex => 10, value => mt '_searchbox_submit'; } ], @@ -494,7 +494,7 @@ sub search { return $self->htmlFooter if !$frm->{bq}; my %boards = map +($_,1), @{$frm->{b}}; - %boards = () if keys %boards == @{$self->{discussion_boards}}; + %boards = () if keys %boards == keys %{$self->{discussion_boards}}; my($l, $np); if($frm->{t}) { @@ -610,8 +610,8 @@ sub _threadlist { last if $i++ > 4; txt ', ' if $i > 2; a href => "/t/$_->{type}".($_->{iid}||''), - title => $_->{original}||mt("_dboard_$_->{type}"), - shorten $_->{title}||mt("_dboard_$_->{type}"), 30; + title => $_->{original}||$self->{discussion_boards}{$_->{type}}, + shorten $_->{title}||$self->{discussion_boards}{$_->{type}}, 30; } txt ', ...' if @boards > 4; end; diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm index e36c0254..95bfe155 100644 --- a/lib/VNDB/Handler/Misc.pm +++ b/lib/VNDB/Handler/Misc.pm @@ -109,7 +109,7 @@ sub homepage { my $posts = $self->dbThreadGet(what => 'lastpost boardtitles', results => 10, sort => 'lastpost', reverse => 1, notusers => 1); ul; for (@$posts) { - my $boards = join ', ', map mt("_dboard_$_->{type}").($_->{iid}?' > '.$_->{title}:''), @{$_->{boards}}; + my $boards = join ', ', map $self->{discussion_boards}{$_->{type}}.($_->{iid}?' > '.$_->{title}:''), @{$_->{boards}}; li; lit mt '_home_recentposts_item', $_->{ldate}, sprintf('%s', "/t$_->{id}.$_->{count}", diff --git a/lib/VNDB/Handler/Staff.pm b/lib/VNDB/Handler/Staff.pm index 178d80cb..a6d59cbf 100644 --- a/lib/VNDB/Handler/Staff.pm +++ b/lib/VNDB/Handler/Staff.pm @@ -36,7 +36,7 @@ sub page { $self->htmlRevision('s', $prev, $s, [ name => diff => 1 ], [ original => diff => 1 ], - [ gender => serialize => sub { mt "_gender_$_[0]" } ], + [ gender => serialize => sub { $self->{genders}{$_[0]} } ], [ lang => serialize => sub { "$_[0] ($self->{languages}{$_[0]})" } ], [ l_site => diff => 1 ], [ l_wp => htmlize => sub { @@ -63,7 +63,7 @@ sub page { td colspan => 2; b style => 'margin-right: 10px', $s->{name}; b class => 'grayedout', style => 'margin-right: 10px', $s->{original} if $s->{original}; - cssicon "gen $s->{gender}", mt "_gender_$s->{gender}" if $s->{gender} ne 'unknown'; + cssicon "gen $s->{gender}", $self->{genders}{$s->{gender}} if $s->{gender} ne 'unknown'; end; end; end; @@ -139,7 +139,7 @@ sub _roles { Tr; td class => 'tc1'; a href => "/v$l->{vid}", title => $l->{t_original}||$l->{title}, shorten $l->{title}, 60; end; td class => 'tc2'; lit $self->{l10n}->datestr($l->{c_released}); end; - td class => 'tc3', mt '_credit_'.$l->{role}; + td class => 'tc3', $self->{staff_roles}{$l->{role}}; td class => 'tc4', title => $l->{original}||$l->{name}, $l->{name}; td class => 'tc5', $l->{note}; end; @@ -275,7 +275,7 @@ sub edit { [ static => content => '
' ], [ text => name => mt('_staffe_form_note').'
'.mt('_inenglish').'', short => 'desc', rows => 4 ], [ select => name => mt('_staffe_form_gender'),short => 'gender', options => [ - map [ $_, mt("_gender_$_") ], qw(unknown m f) ] ], + map [ $_, $self->{genders}{$_} ], qw(unknown m f) ] ], [ select => name => mt('_staffe_form_lang'), short => 'lang', options => [ map [ $_, "$_ ($self->{languages}{$_})" ], keys %{$self->{languages}} ] ], [ input => name => mt('_staffe_form_site'), short => 'l_site' ], diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm index b906eafa..870f9fb8 100644 --- a/lib/VNDB/Handler/VNEdit.pm +++ b/lib/VNDB/Handler/VNEdit.pm @@ -122,7 +122,7 @@ sub edit { { post => 'img_nsfw', required => 0, default => 0 }, { post => 'credits', required => 0, template => 'json', json_unique => ['aid','role'], json_sort => ['aid','role'], json_fields => [ { field => 'aid', required => 1, template => 'id' }, - { field => 'role', required => 1, enum => $self->{staff_roles} }, + { field => 'role', required => 1, enum => [ keys %{$self->{staff_roles}} ] }, { field => 'note', required => 0, maxlength => 250, default => '' }, ]}, { post => 'seiyuu', required => 0, template => 'json', json_unique => ['aid','cid'], json_sort => ['aid','cid'], json_fields => [ diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm index 82a0599e..055e2831 100644 --- a/lib/VNDB/Handler/VNPage.pm +++ b/lib/VNDB/Handler/VNPage.pm @@ -516,7 +516,7 @@ sub _revision { }], [ credits => join => '
', split => sub { my @r = map sprintf('%s [%s]%s', $_->{id}, - xml_escape($_->{original}||$_->{name}), xml_escape($_->{name}), mt("_credit_$_->{role}"), + xml_escape($_->{original}||$_->{name}), xml_escape($_->{name}), xml_escape($self->{staff_roles}{$_->{role}}), $_->{note} ? ' ['.xml_escape($_->{note}).']' : ''), sort { $a->{id} <=> $b->{id} || $a->{role} cmp $b->{role} } @{$_[0]}; return @r ? @r : (mt '_revision_empty'); @@ -886,15 +886,15 @@ sub _chars { return if !@$l; my %done; my %rol; - for my $r (@{$self->{char_roles}}) { + for my $r (keys %{$self->{char_roles}}) { $rol{$r} = [ grep grep($_->{role} eq $r, @{$_->{vns}}) && !$done{$_->{id}}++, @$l ]; } my $first = 0; - for my $r (@{$self->{char_roles}}) { + for my $r (keys %{$self->{char_roles}}) { next if !@{$rol{$r}}; div class => 'mainbox'; $self->charOps(1) if !$first++; - h1 mt "_charrole_$r", scalar @{$rol{$r}}; + h1 $self->{char_roles}{$r}; $self->charTable($_, 1, $_ != $rol{$r}[0], 1, _charspoillvl $v->{id}, $_) for (@{$rol{$r}}); end; } @@ -906,7 +906,7 @@ sub _charsum { return if !@$l; my(@l, %done, $has_spoilers); - for my $r (@{$self->{char_roles}}) { + for my $r (keys %{$self->{char_roles}}) { last if $r eq 'appears'; for (grep grep($_->{role} eq $r, @{$_->{vns}}) && !$done{$_->{id}}++, @$l) { $_->{role} = $r; @@ -922,7 +922,7 @@ sub _charsum { for my $c (@l) { div class => 'charsum_bubble'.($has_spoilers ? ' '.charspoil(_charspoillvl $v->{id}, $c) : ''); div class => 'name'; - i mt '_charrole_'.$c->{role}, 1; + i $self->{char_roles}{$c->{role}}; a href => "/c$c->{id}", title => $c->{original}||$c->{name}, $c->{name}; end; if(@{$c->{seiyuu}}) { @@ -949,11 +949,11 @@ sub _staff { div class => 'mainbox staff summarize', 'data-summarize-height' => 100, id => 'staff'; h1 mt '_vnpage_staff'; - for my $r (@{$self->{staff_roles}}) { + for my $r (keys %{$self->{staff_roles}}) { my @s = grep $_->{role} eq $r, @{$v->{credits}}; next if !@s; ul; - li; b mt '_credit_'.$r; end; + li; b $self->{staff_roles}{$r}; end; for(@s) { li; a href => "/s$_->{id}", title => $_->{original}||$_->{name}, $_->{name}; -- cgit v1.2.3