tools/Translator/sen.pl
2025-02-22 23:59:12 +08:00

30 lines
704 B
Perl

#!/usr/bin/perl
use strict;
use warnings;
use v5.26;
use Text::CSV;
use Carp;
use utf8;
my $csv = Text::CSV->new( { binary => 1, auto_diag => 1 } );
open my $in, "< :encoding(UTF-8)", $ARGV[0] or confess;
open my $out, "> :encoding(UTF-8)", "../output/import.csv" or confess;
$csv->print( $out, [ "原文", "译文" ] );
my $msgid;
my $msgstr;
while ( my $line = <$in> ) {
chomp $line;
if ( $line =~ /^msgid "(.*)"/ ) {
$msgid = $1;
}
elsif ( $line =~ /^msgstr "(.*)"/ ) {
$msgstr = $1;
$msgid =~ s/\\n/\n/g;
$msgstr =~ s/\\n/\n/g;
$csv->print( $out, [ $msgid, $msgstr ] );
print $out "\n";
}
}
close $in;
close $out;