From bd103811033fa174d24d8dc5b84f0694fd9055ee Mon Sep 17 00:00:00 2001 From: intrigeri Date: Wed, 31 Dec 2008 00:38:47 +0100 Subject: [PATCH] po: delete translations of deleted master pages Signed-off-by: intrigeri --- IkiWiki/Plugin/po.pm | 71 +++++++++++++++++++++++++++++++------------- doc/plugins/po.mdwn | 17 +++++------ 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index e25532a0a..515809f70 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -389,26 +389,9 @@ sub change(@) { #{{{ } if ($updated_po_files) { - # Check staged changes in. - if ($config{rcs}) { - IkiWiki::disable_commit_hook(); - IkiWiki::rcs_commit_staged(gettext("updated PO files"), - "IkiWiki::Plugin::po::change", "127.0.0.1"); - IkiWiki::enable_commit_hook(); - IkiWiki::rcs_update(); - } - # Reinitialize module's private variables. - resetalreadyfiltered(); - resettranslationscache(); - flushmemoizecache(); - # Trigger a wiki refresh. - require IkiWiki::Render; - # without preliminary saveindex/loadindex, refresh() - # complains about a lot of uninitialized variables - IkiWiki::saveindex(); - IkiWiki::loadindex(); - IkiWiki::refresh(); - IkiWiki::saveindex(); + commit_and_refresh( + gettext("updated PO files"), + "IkiWiki::Plugin::po::change"); } } #}}} @@ -792,7 +775,53 @@ sub homepageurl (;$) { #{{{ sub deletetranslations ($) { #{{{ my $deletedmasterfile=shift; - debug "po(deletetranslations): TODO: delete translations of $deletedmasterfile"; + my $deletedmasterpage=pagename($deletedmasterfile); + my @todelete; + map { + my $file = newpagefile($deletedmasterpage.'.'.$_, 'po'); + my $absfile = "$config{srcdir}/$file"; + if (-e $absfile && ! -l $absfile && ! -d $absfile) { + push @todelete, $file; + } + } keys %{$config{po_slave_languages}}; + + map { + if ($config{rcs}) { + IkiWiki::rcs_remove($_); + } + else { + IkiWiki::prune("$config{srcdir}/$_"); + } + } @todelete; + + if (scalar @todelete) { + commit_and_refresh( + gettext("removed obsolete PO files"), + "IkiWiki::Plugin::po::deletetranslations"); + } +} #}}} + +sub commit_and_refresh ($$) { #{{{ + my ($msg, $author) = (shift, shift); + + if ($config{rcs}) { + IkiWiki::disable_commit_hook(); + IkiWiki::rcs_commit_staged($msg, $author, "127.0.0.1"); + IkiWiki::enable_commit_hook(); + IkiWiki::rcs_update(); + } + # Reinitialize module's private variables. + resetalreadyfiltered(); + resettranslationscache(); + flushmemoizecache(); + # Trigger a wiki refresh. + require IkiWiki::Render; + # without preliminary saveindex/loadindex, refresh() + # complains about a lot of uninitialized variables + IkiWiki::saveindex(); + IkiWiki::loadindex(); + IkiWiki::refresh(); + IkiWiki::saveindex(); } #}}} # ,---- diff --git a/doc/plugins/po.mdwn b/doc/plugins/po.mdwn index ea1e89278..722a7c66c 100644 --- a/doc/plugins/po.mdwn +++ b/doc/plugins/po.mdwn @@ -562,11 +562,9 @@ Creating new pages on the web See [[contrib/po|contrib/po]]. -Deleting/renaming pages ------------------------ +Renaming pages +-------------- -- When a master page is renamed or deleted, its translations (and the - pot file?) must be renamed or deleted accordingly. - Renaming a translation should be forbidden. Robustness tests @@ -596,16 +594,17 @@ Robustness tests ### Deleting pages -- removing a master page via RCS +- removing a master page via RCS: **OK** - removing a translation via RCS: **OK** -- removing a master page via CGI +- removing a master page via CGI: **OK** - removing a translation via CGI: **OK** ### Renaming pages -- renaming a master page via RCS -- renaming a master page and its translations via RCS -- renaming a master page via CGI +- renaming a master page via RCS: **OK** (but the old translations + are lost, because not all RCS track file renaming) +- renaming a master page and its translations via RCS: **OK** +- renaming a master page via CGI: **OK** - renaming a translation via RCS - renaming a translation via CGI -- 2.39.5