Bug 22236: Translation should generate tags with consistent attribute order
[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/ ) {
56     my $installer = LangInstaller->new( $lang, $pref, $verbose );
57     if ( $cmd ne 'create' and $lang and not grep( /^$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
91 =head1 DESCRIPTION
92
93 In Koha, three categories of information are translated based on standard GNU
94 .po files: opac templates pages, intranet templates and system preferences. The
95 script is a wrapper. It allows to quickly create/update/install .po files for a
96 given language or for all available languages.
97
98 =head1 USAGE
99
100 Use the -v or --verbose parameter to make translator more verbose.
101
102 =over
103
104 =item translate create F<lang>
105
106 Create 3 .po files in F</misc/translator/po> subdirectory: (1) from opac pages
107 templates, (2) intranet templates, and (3) from preferences. English 'en'
108 version of templates and preferences are used as references.
109
110 =over
111
112 =item F<lang>-opac-{theme}.po
113
114 Contains extracted text from english (en) OPAC templates found in
115 <KOHA_ROOT>/koha-tmpl/opac-tmpl/{theme}/en/ directory.
116
117 =item F<lang>-intranet.po
118
119 Contains extracted text from english (en) intranet templates found in
120 <KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/ directory.
121
122 =item F<lang>-pref.po
123
124 Contains extracted text from english (en) preferences. They are found in files
125 located in <KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/admin/preferences
126 directory.
127
128 =back
129
130 =item translate [-p] update F<lang>
131
132 Update .po files in F<po> directory, named F<lang>-*.po. Without F<lang>, all
133 available languages are updated. With -p option, only preferences .po file is
134 updated.
135
136 =item translate [-p|-f] install F<lang>
137
138 Use .po files to translate the english version of templates and preferences files
139 and copy those files in the appropriate directory. Without F<lang>, all
140 available languages are installed. With -p option, only preferences .po file is
141 updated.
142
143 With -f parameter (repeatable) you can specify specific files to translate. For
144 example, -f search will translate all templates containing 'search'.
145
146 =back
147
148 =cut
149