summaryrefslogtreecommitdiffstats
path: root/po/bin
diff options
context:
space:
mode:
Diffstat (limited to 'po/bin')
-rwxr-xr-xpo/bin/add_text56
-rwxr-xr-xpo/bin/fixpot27
-rwxr-xr-xpo/bin/po2txt165
-rwxr-xr-xpo/bin/rm_text63
4 files changed, 311 insertions, 0 deletions
diff --git a/po/bin/add_text b/po/bin/add_text
new file mode 100755
index 0000000..a725b46
--- /dev/null
+++ b/po/bin/add_text
@@ -0,0 +1,56 @@
+#! /usr/bin/perl
+
+# add a new text to *.po files
+
+die "usage: add_text [-c comment] id text_line1 text_line2 ... \nexample:\n add_text MENU_LANG Language\n" if @ARGV < 2;
+
+if($ARGV[0] eq '-c') {
+ shift;
+ $comment = shift;
+}
+
+$id = shift;
+@texts = @ARGV;
+
+$id =~ s/^txt_//;
+
+$_ = join '', @texts;
+
+push @l, "# $comment\n" if $comment;
+push @l, "#. txt_$id\n";
+push @l, "#, c-format\n" if /%/;
+
+if(@texts == 1) {
+ push @l, "msgid \"$texts[0]\"\n"
+}
+else {
+ push @l, "msgid \"\"\n";
+ for (@texts) { push @l, "\"$_\"\n" }
+}
+
+push @l, "msgstr \"\"\n";
+push @l, "\n";
+
+print @l;
+
+print STDERR "Should this entry be added to all *.po files? [Y/n]\n";
+
+$_ = <STDIN>;
+
+chomp;
+
+$_ = "\L$_";
+
+exit unless $_ eq '' || $_ eq 'y';
+
+print "ok\n";
+
+for $f ("bootloader.pot", <*.po>) {
+ if(open F, "+<$f") {
+ @f = <F>;
+ print F "\n" if $f[-1] !~ /^\s*$/;
+ print F @l;
+ close F;
+ }
+}
+
diff --git a/po/bin/fixpot b/po/bin/fixpot
new file mode 100755
index 0000000..1ed9665
--- /dev/null
+++ b/po/bin/fixpot
@@ -0,0 +1,27 @@
+#! /usr/bin/perl
+
+while(<>) {
+ if(/^\s*#|^\s*$/) { $msg[$cnt]{comment} .= $_; next }
+ if(s/^\s*msgid\b\s*//) { $cnt++; $id = 1 }
+ if(s/^\s*msgstr\b\s*//) { $id = 2 }
+ if($id == 1) { $msg[$cnt - 1]{id} .= $_; next }
+ if($id == 2) { $msg[$cnt - 1]{str} .= $_; next }
+
+ die "oops at line $.\n";
+}
+
+for (@msg) {
+ print $_->{comment};
+
+ next unless defined($_->{id}) && defined($_->{str});
+
+ if($_->{id} =~ /^\s*""\s*$/ || $_->{str} =~ /^\s*""\s*$/) {
+ print "msgid ", $_->{id};
+ print "msgstr ", $_->{str};
+ }
+ else {
+ print "msgid ", $_->{str};
+ print "msgstr \"\"\n";
+ }
+}
+
diff --git a/po/bin/po2txt b/po/bin/po2txt
new file mode 100755
index 0000000..f10ee5b
--- /dev/null
+++ b/po/bin/po2txt
@@ -0,0 +1,165 @@
+#! /usr/bin/perl
+
+# convert *.po files to texts.* files suitable for gfxboot
+# usage: po2txt lang.po >texts.lang
+# Note: en.po ist treated specially!
+
+use Getopt::Long;
+
+sub read_texts;
+sub join_msg;
+
+$opt_product = "SUSE Linux";
+
+GetOptions(
+ 'product=s' => \$opt_product
+);
+
+
+for $lang (@ARGV) {
+ $lang = 'en' if $lang eq 'bootloader.pot';
+ $lang =~ s/\.po$//;
+ read_texts $lang;
+}
+
+sub read_texts
+{
+ local $_;
+
+ my ($lang, @f, $txt, $context, $t, $p, $ids, $file);
+
+ $lang = shift;
+
+ $file = "$lang.po";
+ $file = 'bootloader.pot' if $lang eq 'en';
+
+ if($lang eq 'en') {
+ $ids = 1;
+ }
+
+ open F, $file;
+ @f = (<F>);
+ close F;
+
+ map { s/<product>/$opt_product/g; } @f;
+
+ $_ = $lang;
+ s/.*\///;
+
+ for (@f) {
+ if(/^\s*#\.\s*(txt_\S+)/) {
+ if($txt) {
+ @msgstr = @msgid if $ids || join_msg(\@msgstr) eq "";
+ $txts{$txt} = join_msg(\@msgstr);
+ }
+
+ $txt = $1;
+
+ undef @msgid;
+ undef @msgstr;
+ undef $context;
+ next;
+ }
+
+ next if /^\s*#.*|^\s*$/;
+
+ if(/^\s*msgid\s*(\".*\")\s*$/) {
+ push @msgid, $1 unless $1 eq '""';
+ $context = 1;
+ next;
+ }
+
+ if(/^\s*msgstr\s*(\".*\")\s*$/) {
+ push @msgstr, $1 unless $1 eq '""';
+ $context = 2;
+ next;
+ }
+
+ if(/^\s*(\".*\")\s*$/) {
+ if($context == 1) {
+ push @msgid, $1;
+ }
+ elsif($context == 2) {
+ push @msgstr, $1;
+ }
+ else {
+ die "format oops in ${lang}.po: $_"
+ }
+ }
+ }
+
+ if($txt) {
+ @msgstr = @msgid if $ids || join_msg(\@msgstr) eq "";
+ $txts{$txt} = join_msg(\@msgstr);
+ }
+
+ @txts = sort keys %txts;
+
+ for (@txts) {
+ $txt = $txts{$_};
+ $txt =~ s/\\"/"/g;
+ $txt =~ s/\\\\/\\/g;
+ $txt =~ s/\\n/\n/g;
+ print "$txt\x00"
+ }
+
+ if($ids) {
+ open W, ">text.inc";
+ print W "%\n% This file is generated automatically. Editing it is pointless.\n%\n\n";
+ print W "/texts [\n";
+ $p = pop @txts;
+ for (@txts) { print W " /$_\n" }
+ print W " /$p\n] def\n";
+ close W;
+ }
+ else {
+ open F, "text.inc";
+ for (<F>) {
+ if(/\s+\/(txt_\S+)/) {
+ $txt_ref{$1} = undef;
+ }
+ }
+ close F;
+ for (@txts) {
+ $txt_list{$_}++;
+ $txt_multi{$_} = 1 if $txt_list{$_} > 1;
+ }
+ for (@txts) {
+ $txt_unknown{$_} = 1 unless exists $txt_ref{$_};
+ }
+ for (keys %txt_ref) {
+ $txt_miss{$_} = 1 unless exists $txt_list{$_};
+ }
+
+ if(defined(%txt_miss) || defined(%txt_unknown) || defined(%txt_multi)) {
+ print STDERR "$lang:\n";
+ for (sort keys %txt_miss) {
+ print STDERR " missing: $_\n"
+ }
+ for (sort keys %txt_unknown) {
+ print STDERR " unknown: $_\n"
+ }
+ for (sort keys %txt_multi) {
+ print STDERR " multi: $_\n"
+ }
+ }
+ }
+
+}
+
+
+sub join_msg
+{
+ local $_;
+ my ($s, $msg, $m);
+
+ $msg = shift;
+
+ for $s (@{$msg}) {
+ $_ = $s;
+ s/^\"(.*)\"$/$1/;
+ $m .= $_;
+ }
+
+ return $m;
+}
diff --git a/po/bin/rm_text b/po/bin/rm_text
new file mode 100755
index 0000000..9b96555
--- /dev/null
+++ b/po/bin/rm_text
@@ -0,0 +1,63 @@
+#! /usr/bin/perl
+
+# remove a text from *.po files
+
+sub drop;
+
+die "usage: rm_text id\n" if @ARGV != 1;
+
+$id = shift;
+$id = "txt_$id" unless $id =~ /^txt_/;
+
+mkdir old, 0755;
+
+for $f ("bootloader.pot", <*.po>) {
+ if(open F, $f) {
+ @f = <F>;
+ close F;
+
+ ( $new, $old ) = drop @f;
+ if(open F, ">>old/$f") {
+ print F @$old;
+ close F;
+
+ open F, ">$f";
+ print F @$new;
+ close F;
+ }
+ }
+}
+
+
+sub drop
+{
+ local $_;
+ my (@f, @g, $drop_it, @d);
+
+ for (@_) {
+ push @g, $_;
+ $drop_it = 1 if /^#\.\s*${id}\s*$/;
+ if(/^\s*$/) {
+ if($drop_it) {
+ push @d, @g;
+ }
+ else {
+ push @f, @g;
+ }
+ undef $drop_it;
+ undef @g;
+ }
+ }
+
+ if(@g) {
+ if($drop_it) {
+ push @d, @g;
+ }
+ else {
+ push @f, @g;
+ }
+ }
+
+ return ( \@f, \@d );
+}
+