Bug 8044: (follow-up) fix warning and error messages in translate.pl
authorJulian Maurice <julian.maurice@biblibre.com>
Mon, 20 Aug 2012 08:55:50 +0000 (10:55 +0200)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 5 May 2014 04:26:00 +0000 (04:26 +0000)
CHARSET is now automatically replaced by UTF-8, and 'update' creates the
PO file if it does not exist.

Also do not try to create PO files if POT file creation failed (when
there is no messages to translate for example).

+ add some verbosity
+ add Locale::Maketext and Locale::Maketext::Lexicon to Koha
dependencies

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
C4/Installer/PerlDependencies.pm
misc/translator/LangInstaller.pm

index 428204a..f1ddee3 100644 (file)
@@ -709,6 +709,16 @@ our $PERL_DEPS = {
         required   => 1,
         min_ver    => '2.125',
     },
+    'Locale::Maketext' => {
+        'usage'    => 'Core',
+        'required' => '1',
+        'min_ver'  => '1.19',
+    },
+    'Locale::Maketext::Lexicon' => {
+        'usage'    => 'Core',
+        'required' => '1',
+        'min_ver'  => '0.91',
+    },
 };
 
 1;
index 15efc0b..95fd406 100644 (file)
@@ -70,9 +70,11 @@ sub new {
     $self->{cp}              = `which cp`;
     $self->{msgmerge}        = `which msgmerge`;
     $self->{xgettext}        = `which xgettext`;
+    $self->{sed}             = `which sed`;
     chomp $self->{cp};
     chomp $self->{msgmerge};
     chomp $self->{xgettext};
+    chomp $self->{sed};
 
     # Get all .pref file names
     opendir my $fh, $self->{path_pref_en};
@@ -433,6 +435,7 @@ sub create_tmpl {
 sub create_messages {
     my $self = shift;
 
+    print "Create messages ($self->{lang})\n" if $self->{verbose};
     system
         "$self->{cp} $self->{domain}.pot " .
         "$self->{path_po}/$self->{lang}-$self->{domain}.po";
@@ -441,10 +444,13 @@ sub create_messages {
 sub update_messages {
     my $self = shift;
 
-    system
-        "$self->{msgmerge} -U " .
-        "$self->{path_po}/$self->{lang}-$self->{domain}.po " .
-        "$self->{domain}.pot";
+    my $pofile = "$self->{path_po}/$self->{lang}-$self->{domain}.po";
+    print "Update messages ($self->{lang})\n" if $self->{verbose};
+    if ( not -f $pofile ) {
+        print "File $pofile does not exist\n" if $self->{verbose};
+        $self->create_messages();
+    }
+    system "$self->{msgmerge} -U $pofile $self->{domain}.pot";
 }
 
 sub extract_messages {
@@ -476,6 +482,19 @@ sub extract_messages {
     if (system($xgettext_cmd) != 0) {
         die "system call failed: $xgettext_cmd";
     }
+
+    if ( -f "$Bin/$self->{domain}.pot" ) {
+        my $replace_charset_cmd = "$self->{sed} --in-place " .
+            "$Bin/$self->{domain}.pot " .
+            "--expression='s/charset=CHARSET/charset=UTF-8/'";
+        if (system($replace_charset_cmd) != 0) {
+            die "system call failed: $replace_charset_cmd";
+        }
+    } else {
+        print "No messages found\n" if $self->{verbose};
+        return;
+    }
+    return 1;
 }
 
 sub remove_pot {
@@ -504,14 +523,14 @@ sub get_all_langs {
 sub update {
     my ($self, $files) = @_;
     my @langs = $self->{lang} ? ($self->{lang}) : $self->get_all_langs();
-    $self->extract_messages();
+    my $extract_ok = $self->extract_messages();
     for my $lang ( @langs ) {
         $self->set_lang( $lang );
         $self->update_tmpl($files) unless $self->{pref_only};
         $self->update_prefs();
-        $self->update_messages();
+        $self->update_messages() if $extract_ok;
     }
-    $self->remove_pot();
+    $self->remove_pot() if $extract_ok;
 }
 
 
@@ -520,9 +539,10 @@ sub create {
     return unless $self->{lang};
     $self->create_tmpl($files) unless $self->{pref_only};
     $self->create_prefs();
-    $self->extract_messages();
-    $self->create_messages();
-    $self->remove_pot();
+    if ($self->extract_messages()) {
+        $self->create_messages();
+        $self->remove_pot();
+    }
 }