summaryrefslogtreecommitdiffstats
path: root/bootloader/make-kbd-po
blob: 54ed57ea89544e65479bcf08a73b6385602b2d64 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/perl

# Copyright (C) 2017 Mageia
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

# SYNOPSIS
#
# This program reads the keyboard names file created by the make-kbd-info
# program and generates a PO file containing translations of the keyboard
# names into the language specified by the first command line argument.
# The translations are obtained from libDrakX.
#
# The keyboard names file (kbd-names.txt) is searched for in the directory
# containing this program. The PO file (${LANGUAGE}-kbd.po) is stored in
# the current working directory.

use lib qw(/usr/lib/libDrakX);

use strict;

use Cwd qw(abs_path getcwd);
use MDK::Common;
use common;
use keyboard;

# Get correct namespace (drakx-kbd-mouse-x11 instead of libDrakX).
BEGIN { unshift @::textdomains, 'drakx-kbd-mouse-x11' }

# Set the translation language.
@ARGV == 1 && $ARGV[0] or die "Usage: make-kbd-po <language code>\n";
$ENV{LANGUAGE} = $ARGV[0];

# Read the keyboard names file.
my $kbd_names = dirname(abs_path($0)) . '/kbd-names.txt';
-e $kbd_names or die "cannot find keyboard name file $kbd_names\n";
my @kbds = group_by2(eval(cat_($kbd_names)))
  or die "error in keyboard name file $kbd_names\n";

# Open the output file
my $fn = getcwd() . '/' . $ARGV[0] . '-kbd.po';
open(my $fh, '>' . $fn) or die "couldn't open $fn";

print $fh "# This file is automatically generated\n";
print $fh "\n";

foreach (@kbds) {
    my ($kbd, $msgid) = @$_;

    # make-kbd-info strips off the prefix from the drakx-kbd-mouse-x11
    # msgids, so we must use the original msgid to get the translation.
    my $msgstr = translate(keyboard::KEYBOARD2text($kbd));

    # Any double quote characters need to be escaped when writing the
    # PO file.
    $msgid  =~ s/"/\\"/g;
    $msgstr =~ s/"/\\"/g;

    # Some translations contain embedded newline characters. We need
    # all translations to be a single line.
    $msgstr =~ s/\R/ /g;

    # Write the entry for this keyboard.
    print $fh "msgid \"$msgid\"\n";
    print $fh "msgstr \"$msgstr\"\n";
    print $fh "\n";
}

close($fh);