Merge remote branch 'intrigeri/po'

master
Joey Hess 2010-07-24 05:22:33 -04:00
commit 52f09a63a1
2 changed files with 20 additions and 13 deletions

View File

@ -164,7 +164,7 @@ sub checkconfig () {
map { map {
islanguagecode($_) islanguagecode($_)
or error(sprintf(gettext("%s is not a valid language code"), $_)); or error(sprintf(gettext("%s is not a valid language code"), $_));
} ($config{po_master_language}{code}, keys %{$config{po_slave_languages}}); } ($config{po_master_language}{code}, @slavelanguages);
if (! exists $config{po_translatable_pages} || if (! exists $config{po_translatable_pages} ||
! defined $config{po_translatable_pages}) { ! defined $config{po_translatable_pages}) {
@ -193,7 +193,7 @@ sub checkconfig () {
next if $underlay=~/^locale\//; next if $underlay=~/^locale\//;
# Underlays containing the po files for slave languages. # Underlays containing the po files for slave languages.
foreach my $ll (keys %{$config{po_slave_languages}}) { foreach my $ll (@slavelanguages) {
add_underlay("po/$ll/$underlay") add_underlay("po/$ll/$underlay")
if -d "$config{underlaydirbase}/po/$ll/$underlay"; if -d "$config{underlaydirbase}/po/$ll/$underlay";
} }
@ -615,7 +615,7 @@ sub mybeautify_urlpath ($) {
$res =~ s!/\Qindex.$config{htmlext}\E$!/!; $res =~ s!/\Qindex.$config{htmlext}\E$!/!;
map { map {
$res =~ s!/\Qindex.$_.$config{htmlext}\E$!/!; $res =~ s!/\Qindex.$_.$config{htmlext}\E$!/!;
} (keys %{$config{po_slave_languages}}); } @slavelanguages;
} }
return $res; return $res;
} }
@ -852,7 +852,7 @@ sub otherlanguages_codes ($) {
return \@ret unless istranslation($page) || istranslatable($page); return \@ret unless istranslation($page) || istranslatable($page);
my $curlang=lang($page); my $curlang=lang($page);
foreach my $lang foreach my $lang
($config{po_master_language}{code}, keys %{$config{po_slave_languages}}) { ($config{po_master_language}{code}, @slavelanguages) {
next if $lang eq $curlang; next if $lang eq $curlang;
push @ret, $lang; push @ret, $lang;
} }
@ -890,7 +890,7 @@ sub pofile ($$) {
sub pofiles ($) { sub pofiles ($) {
my $masterfile=shift; my $masterfile=shift;
return map pofile($masterfile, $_), (keys %{$config{po_slave_languages}}); return map pofile($masterfile, $_), @slavelanguages;
} }
sub refreshpot ($) { sub refreshpot ($) {
@ -1048,7 +1048,7 @@ sub ishomepage ($) {
my $page = shift; my $page = shift;
return 1 if $page eq 'index'; return 1 if $page eq 'index';
map { return 1 if $page eq 'index.'.$_ } keys %{$config{po_slave_languages}}; map { return 1 if $page eq 'index.'.$_ } @slavelanguages;
return undef; return undef;
} }
@ -1063,7 +1063,7 @@ sub deletetranslations ($) {
if (-e $absfile && ! -l $absfile && ! -d $absfile) { if (-e $absfile && ! -l $absfile && ! -d $absfile) {
push @todelete, $file; push @todelete, $file;
} }
} keys %{$config{po_slave_languages}}; } @slavelanguages;
map { map {
if ($config{rcs}) { if ($config{rcs}) {

19
t/po.t
View File

@ -17,7 +17,7 @@ BEGIN {
} }
} }
use Test::More tests => 65; use Test::More tests => 68;
BEGIN { use_ok("IkiWiki"); } BEGIN { use_ok("IkiWiki"); }
@ -42,8 +42,8 @@ $config{po_slave_languages} = {
$config{po_translatable_pages}='index or test1 or test2 or translatable'; $config{po_translatable_pages}='index or test1 or test2 or translatable';
$config{po_link_to}='negotiated'; $config{po_link_to}='negotiated';
IkiWiki::loadplugins(); IkiWiki::loadplugins();
IkiWiki::checkconfig();
ok(IkiWiki::loadplugin('po'), "po plugin loaded"); ok(IkiWiki::loadplugin('po'), "po plugin loaded");
IkiWiki::checkconfig();
### seed %pagesources and %pagecase ### seed %pagesources and %pagecase
$pagesources{'index'}='index.mdwn'; $pagesources{'index'}='index.mdwn';
@ -91,6 +91,13 @@ ok(! IkiWiki::Plugin::po::istranslatable('test3'), "test3 is not translatable");
ok(! IkiWiki::Plugin::po::istranslation('test3'), "test3 is not a translation"); ok(! IkiWiki::Plugin::po::istranslation('test3'), "test3 is not a translation");
} }
### pofiles
my @pofiles = IkiWiki::Plugin::po::pofiles(srcfile("index.mdwn"));
ok( @pofiles, "pofiles is defined");
ok( @pofiles == 2, "pofiles has correct size");
is_deeply(\@pofiles, ["$config{srcdir}/index.es.po", "$config{srcdir}/index.fr.po"], "pofiles content is correct");
### links ### links
require IkiWiki::Render; require IkiWiki::Render;
@ -111,8 +118,8 @@ $config{po_link_to}='negotiated';
$msgprefix="links (po_link_to=negotiated)"; $msgprefix="links (po_link_to=negotiated)";
refresh_n_scan('index.mdwn', 'translatable.mdwn', 'nontranslatable.mdwn'); refresh_n_scan('index.mdwn', 'translatable.mdwn', 'nontranslatable.mdwn');
is_deeply(\@{$links{'index'}}, ['translatable', 'nontranslatable'], "$msgprefix index"); is_deeply(\@{$links{'index'}}, ['translatable', 'nontranslatable'], "$msgprefix index");
is_deeply(\@{$links{'index.es'}}, ['translatable.es', 'nontranslatable'], "$msgprefix index.es"); is_deeply(\@{$links{'index.es'}}, ['translatable.es', 'nontranslatable', 'SandBox', 'ikiwiki'], "$msgprefix index.es");
is_deeply(\@{$links{'index.fr'}}, ['translatable.fr', 'nontranslatable'], "$msgprefix index.fr"); is_deeply(\@{$links{'index.fr'}}, ['translatable.fr', 'nontranslatable', 'SandBox', 'ikiwiki'], "$msgprefix index.fr");
is_deeply(\@{$links{'translatable'}}, ['nontranslatable'], "$msgprefix translatable"); is_deeply(\@{$links{'translatable'}}, ['nontranslatable'], "$msgprefix translatable");
is_deeply(\@{$links{'translatable.es'}}, ['nontranslatable'], "$msgprefix translatable.es"); is_deeply(\@{$links{'translatable.es'}}, ['nontranslatable'], "$msgprefix translatable.es");
is_deeply(\@{$links{'translatable.fr'}}, ['nontranslatable'], "$msgprefix translatable.fr"); is_deeply(\@{$links{'translatable.fr'}}, ['nontranslatable'], "$msgprefix translatable.fr");
@ -122,8 +129,8 @@ $config{po_link_to}='current';
$msgprefix="links (po_link_to=current)"; $msgprefix="links (po_link_to=current)";
refresh_n_scan('index.mdwn', 'translatable.mdwn', 'nontranslatable.mdwn'); refresh_n_scan('index.mdwn', 'translatable.mdwn', 'nontranslatable.mdwn');
is_deeply(\@{$links{'index'}}, ['translatable', 'nontranslatable'], "$msgprefix index"); is_deeply(\@{$links{'index'}}, ['translatable', 'nontranslatable'], "$msgprefix index");
is_deeply(\@{$links{'index.es'}}, [ map bestlink('index.es', $_), ('translatable.es', 'nontranslatable')], "$msgprefix index.es"); is_deeply(\@{$links{'index.es'}}, [ (map bestlink('index.es', $_), ('translatable.es', 'nontranslatable')), 'SandBox', 'ikiwiki'], "$msgprefix index.es");
is_deeply(\@{$links{'index.fr'}}, [ map bestlink('index.fr', $_), ('translatable.fr', 'nontranslatable')], "$msgprefix index.fr"); is_deeply(\@{$links{'index.fr'}}, [ (map bestlink('index.fr', $_), ('translatable.fr', 'nontranslatable')), 'SandBox', 'ikiwiki'], "$msgprefix index.fr");
is_deeply(\@{$links{'translatable'}}, [bestlink('translatable', 'nontranslatable')], "$msgprefix translatable"); is_deeply(\@{$links{'translatable'}}, [bestlink('translatable', 'nontranslatable')], "$msgprefix translatable");
is_deeply(\@{$links{'translatable.es'}}, ['nontranslatable'], "$msgprefix translatable.es"); is_deeply(\@{$links{'translatable.es'}}, ['nontranslatable'], "$msgprefix translatable.es");
is_deeply(\@{$links{'translatable.fr'}}, ['nontranslatable'], "$msgprefix translatable.fr"); is_deeply(\@{$links{'translatable.fr'}}, ['nontranslatable'], "$msgprefix translatable.fr");