f53dd464ff2276fe8ab562a51bcb3f90b0e1dbc6
[koha-ffzg.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 =~ /^(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;
62     }
63     if ( $all ) {
64         usage() if $cmd eq 'create';
65         for my $lang ( @{$installer->{langs}} ) {
66             $installer->set_lang( $lang );
67             $installer->$cmd(\@files);
68         }
69     }
70     else {
71         $installer->$cmd(\@files);
72     }
73
74     Koha::Caches->get_instance()->flush_all if $cmd ne 'update';
75 }
76 else {
77     usage();
78 }
79
80
81
82 =head1 NAME
83
84 translate - Handle templates and preferences translation
85
86 =head1 SYNOPSYS
87
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]
96
97 =head1 DESCRIPTION
98
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.
103
104 =head1 USAGE
105
106 Use the -v or --verbose parameter to make translator more verbose.
107
108 =over
109
110 =item translate create F<lang>
111
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.
115
116 =over
117
118 =item F<lang>-opac-{theme}.po
119
120 Contains extracted text from english (en) OPAC templates found in
121 <KOHA_ROOT>/koha-tmpl/opac-tmpl/{theme}/en/ directory.
122
123 =item F<lang>-intranet.po
124
125 Contains extracted text from english (en) intranet templates found in
126 <KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/ directory.
127
128 =item F<lang>-pref.po
129
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.
133
134 =back
135
136 =item translate [-p] update F<lang>
137
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.
141
142 =item translate [-p|-f] install F<lang>
143
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.
148
149 With -f parameter (repeatable) you can specify specific files to translate. For
150 example, -f search will translate all templates containing 'search'.
151
152 =item translate compress F<lang>
153
154 Compress .po files in F<po> directory, named F<lang>-*.po. Without F<lang>, files
155 from all available languages are compressed.
156
157 =item translate uncompress F<lang>
158
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.
161
162
163 =back
164
165 =cut
166