Koha 3.8.0 Translation Update
[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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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 GetOptions(
34     'v|verbose' => \$verbose,
35     'p'         => \$pref,
36     'a|all'     => \$all,
37 );
38
39
40 sub usage {
41     pod2usage( -verbose => 2 );
42     exit;
43 }
44
45
46 usage() if $#ARGV != 1 && $#ARGV != 0;
47
48 my ($cmd, $lang) = @ARGV;
49 $cmd = lc $cmd;
50 if ( $cmd =~ /create|install|update/ ) {
51     my $installer = LangInstaller->new( $lang, $pref, $verbose );
52     if ( $cmd !~ /create/ && $lang && not $lang ~~ $installer->{langs} ) {
53         print "Unsupported language: $lang\n";
54         exit;
55     }
56     if ( $all ) {
57         usage() if $cmd eq 'create';
58         for my $lang ( @{$installer->{langs}} ) {
59             $installer->set_lang( $lang );
60             $installer->$cmd();
61         }
62     }
63     else {
64         $installer->$cmd();
65     }
66 }
67 else {
68     usage();
69 }
70
71
72
73 =head1 NAME
74
75 translate - Handle templates and preferences translation
76
77 =head1 SYNOPSYS
78
79   translate create fr-FR
80   translate update fr-FR
81   translate install fr-FR
82   translate -p install fr-FR
83   translate install
84
85 =head1 DESCRIPTION
86
87 In Koha, three categories of information are translated based on standard GNU
88 .po files: opac templates pages, intranet templates and system preferences. The
89 script is a wrapper. It allows to quickly create/update/install .po files for a
90 given language or for all available languages.
91
92 =head1 USAGE
93
94 =over
95
96 =item translate create F<lang>
97
98 Create 3 .po files in F</misc/translator/po> subdirectory: (1) from opac pages
99 templates, (2) intranet templates, and (3) from preferences. English 'en'
100 version of templates and preferences are used as references.
101
102 =over
103
104 =item F<lang>-opac.po
105
106 Contains extracted text from english (en) OPAC templates found in
107 <KOHA_ROOT>/koha-tmpl/opac-tmpl/prog/en/ directory.
108
109 =item F<lang>-intranet.po
110
111 Contains extracted text from english (en) intranet templates found in
112 <KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/ directory.
113
114 =item F<lang>-pref.po
115
116 Contains extracted text from english (en) preferences. They are found in files
117 located in <KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/admin/preferences
118 directory.
119
120 =back
121
122 =item translate [-p] update F<lang>
123
124 Update .po files in F<po> directory, named F<lang>-*.po. Without F<lang>, all
125 available languages are updated. With -p option, only preferences .po file is
126 updated.
127
128 =item translate [-p] install F<lang>
129
130 Use .po files to translate the english version of templayes and preferences files
131 and copy those files in the appropriate directory. Without F<lang>, all
132 available languages are installed. With -p option, only preferences .po file is
133 updated.
134
135 =back
136
137 =cut
138