po: Auto-upgrade old format settings to new formats when writing setup file.
authorJoey Hess <joey@kitenet.net>
Fri, 10 Sep 2010 18:04:43 +0000 (14:04 -0400)
committerJoey Hess <joey@kitenet.net>
Fri, 10 Sep 2010 18:04:43 +0000 (14:04 -0400)
IkiWiki/Plugin/po.pm
debian/changelog

index a233fb5affee8927c2d667244c170bf406982403..d920d36486a7aa88dfbafc5d8bcbcd1049827812 100644 (file)
@@ -30,6 +30,7 @@ my %translations;
 my @origneedsbuild;
 my %origsubs;
 my @slavelanguages; # language codes ordered as in config po_slave_languages
 my @origneedsbuild;
 my %origsubs;
 my @slavelanguages; # language codes ordered as in config po_slave_languages
+my %slavelanguages; # language code to name lookup
 
 memoize("istranslatable");
 memoize("_istranslation");
 
 memoize("istranslatable");
 memoize("_istranslation");
@@ -138,6 +139,7 @@ sub checkconfig () {
                else {
                        $master_language_code=$config{po_master_language}{code};
                        $master_language_name=$config{po_master_language}{name};
                else {
                        $master_language_code=$config{po_master_language}{code};
                        $master_language_name=$config{po_master_language}{name};
+                       $config{po_master_language}=joinlangpair($master_language_code, $master_language_name);
                }
        }
        if (! defined $master_language_code) {
                }
        }
        if (! defined $master_language_code) {
@@ -148,23 +150,25 @@ sub checkconfig () {
        }
 
        if (ref $config{po_slave_languages} eq 'ARRAY') {
        }
 
        if (ref $config{po_slave_languages} eq 'ARRAY') {
-               my %slaves;
                foreach my $pair (@{$config{po_slave_languages}}) {
                        my ($code, $name)=splitlangpair($pair);
                        if (defined $code) {
                                push @slavelanguages, $code;
                foreach my $pair (@{$config{po_slave_languages}}) {
                        my ($code, $name)=splitlangpair($pair);
                        if (defined $code) {
                                push @slavelanguages, $code;
-                               $slaves{$code} = $name;
+                               $slavelanguages{$code} = $name;
                        }
                }
                        }
                }
-               $config{po_slave_languages} = \%slaves;
        }
        elsif (ref $config{po_slave_languages} eq 'HASH') {
        }
        elsif (ref $config{po_slave_languages} eq 'HASH') {
+               %slavelanguages=%{$config{po_slave_languages}};
                @slavelanguages = sort {
                        $config{po_slave_languages}->{$a} cmp $config{po_slave_languages}->{$b};
                @slavelanguages = sort {
                        $config{po_slave_languages}->{$a} cmp $config{po_slave_languages}->{$b};
-               } keys %{$config{po_slave_languages}};
+               } keys %slavelanguages;
+               $config{po_slave_languages}=[
+                       map { joinlangpair($_, $slavelanguages{$_}) } @slavelanguages
+               ]
        }
 
        }
 
-       delete $config{po_slave_languages}{$master_language_code};
+       delete $slavelanguages{$master_language_code};
 
        map {
                islanguagecode($_)
 
        map {
                islanguagecode($_)
@@ -797,7 +801,7 @@ sub _istranslation ($) {
        return 0 unless defined $masterpage && defined $lang
                         && length $masterpage && length $lang
                         && defined $pagesources{$masterpage}
        return 0 unless defined $masterpage && defined $lang
                         && length $masterpage && length $lang
                         && defined $pagesources{$masterpage}
-                        && defined $config{po_slave_languages}{$lang};
+                        && defined $slavelanguages{$lang};
 
        return (maybe_add_leading_slash($masterpage, $hasleadingslash), $lang)
                if istranslatable($masterpage);
 
        return (maybe_add_leading_slash($masterpage, $hasleadingslash), $lang)
                if istranslatable($masterpage);
@@ -1015,8 +1019,8 @@ sub languagename ($) {
 
        return $master_language_name
                if $code eq $master_language_code;
 
        return $master_language_name
                if $code eq $master_language_code;
-       return $config{po_slave_languages}{$code}
-               if defined $config{po_slave_languages}{$code};
+       return $slavelanguages{$code}
+               if defined $slavelanguages{$code};
        return;
 }
 
        return;
 }
 
@@ -1252,6 +1256,13 @@ sub splitlangpair ($) {
        return $code, $name;
 }
 
        return $code, $name;
 }
 
+sub joinlangpair ($$) {
+       my $code=shift;
+       my $name=shift;
+
+       return "$code|$name";
+}
+
 # ,----
 # | PageSpecs
 # `----
 # ,----
 # | PageSpecs
 # `----
index 72b220a4fe1a528708d003470b2dd52f300b3e79..4b61a12b01bb227343e303af629d78a51fa7e7c8 100644 (file)
@@ -10,6 +10,8 @@ ikiwiki (3.20100832) UNRELEASED; urgency=low
   * po: Make the po_master_language use a langpair like "en|English",
     so it can be configured via the web.
   * po: Allow enabling via web setup.
   * po: Make the po_master_language use a langpair like "en|English",
     so it can be configured via the web.
   * po: Allow enabling via web setup.
+  * po: Auto-upgrade old format settings to new formats when writing
+    setup file.
 
  -- Joey Hess <joeyh@debian.org>  Tue, 07 Sep 2010 12:08:05 -0400
 
 
  -- Joey Hess <joeyh@debian.org>  Tue, 07 Sep 2010 12:08:05 -0400