forked from adblockplus/backup-adblockplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalizeLocales.pl
executable file
·81 lines (67 loc) · 2.41 KB
/
normalizeLocales.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/perl
# This file is part of Adblock Plus <https://adblockplus.org/>,
# Copyright (C) 2006-2015 Eyeo GmbH
#
# Adblock Plus is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# Adblock Plus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
# This script will adjust the locales as received from Babelzilla - normalize
# newlines and remove comments that have been pointlessly copied over from
# en-US.
use strict;
use warnings;
$0 =~ s/(.*[\\\/])//g;
chdir($1) if $1;
opendir(local* LOCALES, "chrome/locale") or die "Failed to open directory chrome/locale";
foreach my $locale (readdir(LOCALES))
{
next if $locale =~ /^\./ || $locale eq "en-US" || $locale eq "de" || $locale eq "ru";
foreach my $file (<chrome/locale/$locale/*.properties>)
{
my $data = readFile($file);
$data =~ s/\r//g; # Normalize newlines
$data =~ s/\n+/\n/g; # Remove empty lines
$data =~ s/\\+?(\\n|'|")/$1/g; # Remove double escapes
$data =~ s/^\s*#.*\n*//gm; # Remove pointless comments
writeFile($file, $data);
unlink($file) if -z $file;
}
foreach my $file (<chrome/locale/$locale/*.dtd>)
{
my $data = readFile($file);
$data =~ s/\r//g; # Normalize newlines
$data =~ s/\\n/\n/g; # Replace misencoded newlines by regular ones
$data =~ s/\\(\n|'|"|&)/$1/g; # Remove wrong escapes
$data =~ s/\n+/\n/g; # Remove empty lines
$data =~ s/[^\S\n]*<!--.*?-->\s*?\n*//gs; # Remove pointless comments
writeFile($file, $data);
unlink($file) if -z $file;
}
}
closedir(LOCALES);
sub readFile
{
my $file = shift;
open(local *FILE, "<", $file) || die "Could not read file '$file'";
binmode(FILE);
local $/;
my $result = <FILE>;
close(FILE);
return $result;
}
sub writeFile
{
my ($file, $contents) = @_;
open(local *FILE, ">", $file) || die "Could not write file '$file'";
binmode(FILE);
print FILE $contents;
close(FILE);
}