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