summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2015-05-13 11:18:36 +0200
committerYorhel <git@yorhel.nl>2015-05-13 11:18:36 +0200
commit339599d9f8afaa61862836d2c89ce0d76045f122 (patch)
tree47c81a55c59b5138ff28353a9055ee16babc1bef /util
parente1096f570ced3976f2b22bb94478317c8384a463 (diff)
I18N: Add cleanup routine to lang.pl + remove English text from tls
Diffstat (limited to 'util')
-rwxr-xr-xutil/lang.pl44
1 files changed, 44 insertions, 0 deletions
diff --git a/util/lang.pl b/util/lang.pl
index 7e05590f..12232e06 100755
--- a/util/lang.pl
+++ b/util/lang.pl
@@ -36,6 +36,14 @@ $0 merge <lang> <file>
$0 reorder <lang1>,<lang2>,..
Re-orders the translation lines in lang.txt using the specified order.
+$0 cleanup
+ Higher-level cleanup/canonicalization. Does a bunch of things:
+ - Adds empty translation lines for languages present in the first key but not in other keys.
+ - Removes translation lines for languages not present in the first key.
+ - Reorders all translations to be in the same order as the first key.
+ - Removes translations that are equivalent to the English text.
+ TL;DR: Uses the first key in lang.txt as a template for all other keys.
+
$0 stage <lang>
Puts all changes of <lang> into the git index, and leaves everything else untouched.
__
@@ -145,6 +153,41 @@ sub reorder {
}
+sub cleanup {
+ my $r = LangFile->new(read => $langtxt);
+ my $w = LangFile->new(write => "$langtxt~");
+ my $key; # current key, undef if not in a TL part
+ my %tl; # translations of the current key
+ my @template; # languages and order of the first key
+ my $havetemp; # set when @template is complete
+ while((my $l = $r->read)) {
+ if($key && $l->[0] ne 'tl') {
+ $havetemp = 1;
+ for(@template) {
+ if(!$tl{$_}) {
+ $w->write('tl', $_, 0, '');
+ } elsif($_ ne 'en' && $tl{$_}[3] eq $tl{en}[3]) {
+ $w->write('tl', $_, 1, '');
+ } else {
+ $w->write(@{$tl{$_}});
+ }
+ }
+ $key = undef;
+ %tl = ();
+ }
+ $key = $l->[1] if $l->[0] eq 'key';
+ $w->write(@$l) unless $l->[0] eq 'tl';
+ if($l->[0] eq 'tl') {
+ $tl{$l->[1]} = $l;
+ push @template, $l->[1] if !$havetemp;
+ }
+ }
+ $r->close;
+ $w->close;
+ rename "$langtxt~", $langtxt or die $!;
+}
+
+
sub stage {
my $lang = shift;
chdir "$ROOT/data";
@@ -164,5 +207,6 @@ add @ARGV if $act eq 'add';
only @ARGV if $act eq 'only';
merge @ARGV if $act eq 'merge';
reorder @ARGV if $act eq 'reorder';
+cleanup @ARGV if $act eq 'cleanup';
stage @ARGV if $act eq 'stage';