bab716de43d51634c810f875464137b7769f5155
[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
33 my $verbose     = 0;
34 my $pref        = 0;
35 my $all         = 0;
36 my @files;
37 GetOptions(
38     'v|verbose' => \$verbose,
39     'p'         => \$pref,
40     'f:s'       => \@files,
41     'a|all'     => \$all,
42 );
43
44
45 sub usage {
46     pod2usage( -verbose => 2 );
47     exit;
48 }
49
50
51 usage() if $#ARGV != 1 && $#ARGV != 0;
52
53 my ($cmd, $lang) = @ARGV;
54 $cmd = lc $cmd;
55 if ( $cmd =~ /^(create|install|update|compress|uncompress)$/ ) {
56     my $installer = LangInstaller->new( $lang, $pref, $verbose );
57     if ( $cmd ne 'create' and $lang and not grep( {$_ eq $lang} @{ $installer->{langs} } ) ) {
58         print "Unsupported language: $lang\n";
59         exit;
60     }
61     if ( $all ) {
62         usage() if $cmd eq 'create';
63         for my $lang ( @{$installer->{langs}} ) {
64             $installer->set_lang( $lang );
65             $installer->$cmd(\@files);
66         }
67     }
68     else {
69         $installer->$cmd(\@files);
70     }
71 }
72 else {
73     usage();
74 }
75
76
77
78 =head1 NAME
79
80 translate - Handle templates and preferences translation
81
82 =head1 SYNOPSYS
83
84   translate create fr-FR
85   translate update fr-FR
86   translate install fr-FR
87   translate install fr-FR -f search -f memberentry
88   translate -p install fr-FR
89   translate install
90   translate compress [fr-FR]
91   translate uncompress [fr-FR]
92
93 =head1 DESCRIPTION
94
95 In Koha, three categories of information are translated based on standard GNU
96 .po files: opac templates pages, intranet templates and system preferences. The
97 script is a wrapper. It allows to quickly create/update/install .po files for a
98 given language or for all available languages.
99
100 =head1 USAGE
101
102 Use the -v or --verbose parameter to make translator more verbose.
103
104 =over
105
106 =item translate create F<lang>
107
108 Create 3 .po files in F</misc/translator/po> subdirectory: (1) from opac pages
109 templates, (2) intranet templates, and (3) from preferences. English 'en'
110 version of templates and preferences are used as references.
111
112 =over
113
114 =item F<lang>-opac-{theme}.po
115
116 Contains extracted text from english (en) OPAC templates found in
117 <KOHA_ROOT>/koha-tmpl/opac-tmpl/{theme}/en/ directory.
118
119 =item F<lang>-intranet.po
120
121 Contains extracted text from english (en) intranet templates found in
122 <KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/ directory.
123
124 =item F<lang>-pref.po
125
126 Contains extracted text from english (en) preferences. They are found in files
127 located in <KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/admin/preferences
128 directory.
129
130 =back
131
132 =item translate [-p] update F<lang>
133
134 Update .po files in F<po> directory, named F<lang>-*.po. Without F<lang>, all
135 available languages are updated. With -p option, only preferences .po file is
136 updated.
137
138 =item translate [-p|-f] install F<lang>
139
140 Use .po files to translate the english version of templates and preferences files
141 and copy those files in the appropriate directory. Without F<lang>, all
142 available languages are installed. With -p option, only preferences .po file is
143 updated.
144
145 With -f parameter (repeatable) you can specify specific files to translate. For
146 example, -f search will translate all templates containing 'search'.
147
148 =item translate compress F<lang>
149
150 Compress .po files in F<po> directory, named F<lang>-*.po. Without F<lang>, files
151 from all available languages are compressed.
152
153 =item translate uncompress F<lang>
154
155 Uncompress .po.gz files in F<po> directory, named F<lang>-*.po.gz. Without F<lang>,
156 files from all available languages are uncompressed.
157
158
159 =back
160
161 =cut
162