summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/Func.pm68
-rw-r--r--lib/VNDB/Handler/Discussions.pm14
-rw-r--r--lib/VNDB/Handler/Misc.pm6
-rw-r--r--lib/VNDB/Handler/Producers.pm2
-rw-r--r--lib/VNDB/Handler/Releases.pm6
-rw-r--r--lib/VNDB/Handler/Tags.pm8
-rw-r--r--lib/VNDB/Handler/ULists.pm4
-rw-r--r--lib/VNDB/Handler/Users.pm6
-rw-r--r--lib/VNDB/Handler/VNBrowse.pm2
-rw-r--r--lib/VNDB/Handler/VNPage.pm2
-rw-r--r--lib/VNDB/L10N.pm96
-rw-r--r--lib/VNDB/Util/CommonHTML.pm18
12 files changed, 128 insertions, 104 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 31a04f8a..cd4c4b62 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -6,7 +6,7 @@ use warnings;
use YAWF ':html';
use Exporter 'import';
use POSIX 'strftime', 'ceil', 'floor';
-our @EXPORT = qw| shorten age date datestr monthstr userstr bb2html gtintype liststat clearfloat cssicon tagscore mt |;
+our @EXPORT = qw| shorten bb2html gtintype liststat clearfloat cssicon tagscore mt |;
# I would've done this as a #define if this was C...
@@ -16,72 +16,6 @@ sub shorten {
}
-# Argument: unix timestamp
-# Returns: age
-sub age {
- my $a = time-$_[0];
- return sprintf '%d %s ago',
- $a > 60*60*24*365*2 ? ( $a/60/60/24/365, 'years' ) :
- $a > 60*60*24*(365/12)*2 ? ( $a/60/60/24/(365/12), 'months' ) :
- $a > 60*60*24*7*2 ? ( $a/60/60/24/7, 'weeks' ) :
- $a > 60*60*24*2 ? ( $a/60/60/24, 'days' ) :
- $a > 60*60*2 ? ( $a/60/60, 'hours' ) :
- $a > 60*2 ? ( $a/60, 'min' ) :
- ( $a, 'sec' );
-}
-
-
-# argument: unix timestamp and optional format (compact/full)
-# return value: yyyy-mm-dd
-# (maybe an idea to use cgit-style ages for recent timestamps)
-sub date {
- my($t, $f) = @_;
- return strftime '%Y-%m-%d', gmtime $t if !$f || $f eq 'compact';
- return strftime '%Y-%m-%d at %R', gmtime $t;
-}
-
-
-# argument: database release date format (yyyymmdd)
-# y = 0000 -> unknown
-# y = 9999 -> TBA
-# m = 99 -> month+day unknown
-# d = 99 -> day unknown
-# return value: (unknown|TBA|yyyy|yyyy-mm|yyyy-mm-dd)
-# if date > now: <b class="future">str</b>
-sub datestr {
- my $date = sprintf '%08d', shift||0;
- my $future = $date > strftime '%Y%m%d', gmtime;
- my($y, $m, $d) = ($1, $2, $3) if $date =~ /^([0-9]{4})([0-9]{2})([0-9]{2})$/;
-
- my $str = $y == 0 ? 'unknown' : $y == 9999 ? 'TBA' :
- $m == 99 ? sprintf('%04d', $y) :
- $d == 99 ? sprintf('%04d-%02d', $y, $m) :
- sprintf('%04d-%02d-%02d', $y, $m, $d);
-
- return $str if !$future;
- return qq|<b class="future">$str</b>|;
-}
-
-# same as datestr(), but different output format:
-# e.g.: 'Jan 2009', '2009', 'unknown', 'TBA'
-sub monthstr {
- my $date = sprintf '%08d', shift||0;
- my($y, $m, $d) = ($1, $2, $3) if $date =~ /^([0-9]{4})([0-9]{2})([0-9]{2})/;
- return 'TBA' if $y == 9999;
- return 'unknown' if $y == 0;
- return $y if $m == 99;
- my $r = sprintf '%s %d', [qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)]->[$m-1], $y;
- return $d == 99 ? "<i>$r</i>" : $r;
-}
-
-
-# Arguments: (uid, username), or a hashref containing that info
-sub userstr {
- my($id,$n) = ref($_[0])eq'HASH'?($_[0]{uid}||$_[0]{requester}, $_[0]{username}):@_;
- return !$id ? '[deleted]' : '<a href="/u'.$id.'">'.$n.'</a>';
-}
-
-
# Arguments: input, and optionally the maximum length
# Parses:
# [url=..] [/url]
diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm
index 811bd74a..22b2eed2 100644
--- a/lib/VNDB/Handler/Discussions.pm
+++ b/lib/VNDB/Handler/Discussions.pm
@@ -61,9 +61,9 @@ sub thread {
a href => "/t$tid.$_->{num}", name => $_->{num}, "#$_->{num}";
if(!$_->{hidden}) {
txt ' by ';
- lit userstr $_;
+ lit $self->{l10n}->userstr($_);
br;
- lit date $_->{date}, 'full';
+ lit $self->{l10n}->date($_->{date}, 'full');
}
end;
td class => 'tc2';
@@ -78,7 +78,7 @@ sub thread {
i class => 'deleted', 'Post deleted.';
} else {
lit bb2html $_->{msg};
- i class => 'lastmod', 'Last modified on '.date($_->{edited}, 'full') if $_->{edited};
+ i class => 'lastmod', 'Last modified on '.$self->{l10n}->date($_->{edited}, 'full') if $_->{edited};
}
end;
end;
@@ -235,7 +235,7 @@ sub edit {
my $url = !$tid ? "/t/$board/new" : !$num ? "/t$tid/reply" : "/t$tid.$num/edit";
$self->htmlHeader(title => $title, noindex => 1);
$self->htmlForm({ frm => $frm, action => $url }, $title => [
- [ static => label => 'Username', content => userstr($self->authInfo->{id}, $self->authInfo->{username}) ],
+ [ static => label => 'Username', content => $self->{l10n}->userstr($self->authInfo->{id}, $self->authInfo->{username}) ],
!$tid || $num == 1 ? (
[ input => short => 'title', name => 'Thread title' ],
[ input => short => 'boards', name => 'Board(s)' ],
@@ -368,13 +368,13 @@ sub _threadlist {
end;
td class => 'tc2', $o->{count}-1;
td class => 'tc3';
- lit userstr $o->{fuid}, $o->{fusername};
+ lit $self->{l10n}->userstr($o->{fuid}, $o->{fusername});
end;
td class => 'tc4';
- lit userstr $o->{luid}, $o->{lusername};
+ lit $self->{l10n}->userstr($o->{luid}, $o->{lusername});
lit ' @ ';
a href => "/t$o->{id}.$o->{count}";
- lit date $o->{ldate};
+ lit $self->{l10n}->date($o->{ldate});
end;
end;
end;
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm
index 20b8c564..a0949c92 100644
--- a/lib/VNDB/Handler/Misc.pm
+++ b/lib/VNDB/Handler/Misc.pm
@@ -100,7 +100,7 @@ sub homepage {
for (@$posts) {
my $boards = join ', ', map $self->{discussion_boards}{$_->{type}}.($_->{iid}?' > '.$_->{title}:''), @{$_->{boards}};
li;
- txt age($_->{ldate}).' ';
+ txt $self->{l10n}->age($_->{ldate}).' ';
a href => "/t$_->{id}.$_->{count}", title => "Posted in $boards", shorten $_->{title}, 20;
txt ' by ';
a href => "/u$_->{luid}", $_->{lusername};
@@ -132,7 +132,7 @@ sub homepage {
ul;
for (@$upcoming) {
li;
- lit datestr $_->{released};
+ lit $self->{l10n}->datestr($_->{released});
txt ' ';
cssicon $_, mt "_plat_$_" for (@{$_->{platforms}});
txt ' ';
@@ -149,7 +149,7 @@ sub homepage {
ul;
for (@$justrel) {
li;
- lit datestr $_->{released};
+ lit $self->{l10n}->datestr($_->{released});
txt ' ';
cssicon $_, mt "_plat_$_" for (@{$_->{platforms}});
txt ' ';
diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm
index 57e79490..43b7c025 100644
--- a/lib/VNDB/Handler/Producers.pm
+++ b/lib/VNDB/Handler/Producers.pm
@@ -72,7 +72,7 @@ sub page {
for (@{$p->{vn}}) {
li;
i;
- lit datestr $_->{date};
+ lit $self->{l10n}->datestr($_->{date});
end;
a href => "/v$_->{id}", title => $_->{original}, $_->{title};
end;
diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm
index 71447626..61889459 100644
--- a/lib/VNDB/Handler/Releases.pm
+++ b/lib/VNDB/Handler/Releases.pm
@@ -49,7 +49,7 @@ sub page {
[ catalog => 'Catalog number', serialize => sub { $_[0]||'[none]' } ],
[ languages => 'Language', join => ', ', split => sub { map mt("_lang_$_"), @{$_[0]} } ],
[ website => 'Website', ],
- [ released => 'Release date', htmlize => sub { datestr $_[0] } ],
+ [ released => 'Release date', htmlize => sub { $self->{l10n}->datestr($_[0]) } ],
[ minage => 'Age rating', serialize => sub { $self->{age_ratings}{$_[0]}[0] } ],
[ notes => 'Notes', diff => 1 ],
[ platforms => 'Platforms', join => ', ', split => sub { map mt("_plat_$_"), @{$_[0]} } ],
@@ -188,7 +188,7 @@ sub _infotable {
Tr ++$i % 2 ? (class => 'odd') : ();
td 'Released';
td;
- lit datestr $r->{released};
+ lit $self->{l10n}->datestr($r->{released});
end;
end;
@@ -539,7 +539,7 @@ sub browse {
my($s, $n, $l) = @_;
Tr $n % 2 ? (class => 'odd') : ();
td class => 'tc1';
- lit datestr $l->{released};
+ lit $self->{l10n}->datestr($l->{released});
end;
td class => 'tc2', $l->{minage} > -1 ? $self->{age_ratings}{$l->{minage}}[0] : '';
td class => 'tc3';
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index fce4fadb..ecdaebbc 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -217,7 +217,7 @@ sub _vnlist {
for (reverse sort split /\//, $l->{c_languages});
end;
td class => 'tc5';
- lit monthstr $l->{c_released};
+ lit $self->{l10n}->monthstr($l->{c_released});
end;
td class => 'tc6', sprintf '%.2f', $l->{c_popularity}*100;
end;
@@ -398,7 +398,7 @@ sub taglist {
row => sub {
my($s, $n, $l) = @_;
Tr $n % 2 ? (class => 'odd') : ();
- td class => 'tc1', age $l->{added};
+ td class => 'tc1', $self->{l10n}->age($l->{added});
td class => 'tc3';
a href => "/g$l->{id}", $l->{name};
if($f->{t} == -1) {
@@ -608,7 +608,7 @@ sub tagindex {
ul;
for (@$r) {
li;
- txt age $_->{added};
+ txt $self->{l10n}->age($_->{added});
txt ' ';
a href => "/g$_->{id}", $_->{name};
end;
@@ -638,7 +638,7 @@ sub tagindex {
li "Moderation queue empty! yay!" if !@$r;
for (@$r) {
li;
- txt age $_->{added};
+ txt $self->{l10n}->age($_->{added});
txt ' ';
a href => "/g$_->{id}", $_->{name};
end;
diff --git a/lib/VNDB/Handler/ULists.pm b/lib/VNDB/Handler/ULists.pm
index 3cffb9e6..f01d0db2 100644
--- a/lib/VNDB/Handler/ULists.pm
+++ b/lib/VNDB/Handler/ULists.pm
@@ -170,7 +170,7 @@ sub wishlist {
a href => "/v$i->{vid}", title => $i->{original}||$i->{title}, ' '.shorten $i->{title}, 70;
end;
td class => 'tc2', ucfirst $self->{wishlist_status}[$i->{wstat}];
- td class => 'tc3', date $i->{added}, 'compact';
+ td class => 'tc3', $self->{l10n}->date($i->{added}, 'compact');
end;
},
$own ? (footer => sub {
@@ -312,7 +312,7 @@ sub _vnlist_browse {
td class => 'tc1'.($own ? ' own' : '');
input type => 'checkbox', name => 'sel', value => $_->{rid}
if $own;
- lit datestr $_->{released};
+ lit $self->{l10n}->datestr($_->{released});
end;
td class => 'tc2';
cssicon "lang $_", mt "_lang_$_" for @{$_->{languages}};
diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm
index ca5719e1..dbf9dee4 100644
--- a/lib/VNDB/Handler/Users.pm
+++ b/lib/VNDB/Handler/Users.pm
@@ -52,7 +52,7 @@ sub userpage {
Tr ++$i % 2 ? (class => 'odd') : ();
td 'Registered';
- td date $u->{registered};
+ td $self->{l10n}->date($u->{registered});
end;
Tr ++$i % 2 ? (class => 'odd') : ();
@@ -432,7 +432,7 @@ sub posts {
Tr $n % 2 ? (class => 'odd') : ();
td class => 'tc1'; a href => "/t$l->{tid}.$l->{num}", 't'.$l->{tid}; end;
td class => 'tc2'; a href => "/t$l->{tid}.$l->{num}", '.'.$l->{num}; end;
- td class => 'tc3', date $l->{date};
+ td class => 'tc3', $self->{l10n}->date($l->{date});
td class => 'tc4'; a href => "/t$l->{tid}.$l->{num}", $l->{title}; end;
end;
Tr class => $n % 2 ? 'editsum odd hidden' : 'editsum hidden';
@@ -538,7 +538,7 @@ sub list {
td class => 'tc1';
a href => '/u'.$l->{id}, $l->{username};
end;
- td class => 'tc2', date $l->{registered};
+ td class => 'tc2', $self->{l10n}->date($l->{registered});
td class => 'tc3'.(!$l->{show_list} && $self->authCan('usermod') ? ' linethrough' : '');
lit !$l->{show_list} && !$self->authCan('usermod') ? '-' : !$l->{c_votes} ? 0 :
qq|<a href="/u$l->{id}/list">$l->{c_votes}</a>|;
diff --git a/lib/VNDB/Handler/VNBrowse.pm b/lib/VNDB/Handler/VNBrowse.pm
index 3b8dc2ab..e11a2942 100644
--- a/lib/VNDB/Handler/VNBrowse.pm
+++ b/lib/VNDB/Handler/VNBrowse.pm
@@ -111,7 +111,7 @@ sub list {
for (reverse sort split /\//, $l->{c_languages});
end;
td class => 'tc4';
- lit monthstr $l->{c_released};
+ lit $self->{l10n}->monthstr($l->{c_released});
end;
td class => 'tc5', sprintf '%.2f', $l->{c_popularity}*100;
end;
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index b618f792..facf70e2 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -378,7 +378,7 @@ sub _releases {
end;
for my $rel (grep grep($_ eq $l, @{$_->{languages}}), @$r) {
Tr;
- td class => 'tc1'; lit datestr $rel->{released}; end;
+ td class => 'tc1'; lit $self->{l10n}->datestr($rel->{released}); end;
td class => 'tc2', $rel->{minage} < 0 ? '' : $self->{age_ratings}{$rel->{minage}}[0];
td class => 'tc3';
for (sort @{$rel->{platforms}}) {
diff --git a/lib/VNDB/L10N.pm b/lib/VNDB/L10N.pm
index d71a72dc..3dfe00c6 100644
--- a/lib/VNDB/L10N.pm
+++ b/lib/VNDB/L10N.pm
@@ -81,15 +81,105 @@ use warnings;
{
package VNDB::L10N::en;
use base 'VNDB::L10N';
- our %Lexicon = (
- _AUTO => 1
- );
+ use POSIX 'strftime';
+ our %Lexicon;
+
+ # Argument: unix timestamp
+ # Returns: age
+ sub age {
+ my $a = time-$_[1];
+ return sprintf '%d %s ago',
+ $a > 60*60*24*365*2 ? ( $a/60/60/24/365, 'years' ) :
+ $a > 60*60*24*(365/12)*2 ? ( $a/60/60/24/(365/12), 'months' ) :
+ $a > 60*60*24*7*2 ? ( $a/60/60/24/7, 'weeks' ) :
+ $a > 60*60*24*2 ? ( $a/60/60/24, 'days' ) :
+ $a > 60*60*2 ? ( $a/60/60, 'hours' ) :
+ $a > 60*2 ? ( $a/60, 'min' ) :
+ ( $a, 'sec' );
+ }
+
+ # argument: unix timestamp and optional format (compact/full)
+ # return value: yyyy-mm-dd
+ # (maybe an idea to use cgit-style ages for recent timestamps)
+ sub date {
+ my($s, $t, $f) = @_;
+ return strftime '%Y-%m-%d', gmtime $t if !$f || $f eq 'compact';
+ return strftime '%Y-%m-%d at %R', gmtime $t;
+ }
+
+ # argument: database release date format (yyyymmdd)
+ # y = 0000 -> unknown
+ # y = 9999 -> TBA
+ # m = 99 -> month+day unknown
+ # d = 99 -> day unknown
+ # return value: (unknown|TBA|yyyy|yyyy-mm|yyyy-mm-dd)
+ # if date > now: <b class="future">str</b>
+ sub datestr {
+ my $self = shift;
+ my $date = sprintf '%08d', shift||0;
+ my $future = $date > strftime '%Y%m%d', gmtime;
+ my($y, $m, $d) = ($1, $2, $3) if $date =~ /^([0-9]{4})([0-9]{2})([0-9]{2})$/;
+
+ my $str = $y == 0 ? 'unknown' : $y == 9999 ? 'TBA' :
+ $m == 99 ? sprintf('%04d', $y) :
+ $d == 99 ? sprintf('%04d-%02d', $y, $m) :
+ sprintf('%04d-%02d-%02d', $y, $m, $d);
+
+ return $str if !$future;
+ return qq|<b class="future">$str</b>|;
+ }
+
+ # same as datestr(), but different output format:
+ # e.g.: 'Jan 2009', '2009', 'unknown', 'TBA'
+ sub monthstr {
+ my $self = shift;
+ my $date = sprintf '%08d', shift||0;
+ my($y, $m, $d) = ($1, $2, $3) if $date =~ /^([0-9]{4})([0-9]{2})([0-9]{2})/;
+ return 'TBA' if $y == 9999;
+ return 'unknown' if $y == 0;
+ return $y if $m == 99;
+ my $r = sprintf '%s %d', [qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)]->[$m-1], $y;
+ return $d == 99 ? "<i>$r</i>" : $r;
+ }
+
+ # Arguments: (uid, username), or a hashref containing that info
+ sub userstr {
+ my $self = shift;
+ my($id,$n) = ref($_[0])eq'HASH'?($_[0]{uid}||$_[0]{requester}, $_[0]{username}):@_;
+ return !$id ? '[deleted]' : '<a href="/u'.$id.'">'.$n.'</a>';
+ }
}
+
+
{
package VNDB::L10N::ru;
use base 'VNDB::L10N::en';
our %Lexicon;
+
+ sub quant {
+ my($self, $num, $single, $couple, $lots) = @_;
+ return $single if ($num % 10) == 1 && ($num % 100) != 11;
+ return $couple if ($num % 10) >= 2 && ($num % 10) <= 4 && !(($num % 100) >= 12 && ($num % 100) <= 14);
+ return $lots;
+ }
+
+ sub age {
+ my $self = shift;
+ my $a = time-shift;
+ use utf8;
+ my @l = (
+ $a > 60*60*24*365*2 ? ( $a/60/60/24/365, 'год', 'года', 'лет' ) :
+ $a > 60*60*24*(365/12)*2 ? ( $a/60/60/24/(365/12), 'месяц', 'месяца', 'месяцев' ) :
+ $a > 60*60*24*7*2 ? ( $a/60/60/24/7, 'неделя', 'недели', 'недель' ) :
+ $a > 60*60*24*2 ? ( $a/60/60/24, 'день', 'дня', 'дней' ) :
+ $a > 60*60*2 ? ( $a/60/60, 'час', 'часа', 'часов' ) :
+ $a > 60*2 ? ( $a/60, 'минута', 'минуты', 'минут' ) :
+ ( $a, 'секунда', 'секунды', 'секунд' )
+ );
+ return sprintf '%d %s назад', $l[0], $self->quant(@l);
+ }
+
}
diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm
index ffdbe505..08a73802 100644
--- a/lib/VNDB/Util/CommonHTML.pm
+++ b/lib/VNDB/Util/CommonHTML.pm
@@ -275,7 +275,7 @@ sub htmlRevision {
# no previous revision, just show info about the revision itself
if(!$old) {
div;
- revheader($type, $new);
+ revheader($self, $type, $new);
br;
b 'Edit summary:';
br; br;
@@ -289,8 +289,8 @@ sub htmlRevision {
thead;
Tr;
td; lit '&nbsp;'; end;
- td; revheader($type, $old); end;
- td; revheader($type, $new); end;
+ td; revheader($self, $type, $old); end;
+ td; revheader($self, $type, $new); end;
end;
Tr;
td; lit '&nbsp;'; end;
@@ -309,16 +309,16 @@ sub htmlRevision {
}
sub revheader { # type, obj
- my($type, $obj) = @_;
+ my($self, $type, $obj) = @_;
b 'Revision '.$obj->{rev};
txt ' (';
a href => "/$type$obj->{id}.$obj->{rev}/edit", 'edit';
txt ')';
br;
txt 'By ';
- lit userstr($obj);
+ lit $self->{l10n}->userstr($obj);
txt ' on ';
- lit date $obj->{added}, 'full';
+ lit $self->{l10n}->date($obj->{added}, 'full');
}
sub revdiff {
@@ -477,7 +477,7 @@ sub htmlVoteStats {
}
end;
td $recent->[$_]{vote};
- td date $recent->[$_]{date};
+ td $self->{l10n}->date($recent->[$_]{date});
end;
}
end;
@@ -520,9 +520,9 @@ sub htmlHistory {
td class => 'tc1_2';
a href => $revurl, ".$i->{rev}";
end;
- td class => 'tc2', date $i->{added};
+ td class => 'tc2', $self->{l10n}->date($i->{added});
td class => 'tc3';
- lit userstr($i);
+ lit $self->{l10n}->userstr($i);
end;
td;
a href => $revurl, title => $i->{ioriginal}, shorten $i->{ititle}, 80;