diff options
author | intrigeri <intrigeri@boum.org> | 2008-11-10 21:19:21 +0100 |
---|---|---|
committer | intrigeri <intrigeri@boum.org> | 2008-11-10 21:19:21 +0100 |
commit | b4ab0d0b9eae7b2204b8ea8e1ee70e63117b23ab (patch) | |
tree | 43ac0c9588e95e128541e6410b4aa397fcce40f8 | |
parent | c5513548c9d43923829c9bc2080a3e1bb9e2cac0 (diff) |
po: rewrote otherlanguagesloop()
It is now more elegant IMHO, and the output is now sorted according to the
language name (instead of code).
Signed-off-by: intrigeri <intrigeri@boum.org>
-rw-r--r-- | IkiWiki/Plugin/po.pm | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index eabc96977..1754260ed 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -98,8 +98,8 @@ sub getsetup () { #{{{ } #}}} sub islanguagecode ($) { #{{{ - my $code=shift; - return ($code =~ /^[a-z]{2}$/); + my $code=shift; + return ($code =~ /^[a-z]{2}$/); } #}}} sub checkconfig () { #{{{ @@ -483,39 +483,44 @@ sub percenttranslated ($) { #{{{ return $percent; } #}}} +sub languagename ($) { #{{{ + my $code=shift; + + return $config{po_master_language}{name} + if $code eq $config{po_master_language}{code}; + return $config{po_slave_languages}{$code} + if defined $config{po_slave_languages}{$code}; + return; +} #}}} + sub otherlanguagesloop ($) { #{{{ my $page=shift; my @ret; - if (istranslatable($page)) { - my %otherpages=%{otherlanguages($page)}; - while (my ($lang, $translation) = each %otherpages) { + my %otherpages=%{otherlanguages($page)}; + while (my ($lang, $otherpage) = each %otherpages) { + if (istranslation($page) && masterpage($page) eq $otherpage) { push @ret, { - url => urlto($translation, $page), + url => urlto_with_orig_beautiful_urlpath($otherpage, $page), code => $lang, - language => $config{po_slave_languages}{$lang}, - percent => percenttranslated($translation), + language => languagename($lang), + master => 1, }; } - } - elsif (istranslation($page)) { - my ($masterpage, $curlang) = (masterpage($page), lang($page)); - push @ret, { - url => urlto_with_orig_beautiful_urlpath($masterpage, $page), - code => $config{po_master_language}{code}, - language => $config{po_master_language}{name}, - master => 1, - }; - foreach my $lang (sort keys %{$translations{$masterpage}}) { + else { push @ret, { - url => urlto($translations{$masterpage}{$lang}, $page), + url => urlto($otherpage, $page), code => $lang, - language => $config{po_slave_languages}{$lang}, - percent => percenttranslated($translations{$masterpage}{$lang}), - } unless ($lang eq $curlang); + language => languagename($lang), + percent => percenttranslated($otherpage), + } } } - return @ret; + return sort { + return -1 if $a->{code} eq $config{po_master_language}{code}; + return 1 if $b->{code} eq $config{po_master_language}{code}; + return $a->{language} cmp $b->{language}; + } @ret; } #}}} sub pagetemplate (@) { #{{{ |