diff options
author | Yorhel <git@yorhel.nl> | 2019-10-14 10:20:46 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2019-10-14 10:20:49 +0200 |
commit | 3039de16322c4d487ab15ff84c576ee59a5f2b71 (patch) | |
tree | 4f7e00e90c56f7cbc5ae4c84b2e2a05daf1721ac | |
parent | 1719ff16a7ccd829a704fe38e7eba08dfcaa08d4 (diff) |
Add lang HTML attribute to some original language fields
The database doesn't have a language attribute for every field, so this
is more of a best-effort heuristic. The attribute should allow browsers
to choose the correct font.
https://vndb.org/t2520.300
-rw-r--r-- | lib/VNDB/DB/VN.pm | 2 | ||||
-rw-r--r-- | lib/VNDB/Func.pm | 14 | ||||
-rw-r--r-- | lib/VNDB/Handler/Producers.pm | 2 | ||||
-rw-r--r-- | lib/VNDB/Handler/Releases.pm | 6 | ||||
-rw-r--r-- | lib/VNDB/Handler/Staff.pm | 6 | ||||
-rw-r--r-- | lib/VNDB/Handler/VNPage.pm | 4 |
6 files changed, 24 insertions, 10 deletions
diff --git a/lib/VNDB/DB/VN.pm b/lib/VNDB/DB/VN.pm index 9f0e4b1e..77f9029b 100644 --- a/lib/VNDB/DB/VN.pm +++ b/lib/VNDB/DB/VN.pm @@ -111,7 +111,7 @@ sub dbVNGet { my $tag_ids = $o{tag_inc} && join ',', ref $o{tag_inc} ? @{$o{tag_inc}} : $o{tag_inc}; my @select = ( # see https://rt.cpan.org/Ticket/Display.html?id=54224 for the cast on c_languages and c_platforms - qw|v.id v.locked v.hidden v.c_released v.c_languages::text[] v.c_platforms::text[] v.title v.original v.rgraph|, + qw|v.id v.locked v.hidden v.c_released v.c_languages::text[] v.c_olang::text[] v.c_platforms::text[] v.title v.original v.rgraph|, $o{what} =~ /extended/ ? ( qw|v.alias v.image v.img_nsfw v.length v.desc v.l_wp v.l_encubed v.l_renai v.l_wikidata| ) : (), $o{what} =~ /relgraph/ ? 'vg.svg' : (), diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm index 32830459..3a1d9261 100644 --- a/lib/VNDB/Func.pm +++ b/lib/VNDB/Func.pm @@ -14,6 +14,7 @@ our @EXPORT = (@VNDBUtil::EXPORT, 'bb2html', 'bb2text', qw| clearfloat cssicon tagscore minage fil_parse fil_serialize parenttags childtags charspoil imgpath imgurl fmtvote fmtmedia fmtvnlen fmtage fmtdatestr fmtdate fmtrating fmtspoil + lang_attr json_encode json_decode script_json form_compare |); @@ -276,6 +277,19 @@ sub fmtspoil { } +# Generates a HTML 'lang' attribute given a list of possible languages. +# This is used for the 'original language' field, which we can safely assume is not used for latin-alphabet languages. +sub lang_attr { + my @l = ref $_[0] ? $_[0]->@* : @_; + # Choose Japanese, Chinese or Korean (in order of likelyness) if those are in the list. + return (lang => 'ja') if grep $_ eq 'ja', @l; + return (lang => 'zh') if grep $_ eq 'zh', @l; + return (lang => 'ko') if grep $_ eq 'ko', @l; + return (lang => $l[0]) if @l == 1; + () +} + + # JSON::XS::encode_json converts input to utf8, whereas the below functions # operate on wide character strings. Canonicalization is enabled to allow for diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm index ddc992f2..75ca792f 100644 --- a/lib/VNDB/Handler/Producers.pm +++ b/lib/VNDB/Handler/Producers.pm @@ -86,7 +86,7 @@ sub page { div class => 'mainbox'; $self->htmlItemMessage('p', $p); h1 $p->{name}; - h2 class => 'alttitle', $p->{original} if $p->{original}; + h2 class => 'alttitle', lang => $p->{lang}, $p->{original} if $p->{original}; p class => 'center'; txt "$LANGUAGE{$p->{lang}} $PRODUCER_TYPE{$p->{type}}"; if($p->{alias}) { diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm index 4abfb036..88e9bd47 100644 --- a/lib/VNDB/Handler/Releases.pm +++ b/lib/VNDB/Handler/Releases.pm @@ -91,7 +91,7 @@ sub page { [ ani_ero => 'Ero animation', serialize => sub { $ANIMATED{$_[0]}{txt} } ], [ engine => 'Engine' ], [ producers => 'Producers', join => '<br />', split => sub { - map sprintf('<a href="/p%d" title="%s">%s</a> (%s)', $_->{id}, $_->{original}||$_->{name}, shorten($_->{name}, 50), + map sprintf('<a href="/p%d" title="%s">%s</a> (%s)', $_->{id}, xml_escape($_->{original}||$_->{name}), xml_escape(shorten($_->{name}, 50)), join(', ', $_->{developer} ? 'developer' :(), $_->{publisher} ? 'publisher' :()) ), @{$_[0]}; } ], @@ -101,7 +101,7 @@ sub page { div class => 'mainbox release'; $self->htmlItemMessage('r', $r); h1 $r->{title}; - h2 class => 'alttitle', $r->{original} if $r->{original}; + h2 class => 'alttitle', lang_attr($r->{languages}), $r->{original} if $r->{original}; _infotable($self, $r); @@ -138,7 +138,7 @@ sub _infotable { if($r->{original}) { Tr; td 'Original title'; - td $r->{original}; + td lang_attr($r->{languages}), $r->{original}; end; } diff --git a/lib/VNDB/Handler/Staff.pm b/lib/VNDB/Handler/Staff.pm index 5bf9d29f..bcdbb08f 100644 --- a/lib/VNDB/Handler/Staff.pm +++ b/lib/VNDB/Handler/Staff.pm @@ -60,7 +60,7 @@ sub page { div class => 'mainbox staffpage'; $self->htmlItemMessage('s', $s); h1 $s->{name}; - h2 class => 'alttitle', $s->{original} if $s->{original}; + h2 class => 'alttitle', lang => $s->{lang}, $s->{original} if $s->{original}; # info table table class => 'stripe'; @@ -68,7 +68,7 @@ sub page { Tr; td colspan => 2; b style => 'margin-right: 10px', $s->{name}; - b class => 'grayedout', style => 'margin-right: 10px', $s->{original} if $s->{original}; + b class => 'grayedout', style => 'margin-right: 10px', lang => $s->{lang}, $s->{original} if $s->{original}; cssicon "gen $s->{gender}", $GENDER{$s->{gender}} if $s->{gender} ne 'unknown'; end; end; @@ -87,7 +87,7 @@ sub page { td $alias->{original} ? () : (colspan => 2), class => 'key'; txt $alias->{name}; end; - td $alias->{original} if $alias->{original}; + td lang => $s->{lang}, $alias->{original} if $alias->{original}; end; } end; diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm index 2849f820..e1e37f2f 100644 --- a/lib/VNDB/Handler/VNPage.pm +++ b/lib/VNDB/Handler/VNPage.pm @@ -361,7 +361,7 @@ sub page { div class => 'mainbox'; $self->htmlItemMessage('v', $v); h1 $v->{title}; - h2 class => 'alttitle', $v->{original} if $v->{original}; + h2 class => 'alttitle', lang_attr($v->{c_olang}), $v->{original} if $v->{original}; div class => 'vndetails'; @@ -402,7 +402,7 @@ sub page { if($v->{original}) { Tr; td 'Original title'; - td $v->{original}; + td lang_attr($v->{c_olang}), $v->{original}; end; } if($v->{alias}) { |