]> git.evergreen-ils.org Git - working/Evergreen.git/blob - build/i18n/scripts/update_pofiles
Update script for update_pofiles
[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.js
59     admin.properties
60     authority.js
61     auth.properties
62     AutoFieldWidget.js
63     capture.js
64     cat.properties
65     circ.properties
66     common.properties
67     conify.dtd
68     conify.js
69     db.seed
70     FlattenerGrid.js
71     fm_IDL.dtd
72     ils_events.xml
73     lang.dtd
74     match_set.js
75     multiclass_search_help.html
76     offline.properties
77     opac.dtd
78     opac.js
79     patron.properties
80     PCrudFilterPane.js
81     pickup_and_return.js
82     pull_list.js
83     register.js
84     reports.dtd
85     reports.js
86     reservation.js
87     Searcher.js
88     selfcheck.js
89     serial.js
90     serial.properties
91     tpac
92     TranslatorPopup.js
93     URLVerify.js
94     User.js
95     vandelay.dtd
96     vandelay.js
97     XULTermLoader.js
98 /;
99
100 foreach my $pofile (@pofiles) {
101     foreach my $lang (keys %locs) {
102         my $src_file = File::Spec->catfile(
103             ($lp_base_dir, 'build/i18n/po', $pofile), "$lang.po"
104         );
105         my $dest_file = File::Spec->catfile(
106             ($eg_base_dir, 'build/i18n/po', $pofile), "$locs{$lang}.po"
107         );
108
109         # If the source file doesn't exist, move on
110         next if ! -f $src_file;
111
112         # Check for actual changed strings
113         if (-f $dest_file) {
114             my $diff = `diff -u $dest_file $src_file`;
115
116             # Ignore changes to the PO header
117             $diff =~ s/^\+#.*?$//ms;
118             $diff =~ s/^\+"PO-Revision-Date:.*?$//ms;
119             $diff =~ s/^\+"Report-Msgid-Bugs-To:.*?$//ms;
120             $diff =~ s/^\+"X-Launchpad-Export-Date:.*?$//ms;
121             $diff =~ s/^\+"X-Generator:.*?$//ms;
122
123             if ($diff =~ /^\+/sm) {
124                 `cp $src_file $dest_file`;
125             }
126         } else {
127             # Copy brand new translations into place
128             `cp $src_file $dest_file`;
129         }
130     }
131 }
132
133 sub check_options {
134     if (!($lp_base_dir && $eg_base_dir)) {
135         pod2usage(1);
136     }
137
138     if (!-d $lp_base_dir) {
139         print STDERR "$lp_base_dir does not exist; exiting\n";
140         pod2usage(1);
141     }
142
143     if (!-d $eg_base_dir) {
144         print STDERR "$eg_base_dir does not exist; exiting\n";
145         pod2usage(1);
146     }
147
148     if (!-d File::Spec->catdir($lp_base_dir, '.bzr')) {
149         print STDERR "$lp_base_dir is not a bzr branch; exiting\n";
150         pod2usage(1);
151     }
152
153     if (!-f File::Spec->catfile(($eg_base_dir, '.git'), 'config')) {
154         print STDERR "$eg_base_dir is not a git clone; exiting\n";
155         pod2usage(1);
156     }
157 }
158
159 __END__
160
161 =head1 NAME
162
163 update_pofiles - Updates translations from Launchpad
164
165 =head1 SYNOPSIS
166
167 B<update_pofile> B<--launchpad-base-dir>=I<translation-export-directory>
168                 B<--evergreen-base-dir>=I<evergreen-git-clone-directory>
169
170 =head1 DESCRIPTION
171
172 Assuming that you have an updated bzr checkout of the translation-export
173 to satisfy the 'launchpad-base-dir' argument, and an updated git clone
174 of Evergreen master to satisfy the 'evergreen-base-dir' argument,
175 this script attempts to copy only the new or changed translations
176 from the Launchpad directory into the Evergreen directory. It
177 converts the Launchpad I<ll> and I<ll_LL> locale names into Evergreen's
178 I<ll-LL> locale names.
179
180 Note that the user is still required to build, test, and check in the
181 updated translations.
182
183 =head1 OPTIONS
184
185 =over
186
187 =item * B<-l> I<translation-export-directory>, B<--launchpad-base-dir>=I<translation-export-directory>
188
189 Specifies the directory holding the updated bzr checkout of
190 https://code.launchpad.net/~denials/evergreen/translation-export - which
191 you can create via "bzr lp:~denials/evergreen/translation-export".
192
193 =item * B<-e> I<evergreen-directory>, B<--evergreen-base-dir>=I<evergreen-directory>
194
195 Specifies the directory holding the updated git clone of Evergreen, which you
196 can create via "git clone git://git.evergreen-ils.org/Evergreen.git".
197
198 =back
199
200 =head1 AUTHOR
201
202 Dan Scott <dscott@laurentian.ca>
203
204 =head1 COPYRIGHT AND LICENSE
205
206 Copyright 2011 by Dan Scott
207
208 This program is free software; you can redistribute it and/or
209 modify it under the terms of the GNU General Public License
210 as published by the Free Software Foundation; either version 2
211 of the License, or (at your option) any later version.
212
213 This program is distributed in the hope that it will be useful,
214 but WITHOUT ANY WARRANTY; without even the implied warranty of
215 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
216 GNU General Public License for more details.
217
218 You should have received a copy of the GNU General Public License
219 along with this program; if not, write to the Free Software
220 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
221
222 =cut
223