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

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>

Comment: Work as described. No errors.

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
All tests and QA script pass.
Also tested that updated pref files can still be installed correctly.
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
This commit is contained in:
Frédéric Demians 2013-05-14 13:01:56 +02:00 committed by Jared Camins-Esakov
parent b11800df0a
commit 9ce862e451

View file

@ -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 <EMAIL\@ADDRESS>\\n" .
"Language-Team: Koha Translate List <koha-translate\@lists.koha-community.org>\\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};
}