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