Bug 17600: Standardize our EXPORT_OK
[koha.git] / misc / translator / translate
1 #!/usr/bin/perl
2
3 # Copyright (C) 2010 Tamil s.a.r.l.
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
16 #
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>.
19
20 package Main;
21
22 use FindBin;
23 use lib $FindBin::Bin;
24
25 use strict;
26 use warnings;
27
28 use LangInstaller;
29 use Getopt::Long;
30 use Pod::Usage;
31
32 use Koha::Caches;
33
34
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,
44 );
45
46
47 sub usage {
48     pod2usage( -verbose => 2 );
49     exit;
50 }
51
52
53 usage() if $#ARGV != 1 && $#ARGV != 0;
54
55 my ($cmd, $lang) = @ARGV;
56 $cmd = lc $cmd;
57 if ( $cmd =~ /^(install|compress|uncompress)$/ ) {
58     my $installer = LangInstaller->new( $lang, $pref, $verbose );
59     if ( $lang and not grep( {$_ eq $lang} @{ $installer->{langs} } ) ) {
60         print "Unsupported language: $lang\n";
61         exit;
62     }
63     if ( $all ) {
64         for my $lang ( @{$installer->{langs}} ) {
65             $installer->set_lang( $lang );
66             $installer->$cmd(\@files);
67         }
68     }
69     else {
70         $installer->$cmd(\@files);
71     }
72
73     Koha::Caches->get_instance()->flush_all;
74 } elsif ($cmd eq 'create' or $cmd eq 'update') {
75     my $command = "gulp po:$cmd";
76     $command .= " --silent" if (!$verbose);
77     $command .= " --lang $lang" if ($lang);
78
79     if ($verbose) {
80         print STDERR "Deprecation notice: PO creation and update are now gulp tasks. See docs/development/internationalization.md\n";
81         print STDERR "Running `$command`\n";
82     }
83
84     system($command);
85 } else {
86     usage();
87 }
88
89
90
91 =head1 NAME
92
93 translate - Handle templates and preferences translation
94
95 =head1 SYNOPSYS
96
97   translate install fr-FR
98   translate install fr-FR -f search -f memberentry
99   translate -p install fr-FR
100   translate compress [fr-FR]
101   translate uncompress [fr-FR]
102
103 =head1 DESCRIPTION
104
105 In Koha, three categories of information are translated based on standard GNU
106 .po files: opac templates pages, intranet templates and system preferences. The
107 script is a wrapper. It allows to quickly install .po files for a
108 given language or for all available languages.
109
110 =head1 USAGE
111
112 Use the -v or --verbose parameter to make translator more verbose.
113
114 =over
115
116 =item translate [-p|-f] install F<lang>
117
118 Use .po files to translate the english version of templates and preferences files
119 and copy those files in the appropriate directory. Without F<lang>, all
120 available languages are installed. With -p option, only preferences .po file is
121 updated.
122
123 With -f parameter (repeatable) you can specify specific files to translate. For
124 example, -f search will translate all templates containing 'search'.
125
126 =item translate compress F<lang>
127
128 Compress .po files in F<po> directory, named F<lang>-*.po. Without F<lang>, files
129 from all available languages are compressed.
130
131 =item translate uncompress F<lang>
132
133 Uncompress .po.gz files in F<po> directory, named F<lang>-*.po.gz. Without F<lang>,
134 files from all available languages are uncompressed.
135
136
137 =back
138
139 =cut
140