summaryrefslogtreecommitdiffstats
path: root/po/bin/add_text
blob: a725b4654466a62ecef8fd33e79727a77d69aac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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;
  }
}