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