Bug 24664: Add missing *-messages-js.po
[koha.git] / misc / translator / translate
blobbab716de43d51634c810f875464137b7769f5155
1 #!/usr/bin/perl
3 # Copyright (C) 2010 Tamil s.a.r.l.
5 # This file is part of Koha.
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.
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.
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>.
20 package Main;
22 use FindBin;
23 use lib $FindBin::Bin;
25 use strict;
26 use warnings;
28 use LangInstaller;
29 use Getopt::Long;
30 use Pod::Usage;
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,
45 sub usage {
46 pod2usage( -verbose => 2 );
47 exit;
51 usage() if $#ARGV != 1 && $#ARGV != 0;
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;
61 if ( $all ) {
62 usage() if $cmd eq 'create';
63 for my $lang ( @{$installer->{langs}} ) {
64 $installer->set_lang( $lang );
65 $installer->$cmd(\@files);
68 else {
69 $installer->$cmd(\@files);
72 else {
73 usage();
78 =head1 NAME
80 translate - Handle templates and preferences translation
82 =head1 SYNOPSYS
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]
93 =head1 DESCRIPTION
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.
100 =head1 USAGE
102 Use the -v or --verbose parameter to make translator more verbose.
104 =over
106 =item translate create F<lang>
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.
112 =over
114 =item F<lang>-opac-{theme}.po
116 Contains extracted text from english (en) OPAC templates found in
117 <KOHA_ROOT>/koha-tmpl/opac-tmpl/{theme}/en/ directory.
119 =item F<lang>-intranet.po
121 Contains extracted text from english (en) intranet templates found in
122 <KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/ directory.
124 =item F<lang>-pref.po
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.
130 =back
132 =item translate [-p] update F<lang>
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.
138 =item translate [-p|-f] install F<lang>
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.
145 With -f parameter (repeatable) you can specify specific files to translate. For
146 example, -f search will translate all templates containing 'search'.
148 =item translate compress F<lang>
150 Compress .po files in F<po> directory, named F<lang>-*.po. Without F<lang>, files
151 from all available languages are compressed.
153 =item translate uncompress F<lang>
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.
159 =back
161 =cut