Bug 23634: (QA follow-up) Our PUT is really a PATCH
[koha.git] / misc / translator / translate
blobf53dd464ff2276fe8ab562a51bcb3f90b0e1dbc6
1 #!/usr/bin/perl
3 # Copyright (C) 2010 Tamil s.a.r.l.
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 package Main;
22 use FindBin;
23 use lib $FindBin::Bin;
25 use strict;
26 use warnings;
28 use LangInstaller;
29 use Getopt::Long;
30 use Pod::Usage;
32 use Koha::Caches;
35 my $verbose = 0;
36 my $pref = 0;
37 my $all = 0;
38 my @files;
39 GetOptions(
40 'v|verbose' => \$verbose,
41 'p' => \$pref,
42 'f:s' => \@files,
43 'a|all' => \$all,
47 sub usage {
48 pod2usage( -verbose => 2 );
49 exit;
53 usage() if $#ARGV != 1 && $#ARGV != 0;
55 my ($cmd, $lang) = @ARGV;
56 $cmd = lc $cmd;
57 if ( $cmd =~ /^(create|install|update|compress|uncompress)$/ ) {
58 my $installer = LangInstaller->new( $lang, $pref, $verbose );
59 if ( $cmd ne 'create' and $lang and not grep( {$_ eq $lang} @{ $installer->{langs} } ) ) {
60 print "Unsupported language: $lang\n";
61 exit;
63 if ( $all ) {
64 usage() if $cmd eq 'create';
65 for my $lang ( @{$installer->{langs}} ) {
66 $installer->set_lang( $lang );
67 $installer->$cmd(\@files);
70 else {
71 $installer->$cmd(\@files);
74 Koha::Caches->get_instance()->flush_all if $cmd ne 'update';
76 else {
77 usage();
82 =head1 NAME
84 translate - Handle templates and preferences translation
86 =head1 SYNOPSYS
88 translate create fr-FR
89 translate update fr-FR
90 translate install fr-FR
91 translate install fr-FR -f search -f memberentry
92 translate -p install fr-FR
93 translate install
94 translate compress [fr-FR]
95 translate uncompress [fr-FR]
97 =head1 DESCRIPTION
99 In Koha, three categories of information are translated based on standard GNU
100 .po files: opac templates pages, intranet templates and system preferences. The
101 script is a wrapper. It allows to quickly create/update/install .po files for a
102 given language or for all available languages.
104 =head1 USAGE
106 Use the -v or --verbose parameter to make translator more verbose.
108 =over
110 =item translate create F<lang>
112 Create 3 .po files in F</misc/translator/po> subdirectory: (1) from opac pages
113 templates, (2) intranet templates, and (3) from preferences. English 'en'
114 version of templates and preferences are used as references.
116 =over
118 =item F<lang>-opac-{theme}.po
120 Contains extracted text from english (en) OPAC templates found in
121 <KOHA_ROOT>/koha-tmpl/opac-tmpl/{theme}/en/ directory.
123 =item F<lang>-intranet.po
125 Contains extracted text from english (en) intranet templates found in
126 <KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/ directory.
128 =item F<lang>-pref.po
130 Contains extracted text from english (en) preferences. They are found in files
131 located in <KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/admin/preferences
132 directory.
134 =back
136 =item translate [-p] update F<lang>
138 Update .po files in F<po> directory, named F<lang>-*.po. Without F<lang>, all
139 available languages are updated. With -p option, only preferences .po file is
140 updated.
142 =item translate [-p|-f] install F<lang>
144 Use .po files to translate the english version of templates and preferences files
145 and copy those files in the appropriate directory. Without F<lang>, all
146 available languages are installed. With -p option, only preferences .po file is
147 updated.
149 With -f parameter (repeatable) you can specify specific files to translate. For
150 example, -f search will translate all templates containing 'search'.
152 =item translate compress F<lang>
154 Compress .po files in F<po> directory, named F<lang>-*.po. Without F<lang>, files
155 from all available languages are compressed.
157 =item translate uncompress F<lang>
159 Uncompress .po.gz files in F<po> directory, named F<lang>-*.po.gz. Without F<lang>,
160 files from all available languages are uncompressed.
163 =back
165 =cut