added wml2gettext tool to automate migration
This commit is contained in:
parent
5d4b3e9e4e
commit
69b52a9628
2 changed files with 62 additions and 0 deletions
27
utils/wml2gettext.pl
Executable file
27
utils/wml2gettext.pl
Executable file
|
@ -0,0 +1,27 @@
|
|||
#! /usr/bin/perl -wp
|
||||
|
||||
use strict;
|
||||
our %trans;
|
||||
|
||||
BEGIN {
|
||||
require "utils/wmltrans.pm";
|
||||
%trans = readwml ('data/translations/english.cfg');
|
||||
}
|
||||
|
||||
while (m/^(.*)translate_string\(\"([^\"]*)\"\)(.*)/) {
|
||||
my $str = $trans{$2};
|
||||
unless (defined $str) {
|
||||
print STDERR "no translation found for \"$2\"\n";
|
||||
last;
|
||||
}
|
||||
$_ = "$1_(\"$str\")$3\n";
|
||||
}
|
||||
|
||||
while (m/^(.*)string_table\[\"([^\"]*)\"\](.*)/) {
|
||||
my $str = $trans{$2};
|
||||
unless (defined $str) {
|
||||
print STDERR "no translation found for \"$2\"\n";
|
||||
last;
|
||||
}
|
||||
$_ = "$1_(\"$str\")$3\n";
|
||||
}
|
35
utils/wmltrans.pm
Normal file
35
utils/wmltrans.pm
Normal file
|
@ -0,0 +1,35 @@
|
|||
# -*- perl -*-
|
||||
|
||||
sub readwml {
|
||||
my ($file) = @_;
|
||||
open (TRANS, $file) or die "cannot open $file";
|
||||
|
||||
my (%trans, $key);
|
||||
|
||||
while (<TRANS>) {
|
||||
if (m/(\S+)\s*=\s*\"(.*)\"\s*$/) {
|
||||
die "nested key" if defined $key;
|
||||
|
||||
$trans{$1} = $2;
|
||||
|
||||
} elsif (m/(\S+)\s*=\s*\"(.*)/) {
|
||||
die "nested key" if defined $key;
|
||||
|
||||
$key = $1;
|
||||
$trans{$key} = $2 . "\n";
|
||||
|
||||
} elsif (m/(.*)\"\s*$/) {
|
||||
die "end of string without a key" unless defined $key;
|
||||
|
||||
$trans{$key} .= $1;
|
||||
$key = undef;
|
||||
} else {
|
||||
$trans{$key} .= $_ if defined $key;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return %trans;
|
||||
}
|
||||
|
||||
1;
|
Loading…
Add table
Reference in a new issue