diff options
Diffstat (limited to 'bootloader/make-kbd-po')
-rwxr-xr-x | bootloader/make-kbd-po | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/bootloader/make-kbd-po b/bootloader/make-kbd-po new file mode 100755 index 0000000..54ed57e --- /dev/null +++ b/bootloader/make-kbd-po @@ -0,0 +1,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); |