]> sipb.mit.edu Git - ikiwiki.git/commitdiff
create translated underlays in mdwn format
authorJoey Hess <joey@gnu.kitenet.net>
Mon, 20 Jul 2009 04:23:33 +0000 (06:23 +0200)
committerJoey Hess <joey@gnu.kitenet.net>
Mon, 20 Jul 2009 04:23:33 +0000 (06:23 +0200)
These are for use by wikis where the primary language is not English.
On such a wiki, it makes sense to use an underlay has the source for pages
in the native language.

IkiWiki/Plugin/po.pm
Makefile.PL
doc/plugins/po.mdwn
po/po2wiki [new file with mode: 0755]

index 1aa60a14fc891935920352534b88b2f22825fc84..2939bcd9aac1cae6a34847e303bb701ef84fde7e 100644 (file)
@@ -904,10 +904,10 @@ sub otherlanguagesloop ($) {
                }
        }
        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;
+               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 homepageurl (;$) {
index 3db5c0d4063fffb54d7fdabccc61cca6b4ec3cc1..397627c030cc5899fa9d7594c17f2d4366f79be7 100755 (executable)
@@ -64,6 +64,7 @@ underlaypo: ikiwiki.out
        done
        install -d po/underlays/empty
        $(PERL) -Iblib/lib $(extramodules) $(tflag) ikiwiki.out -libdir . -setup underlaypo.setup -refresh
+       PERL5LIB=. po/po2wiki underlaypo.setup
        find po/underlays -name \*.mdwn | xargs rm -f
 
 extra_clean:
index f28c8b188cd1bfbf1dea53b3d5b63ce0b12c1fa3..8e05606f5876a5731ee113abe1874e1ebf9c2bb4 100644 (file)
@@ -286,6 +286,9 @@ The when the user edits index, they get a nice mdwn file to start from.
 
 So, we seem to have two cases, in one po files from the underlay should be
 used, in the other not. Hmm. Support both?
+
+> Update -- I've written po2wiki, which can spit out translated underlays
+> in markdown format. 
 --[[Joey]] 
 
 Duplicate %links ?
diff --git a/po/po2wiki b/po/po2wiki
new file mode 100755 (executable)
index 0000000..031c906
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+# This program uses the po plugin's internals to convert the po files that
+# it generates back into translated wiki source files that can be used as a
+# underlay for a non-English wiki.
+use warnings;
+use strict;
+use IkiWiki;
+
+# Load the passed setup file and initialize ikiwiki config.
+%config=IkiWiki::defaultconfig();
+require IkiWiki::Setup;
+IkiWiki::Setup::load(shift);
+IkiWiki::loadplugins();
+IkiWiki::checkconfig();
+
+require IkiWiki::Render;
+IkiWiki::srcdir_check();
+my ($files, $pages)=IkiWiki::find_src_files();
+
+foreach my $file (@$files) {
+       my $page=pagename($file);
+       $pagesources{$page}=$file; # used by po plugin functions
+}
+
+foreach my $ll (keys %{$config{po_slave_languages}}) {
+       $config{destdir}="po/out.$ll";
+
+       foreach my $file (@$files) {
+               my $page=pagename($file);
+               my ($masterpage, $lang) = IkiWiki::Plugin::po::_istranslation($page);
+               next unless defined $lang && $lang eq $ll;
+               
+               my $content=readfile(srcfile($file));
+               $content=IkiWiki::Plugin::po::po_to_markup($page, $content);
+               writefile($masterpage.".".$config{default_pageext}, $config{destdir}, $content);
+       }
+}