limit to .html and .py files in bin/twlight_i18n_lint.pl
use strict;
use warnings;
+use feature "switch";
use Term::ANSIColor;
# Experimental features add warning output, which we don't want in our CI logs.
no warnings 'experimental';
+
# Exit code.
my $code = 0;
+# File extensions we allow for searching.
+my %allowed = (
+ 'html' => 1,
+ 'py' => 1
+);
+
# We take a file path as the first argument.
my $filename = $ARGV[0];
+
+# Extract the extension from the input filename.
+$filename =~ /\.([^.]+)$/;
+my $extension = $1;
+
+# Only proceed if the file extension is allowed.
+if (exists($allowed{$extension})) {
+ # Capture file content as string.
my $input = do { local $/; <> };
+ given($extension) {
+ # Python files.
+ when($extension eq 'py') {
# Check for newlines that can cause message mismatches with translatewiki.
my @newline_errors = ($input =~ /(?<!_)_\(\n(([ \t]*)?"[^\n]*"\n?)*([ \t]*)\)/sg);
foreach my $match (@newline_errors) {
@@ -31,6 +50,9 @@ foreach my $match (@comment_errors) {
my $message = 'Missing or overlong (> 240 chars) translator comment';
print_error($message, $filename, $input, $match);
}
+ }
+ }
+}
# Prints errors. Surpise!
sub print_error {
