]> git.evergreen-ils.org Git - working/Evergreen.git/blob - build/i18n/scripts/update_pofiles
a65c88e8aa7cb9cd9a64bc86c711350d2eed20d0
[working/Evergreen.git] / build / i18n / scripts / update_pofiles
1 #!/usr/bin/perl
2 # Copyright (C) 2011 Laurentian University
3 # Author: Dan Scott <dscott@laurentian.ca>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 # ---------------------------------------------------------------
15
16 use strict;
17 use warnings;
18 use File::Spec;
19 use Getopt::Long;
20 use Pod::Usage qw/ pod2usage /;
21
22 my $lp_base_dir;
23 my $eg_base_dir;
24 my $help = 0;
25
26 GetOptions(
27     'launchpad-base-dir=s' => \$lp_base_dir,
28     'evergreen-base-dir=s' => \$eg_base_dir,
29     'help' => \$help,
30 );
31
32 if ($help) {
33     pod2usage(0);
34 }
35
36 check_options();
37
38 my %locs = (
39     ar => "ar-AR",
40     cs => "cs-CZ",
41     de => "de-DE",
42     en_CA => "en-CA",
43     en_GB => "en-GB",
44     es => "es-ES",
45     fi => "fi-FI",
46     fr => "fr-CA",
47     he => "he-IL",
48     hu => "hu-HU",
49     hy => "hy-AM",
50     oc => "oc-FR",
51     pt_BR => "pt-BR",
52     ru => "ru-RU",
53     sv => "sv-SE",
54     tr => "tr-TR",
55 );
56
57 my @pofiles = qw/
58     acq
59     acq.js
60     actor
61     admin.properties
62     authority.js
63     auth.properties
64     AutoFieldWidget.js
65     booking
66     capture.js
67     cat
68     cat.properties
69     circ
70     circ.properties
71     common.properties
72     conify
73     conify.dtd
74     conify.js
75     db.seed
76     FlattenerGrid.js
77     fm_IDL.dtd
78     ils_events.xml
79     kpac
80     lang.dtd
81     match_set.js
82     multiclass_search_help.html
83     offline.properties
84     opac.dtd
85     opac.js
86     patron.properties
87     PCrudFilterPane.js
88     pickup_and_return.js
89     pull_list.js
90     register.js
91     reports.dtd
92     reports.js
93     reservation.js
94     Searcher.js
95     selfcheck.js
96     serial
97     serial.js
98     serial.properties
99     tpac
100     TranslatorPopup.js
101     URLVerify.js
102     User.js
103     urlverify
104     vandelay
105     vandelay.dtd
106     vandelay.js
107     webstaff
108     XULTermLoader.js
109 /;
110
111 foreach my $pofile (@pofiles) {
112     foreach my $lang (keys %locs) {
113         my $src_file = File::Spec->catfile(
114             ($lp_base_dir, 'build/i18n/po', $pofile), "$lang.po"
115         );
116         my $dest_file = File::Spec->catfile(
117             ($eg_base_dir, 'build/i18n/po', $pofile), "$locs{$lang}.po"
118         );
119
120         # If the source file doesn't exist, move on
121         next if ! -f $src_file;
122
123         # Check for actual changed strings
124         if (-f $dest_file) {
125             my $diff = `diff -u $dest_file $src_file`;
126
127             # Ignore changes to the PO header
128             $diff =~ s/^\+#.*?$//ms;
129             $diff =~ s/^\+"PO-Revision-Date:.*?$//ms;
130             $diff =~ s/^\+"Report-Msgid-Bugs-To:.*?$//ms;
131             $diff =~ s/^\+"X-Launchpad-Export-Date:.*?$//ms;
132             $diff =~ s/^\+"X-Generator:.*?$//ms;
133
134             if ($diff =~ /^\+/sm) {
135                 `cp $src_file $dest_file`;
136             }
137         } else {
138             # Copy brand new translations into place
139             `cp $src_file $dest_file`;
140         }
141     }
142 }
143
144 sub check_options {
145     if (!($lp_base_dir && $eg_base_dir)) {
146         pod2usage(1);
147     }
148
149     if (!-d $lp_base_dir) {
150         print STDERR "$lp_base_dir does not exist; exiting\n";
151         pod2usage(1);
152     }
153
154     if (!-d $eg_base_dir) {
155         print STDERR "$eg_base_dir does not exist; exiting\n";
156         pod2usage(1);
157     }
158
159     if (!-d File::Spec->catdir($lp_base_dir, '.bzr')) {
160         print STDERR "$lp_base_dir is not a bzr branch; exiting\n";
161         pod2usage(1);
162     }
163
164     if (!-f File::Spec->catfile(($eg_base_dir, '.git'), 'config')) {
165         print STDERR "$eg_base_dir is not a git clone; exiting\n";
166         pod2usage(1);
167     }
168 }
169
170 __END__
171
172 =head1 NAME
173
174 update_pofiles - Updates translations from Launchpad
175
176 =head1 SYNOPSIS
177
178 B<update_pofile> B<--launchpad-base-dir>=I<translation-export-directory>
179                 B<--evergreen-base-dir>=I<evergreen-git-clone-directory>
180
181 =head1 DESCRIPTION
182
183 Assuming that you have an updated bzr checkout of the translation-export
184 to satisfy the 'launchpad-base-dir' argument, and an updated git clone
185 of Evergreen master to satisfy the 'evergreen-base-dir' argument,
186 this script attempts to copy only the new or changed translations
187 from the Launchpad directory into the Evergreen directory. It
188 converts the Launchpad I<ll> and I<ll_LL> locale names into Evergreen's
189 I<ll-LL> locale names.
190
191 Note that the user is still required to build, test, and check in the
192 updated translations.
193
194 =head1 OPTIONS
195
196 =over
197
198 =item * B<-l> I<translation-export-directory>, B<--launchpad-base-dir>=I<translation-export-directory>
199
200 Specifies the directory holding the updated bzr checkout of
201 https://code.launchpad.net/~denials/evergreen/translation-export - which
202 you can create via "bzr lp:~denials/evergreen/translation-export".
203
204 =item * B<-e> I<evergreen-directory>, B<--evergreen-base-dir>=I<evergreen-directory>
205
206 Specifies the directory holding the updated git clone of Evergreen, which you
207 can create via "git clone git://git.evergreen-ils.org/Evergreen.git".
208
209 =back
210
211 =head1 AUTHOR
212
213 Dan Scott <dscott@laurentian.ca>
214
215 =head1 COPYRIGHT AND LICENSE
216
217 Copyright 2011 by Dan Scott
218
219 This program is free software; you can redistribute it and/or
220 modify it under the terms of the GNU General Public License
221 as published by the Free Software Foundation; either version 2
222 of the License, or (at your option) any later version.
223
224 This program is distributed in the hope that it will be useful,
225 but WITHOUT ANY WARRANTY; without even the implied warranty of
226 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
227 GNU General Public License for more details.
228
229 You should have received a copy of the GNU General Public License
230 along with this program; if not, write to the Free Software
231 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
232
233 =cut
234