From 858d21f9db4059da4b53ad698cee44e628e29c28 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 4 May 2012 14:34:13 +0200 Subject: [PATCH 2/2] Bug 8044: Translate basket CSV column names using Koha::I18N This is a test case for new module Koha::I18N. It translate CSV columns headers when you export a basket as CSV. To test: - go to a basket page in staff interface with english interface - click on "Export this basket as CSV" and check that column titles are there and in english - change language and click on the same button. - column titles are still in english - now open a terminal, go to misc/translator and run: ./translate create LANG (e.g. fr-FR) - translate the po misc/translator/po/LANG-messages.po with your favorite po editor. - go back to the navigator and click again on the Export button - column names must be translated, according to the PO file. --- C4/Acquisition.pm | 25 ++++++++++++++++++------- acqui/basket.pl | 4 +++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index e856059..103cac6 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -17,7 +17,6 @@ package C4::Acquisition; # with Koha; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - use strict; use warnings; use Carp; @@ -32,6 +31,7 @@ use C4::SQLHelper qw(InsertInTable); use Time::localtime; use HTML::Entities; +use Text::CSV::Encoded; use vars qw($VERSION @ISA @EXPORT); @@ -230,18 +230,29 @@ Export a basket as CSV =cut sub GetBasketAsCSV { - my ($basketno) = @_; + my ($basketno, $lh) = @_; my $basket = GetBasket($basketno); my @orders = GetOrders($basketno); my $contract = GetContract($basket->{'contractnumber'}); - my $csv = Text::CSV->new(); + my $csv = Text::CSV::Encoded->new(); my $output; - # TODO: Translate headers - my @headers = qw(contractname ordernumber entrydate isbn author title publishercode collectiontitle notes quantity rrp); + my @headers = ( + $lh->maketext('Contract name'), + $lh->maketext('Order number'), + $lh->maketext('Entry date'), + $lh->maketext('ISBN'), + $lh->maketext('Author'), + $lh->maketext('Title'), + $lh->maketext('Publisher code'), + $lh->maketext('Collection title'), + $lh->maketext('Notes'), + $lh->maketext('Quantity'), + $lh->maketext('RRP'), + ); - $csv->combine(@headers); - $output = $csv->string() . "\n"; + $csv->combine(@headers); + $output = $csv->string() . "\n"; my @rows; foreach my $order (@orders) { diff --git a/acqui/basket.pl b/acqui/basket.pl index de66891..284cf39 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -35,6 +35,7 @@ use C4::Members qw/GetMember/; #needed for permissions checking for changing ba use C4::Items; use C4::Suggestions; use Date::Calc qw/Add_Delta_Days/; +use Koha::I18N; =head1 NAME @@ -142,11 +143,12 @@ if ( $op eq 'delete_confirm' ) { print $query->redirect('/cgi-bin/koha/acqui/basketgroup.pl?basketno=' . $basket->{'basketno'} . '&op=attachbasket&booksellerid=' . $booksellerid); # check if we have to "close" a basket before building page } elsif ($op eq 'export') { + my $lh = Koha::I18N->get_handle_from_context($query, 'intranet'); print $query->header( -type => 'text/csv', -attachment => 'basket' . $basket->{'basketno'} . '.csv', ); - print GetBasketAsCSV($query->param('basketno')); + print GetBasketAsCSV($query->param('basketno'), $lh); exit; } elsif ($op eq 'close') { my $confirm = $query->param('confirm') || $confirm_pref eq '2'; -- 1.7.10