-
Notifications
You must be signed in to change notification settings - Fork 11
/
check_translations.pl
executable file
·171 lines (131 loc) · 3.98 KB
/
check_translations.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/perl
use 5.010;
use warnings;
use strict;
use FindBin qw($RealBin);
use Storable qw(dclone);
use File::Find;
use File::Slurp qw(write_file read_file);
use TOML qw(from_toml to_toml);
use Data::Dumper;
use Tomte::Presets qw( devices initialModuleSettings supportedOS essentialRepos otherRepos kernels lockFiles postConfPrograms );
my %msgids;
my %tomteMsgids;
# Specify the directory to start the search
my $scriptDirectory = $RealBin;
my $startDirectory = $scriptDirectory . '/po/';
my $defaultLanguage = 'en';
# Define the subroutine to be executed for each file
sub loadMsgIdsFromDirectories {
my $filePath = $File::Find::name;
# Skip directories
return if -d $filePath;
return unless $filePath =~ /startDirectory(.*)\.po/;
my $languageCode = $1;
open my $inputFile, '<', $filePath or warn "Couldn't open $filePath: $!";
while (my $line = <$inputFile>) {
if (my ($match) = $line =~ /msgid "(.*?)"/) {
if(length($match) > 0){
push @{$msgids{$languageCode}}, $match;
}
}
}
close $inputFile;
}
# Subroutine to compare two lists
sub compareLanguageWithTomteAndPrintDiff {
my ($languageCode) = @_;
print "Comparing Tomte Code msgids with those from $languageCode..\n";
my %uniqueItems = %{ dclone(\%tomteMsgids) };
my %returnHash;
my @onlyInList1;
my @onlyInList2;
# Check items in list 2
foreach my $item (@{$msgids{$languageCode}}) {
if (exists $uniqueItems{$item}) {
delete $uniqueItems{$item}; # Remove common items
} else {
push @onlyInList2, $item; # Item only in list 2
}
}
# Remaining items in %uniqueItems are only in list 1
@onlyInList1 = keys %uniqueItems;
my $list1Size = scalar @onlyInList1;
my $list2Size = scalar @onlyInList2;
print "Found $list1Size msgids only present in Tomte Code:\n";
if($list1Size > 0){
foreach my $msgid (@onlyInList1){
if (defined $msgid) {
print "$msgid\n";
} else {
print "Undefined value\n"; # Or handle it in another way
}
}
print "\n";
}
print "Found $list2Size msgids only present in $languageCode:\n";
if($list2Size > 0){
foreach my $msgid (@onlyInList2){
if (defined $msgid) {
print "$msgid\n";
} else {
print "Undefined value\n"; # Or handle it in another way
}
}
print "\n";
}
print "\n\n";
return $list1Size + $list2Size;
}
#sub readTomlFile {
# my $filePath = shift;
#
# my $tomlStr = read_file($filePath);
# my $tomlHashRef = from_toml($toml_str);
# Check if the TOML data was parsed successfully
# if (!defined $tomlHashRef) {
# die("Failed to parse TOML data from file: $filePath");
# }
# return %$tomlHashRef;
#}
# Perform the file search
find({ wanted => \&loadMsgIdsFromDirectories, no_chdir => 1 }, $startDirectory);
#TODO
print Dumper(\%msgids);
# Open the tomte file
open my $tomteFile, '<', 'src/tuxedo-tomte' or die "Couldn't open input file: $!";
# Process each line in the input file
while (my $line = <$tomteFile>) {
# Find all text between __(' and ')
my @matches;
push @matches, $line =~ /__\((.*?)\)/g;
push @matches, $line =~ /__x\((.*?),/g;
push @matches, $line =~ /__n\((.*?),/g;
push @matches, $line =~ /__nx\((.*?),/g;
# If at least one text was found, process them
if (@matches) {
foreach my $match (@matches) {
$match =~ s/^.(.*).$/$1/; # Remove the first and last quotation marks
# Check if this msgid is unique, then write it to the output
if (!$tomteMsgids{$match}) {
$tomteMsgids{$match} = 1; # Mark as seen
print "Tomte: $match\n";
}
}
}
}
# call descriptions are directly read from modules
delete $tomteMsgids{'module . "_description'};
my %origConfModules = initialModuleSettings();
foreach my $module (keys %origConfModules) {
next if $module eq 'default';
next if ! defined $module;
my $moduleString = $module . "_description";
print "moduleString: $moduleString module: $module\n";
$tomteMsgids{$moduleString} = 1;
}
my $differences = 0;
foreach my $languageCode (keys %msgids){
$differences += compareLanguageWithTomteAndPrintDiff($languageCode);
}
exit $differences;