From 2fdc32b890198bfced204fe3953028aa7ea8d32b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Demians?= Date: Tue, 14 May 2013 13:01:56 +0200 Subject: [PATCH] Bug 10214 Add header to syspref po files With this patch, header is created when creating a new syspref .po file for a new language (translate create), and is added if it doesn't already exist when updating an existing language (translate update). To test: (1) Create a new language syspref file: ./translate create -p xx-XX Check that there is an header (2) Update an existing syspref file without header: ./translate update fr-FR Check that fr-FR-pref.po has a header (3) Update an existing syspref file with header: Modify fr-FR-pref.po. Add an email, or whatever. ./translate update fr-FR Check that fr-FR-pref.po has a header with the manual modification --- misc/translator/LangInstaller.pm | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-) diff --git a/misc/translator/LangInstaller.pm b/misc/translator/LangInstaller.pm index 00daaf4..e5371e6 100644 --- a/misc/translator/LangInstaller.pm +++ b/misc/translator/LangInstaller.pm @@ -29,6 +29,19 @@ use FindBin qw( $Bin ); $YAML::Syck::ImplicitTyping = 1; +# Default file header for .po syspref files +my $default_pref_po_header = Locale::PO->new(-msgid => '', -msgstr => + "Project-Id-Version: PACKAGE VERSION\\n" . + "PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\\n" . + "Last-Translator: FULL NAME \\n" . + "Language-Team: Koha Translate List \\n" . + "MIME-Version: 1.0\\n" . + "Content-Type: text/plain; charset=UTF-8\\n" . + "Content-Transfer-Encoding: 8bit\\n" . + "Plural-Forms: nplurals=2; plural=(n > 1);\\n" +); + + sub set_lang { my ($self, $lang) = @_; @@ -52,7 +65,7 @@ sub new { $self->{verbose} = $verbose; $self->{process} = "$Bin/tmpl_process3.pl " . ($verbose ? '' : '-q'); $self->{path_po} = "$Bin/po"; - $self->{po} = {}; + $self->{po} = { '' => $default_pref_po_header }; # Get all .pref file names opendir my $fh, $self->{path_pref_en}; @@ -222,8 +235,13 @@ sub get_po_from_prefs { sub save_po { my $self = shift; + + # Create file header if it doesn't already exist + my $po = $self->{po}; + $po->{''} ||= $default_pref_po_header; + # Write .po entries into a file put in Koha standard po directory - Locale::PO->save_file_fromhash( $self->po_filename, $self->{po} ); + Locale::PO->save_file_fromhash( $self->po_filename, $po ); say "Saved in file: ", $self->po_filename if $self->{verbose}; } -- 1.7.2.5