Merge remote-tracking branch 'origin/master' into new/bug_6679
[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 );
52     if ( $all ) {
53         usage() if $cmd eq 'create';
54         for my $lang ( @{$installer->{langs}} ) {
55             $installer->set_lang( $lang );
56             $installer->$cmd();
57         }
58     }
59     else {
60         $installer->$cmd();
61     }
62 }
63 else {
64     usage();
65 }
66
67
68
69 =head1 NAME
70
71 translate - Handle templates and preferences translation
72
73 =head1 SYNOPSYS
74
75   translate create fr-FR
76   translate update fr-FR
77   translate install fr-FR
78   translate -p install fr-FR
79   translate install
80
81 =head1 DESCRIPTION
82
83 In Koha, three categories of information are translated based on standard GNU
84 .po files: opac templates pages, intranet templates and system preferences. The
85 script is a wrapper. It allows to quickly create/update/install .po files for a
86 given language or for all available languages.
87
88 =head1 USAGE
89
90 =over
91
92 =item translate create F<lang>
93
94 Create 3 .po files in F</misc/translator/po> subdirectory: (1) from opac pages
95 templates, (2) intranet templates, and (3) from preferences. English 'en'
96 version of templates and preferences are used as references.
97
98 =over
99
100 =item F<lang>-opac.po
101
102 Contains extracted text from english (en) OPAC templates found in
103 <KOHA_ROOT>/koha-tmpl/opac-tmpl/prog/en/ directory.
104
105 =item F<lang>-intranet.po
106
107 Contains extracted text from english (en) intranet templates found in
108 <KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/ directory.
109
110 =item F<lang>-pref.po
111
112 Contains extracted text from english (en) preferences. They are found in files
113 located in <KOHA_ROOT>/koha-tmpl/intranet-tmpl/prog/en/admin/preferences
114 directory.
115
116 =back
117
118 =item translate [-p] update F<lang>
119
120 Update .po files in F<po> directory, named F<lang>-*.po. Without F<lang>, all
121 available languages are updated. With -p option, only preferences .po file is
122 updated.
123
124 =item translate [-p] install F<lang>
125
126 Use .po files to translate the english version of templayes and preferences files
127 and copy those files in the appropriate directory. Without F<lang>, all
128 available languages are installed. With -p option, only preferences .po file is
129 updated.
130
131 =back
132
133 =cut
134