+$config{po_link_to}='current';
+$msgprefix="beautify_urlpath (po_link_to=current)";
+is(IkiWiki::beautify_urlpath('test1/index.en.html'), './test1/index.en.html', "$msgprefix test1/index.en.html");
+is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/index.fr.html', "$msgprefix test1/index.fr.html");
+
+### re-scan
+refresh_n_scan('index.mdwn');
+is($pagestate{'index'}{meta}{title}, 'index title');
+is($pagestate{'index.es'}{meta}{title}, 'index title');
+is($pagestate{'index.fr'}{meta}{title}, 'index title');
+refresh_n_scan('test1.mdwn');
+is($pagestate{'test1'}{meta}{title}, 'test1 title');
+is($pagestate{'test1.es'}{meta}{title}, 'test1 title');
+is($pagestate{'test1.fr'}{meta}{title}, 'test1 title');
+
+### istranslatedto
+ok(IkiWiki::Plugin::po::istranslatedto('index', 'es'));
+ok(IkiWiki::Plugin::po::istranslatedto('index', 'fr'));
+ok(! IkiWiki::Plugin::po::istranslatedto('index', 'cz'));
+ok(IkiWiki::Plugin::po::istranslatedto('test1', 'es'));
+ok(IkiWiki::Plugin::po::istranslatedto('test1', 'fr'));
+ok(! IkiWiki::Plugin::po::istranslatedto('test1', 'cz'));
+ok(! IkiWiki::Plugin::po::istranslatedto('nontranslatable', 'es'));
+ok(! IkiWiki::Plugin::po::istranslatedto('nontranslatable', 'cz'));
+ok(! IkiWiki::Plugin::po::istranslatedto('test1.es', 'fr'));
+ok(! IkiWiki::Plugin::po::istranslatedto('test1.fr', 'es'));
+
+### islanguagecode
+ok(IkiWiki::Plugin::po::islanguagecode('en'));
+ok(IkiWiki::Plugin::po::islanguagecode('es'));
+ok(IkiWiki::Plugin::po::islanguagecode('arn'));
+ok(! IkiWiki::Plugin::po::islanguagecode('es_'));
+ok(! IkiWiki::Plugin::po::islanguagecode('_en'));
+
+# Actually render translated pages
+use IkiWiki::Render;
+
+my %output;
+foreach my $page (sort keys %pagesources) {
+ my $source = "$config{srcdir}/$pagesources{$page}";
+ if (-e $source) {
+ IkiWiki::scan($pagesources{$page});
+ }
+}
+
+# This is the most complicated case, so use this while we test rendering
+$config{po_link_to}='current';
+
+foreach my $page (sort keys %pagesources) {
+ my $source = "$config{srcdir}/$pagesources{$page}";
+ if (-e $source && defined IkiWiki::pagetype($pagesources{$page})) {
+ IkiWiki::scan($pagesources{$page});
+ my $content = readfile($source);
+ #print STDERR "-------------------------------------\n";
+ #print STDERR "SOURCE: $page: $content\n";
+ $content = IkiWiki::filter($page, $page, $content);
+ #print STDERR "FILTERED: $page: $content\n";
+ $content = IkiWiki::preprocess($page, $page, $content);
+ #print STDERR "PREPROCESSED: $page: $content\n";
+ $content = IkiWiki::linkify($page, $page, $content);
+ #print STDERR "LINKIFIED: $page: $content\n";
+ $content = IkiWiki::htmlize($page, $page, IkiWiki::pagetype($pagesources{$page}), $content);
+ #print STDERR "HTMLIZED: $page: $content\n";
+ IkiWiki::run_hooks(format => sub {
+ $content=shift->(
+ page => $page,
+ content => $content,
+ );
+ });
+ #print STDERR "FORMATTED: $page: $content\n";
+ $output{$page} = $content;
+ }
+}
+
+like($output{index}, qr{
+ <p>
+ <a\s+href="\./translatable/index\.en\.html">
+ translatable
+ </a>\s*
+ <a\s+href="\./nontranslatable/">
+ nontranslatable
+ </a>
+ </p>
+}sx);
+
+like($output{'index.es'}, qr{
+ <p>
+ <a\s+href="\./translatable/index\.es\.html">
+ translatable
+ </a>\s*
+ <a\s+href="\./nontranslatable/">
+ nontranslatable
+ </a>
+ </p>
+}sx);
+
+like($output{'index.fr'}, qr{
+ <p>
+ <a\s+href="\./translatable/index\.fr\.html">
+ translatable
+ </a>\s*
+ <a\s+href="\./nontranslatable/">
+ nontranslatable
+ </a>
+ </p>
+}sx);
+
+like($output{'translatable'}, qr{
+ <a\s+href="\.\./nontranslatable/">
+ nontranslatable
+ </a>
+}sx);
+
+TODO: {
+local $TODO = 'was [[/]] meant to be a link to the index?';
+unlike($output{'nontranslatable'}, qr{
+ class=.createlink.
+}sx);
+};
+like($output{'nontranslatable'}, qr{
+ <a\s+href="\.\./translatable/index\.en\.html">
+ translatable
+ </a>
+}sx);
+
+like($output{debian911356}, qr{
+ <p>Before\sfirst\sinline</p>
+ \s*
+ <p>English\scontent</p>
+ \s*
+ <p>Between\sinlines</p>
+ \s*
+ <p>English\scontent</p>
+ \s*
+ <p>After\sinlines</p>
+}sx);
+
+like($output{'debian911356.fr'}, qr{
+ <p>Avant\sla\spremière\sinline</p>
+ \s*
+ <p>Contenu\sfrançais</p>
+ \s*
+ <p>Entre\sles\sinlines</p>
+ \s*
+ <p>Contenu\sfrançais</p>
+ \s*
+ <p>Après\sles\sinlines</p>
+}sx);
+
+# Variation of Debian #911356 without using raw inlines.
+like($output{debian911356ish}, qr{
+ <p>Before\sfirst\sinline</p>
+ \s*
+ <!--feedlinks-->
+ \s*
+ <div\sclass="inlinecontent">
+ \s*
+ <h6>debian911356-inlined</h6>
+ \s*
+ <p>English\scontent</p>
+ \s*
+ </div><!--inlinecontent-->
+ \s*
+ <p>Between\sinlines</p>
+ \s*
+ <!--feedlinks-->
+ \s*
+ <div\sclass="inlinecontent">
+ \s*
+ <h6>debian911356-inlined</h6>
+ \s*
+ <p>English\scontent</p>
+ \s*
+ </div><!--inlinecontent-->
+ \s*
+ <p>After\sinlines</p>
+}sx);
+
+like($output{'debian911356ish.fr'}, qr{
+ <p>Avant\sla\spremière\sinline</p>
+ \s*
+ <!--feedlinks-->
+ \s*
+ <div\sclass="inlinecontent">
+ \s*
+ <h6>debian911356-inlined\.fr</h6>
+ \s*
+ <p>Contenu\sfrançais</p>
+ \s*
+ </div><!--inlinecontent-->
+ \s*
+ <p>Entre\sles\sinlines</p>
+ \s*
+ <!--feedlinks-->
+ \s*
+ <div\sclass="inlinecontent">
+ \s*
+ <h6>debian911356-inlined\.fr</h6>
+ \s*
+ <p>Contenu\sfrançais</p>
+ \s*
+ </div><!--inlinecontent-->
+ \s*
+ <p>Après\sles\sinlines</p>
+}sx);
+
+done_testing;