print $doc->toString;
}
+sub get_ordinal {
+ my ($num, $locale) = @_;
+ my $translation = $translation_mapping{$locale} // 'en';
+
+ if ($translation eq 'no') {
+ return $num . ".";
+ } elsif ($translation eq 'en') {
+ # http://en.wikipedia.org/wiki/English_numerals#Ordinal_numbers
+ my $units = $num % 10;
+ my $tens = (($num - $units) / 10) % 10;
+ if ($tens == 1) {
+ return $num . "th";
+ } elsif ($units == 1) {
+ return $num . "st";
+ } elsif ($units == 2) {
+ return $num . "nd";
+ } elsif ($units == 3) {
+ return $num . "rd";
+ } else {
+ return $num . "th";
+ }
+ } else {
+ die "Missing ordinal strategy for locale $locale";
+ }
+}
+
1;
# Make list of ranks. (Relegation is handled specially.)
my @ranks = ();
for my $i (1..$num_games) {
- push @ranks, { 'th' => "$i." };
+ push @ranks, { 'th' => wloh_common::get_ordinal($i, $locale) };
}
my @players = ();
print CGI->header(-type=>'text/html; charset=utf-8', -expires=>'+5m');
wloh_common::process_template('scenario-not-found', $locale, {
'#nick' => $player_name,
- '#rank' => sprintf("%d.", $match_position + 1)
+ '#rank' => wloh_common::get_ordinal($match_position + 1, $locale)
});
} else {
print CGI->header(-type=>'text/html; charset=utf-8', -expires=>'+5m');
wloh_common::process_template('scenario', $locale, {
'#nick' => $player_name,
- '#rank' => sprintf("%d.", $match_position + 1),
+ '#rank' => wloh_common::get_ordinal($match_position + 1, $locale),
'#results' => \@scenario
});
}
while (my $ref = $q->fetchrow_hashref) {
my %division = ();
- $division{'#rank'} = sprintf "%d.", $ref->{'divisjon'};
+ $division{'#rank'} = wloh_common::get_ordinal($ref->{'divisjon'}, $locale);
$division{'#average'} = sprintf "%.1f", $ref->{'avg_rating'};
$division{'#stddev'} = sprintf "%.1f", $ref->{'stddev_rating'};
while (my $ref = $q->fetchrow_hashref) {
my %player = ();
- $player{'#rank'} = sprintf "%d.", ++$i;
+ $player{'#rank'} = wloh_common::get_ordinal(++$i, $locale);
$player{'#user'} = Encode::decode_utf8($ref->{'navn'});
$player{'#user/href'} = sprintf "http://wordfeud.aasmul.net/bruker-%d", $ref->{'id'};
$player{'#rating'} = sprintf "%.1f", $ref->{'rating'};