diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/msgsearch | 186 | ||||
-rwxr-xr-x | scripts/po4a-display-man | 149 | ||||
-rwxr-xr-x | scripts/po4a-display-pod | 63 |
3 files changed, 398 insertions, 0 deletions
diff --git a/scripts/msgsearch b/scripts/msgsearch new file mode 100755 index 0000000..e6d9de5 --- /dev/null +++ b/scripts/msgsearch @@ -0,0 +1,186 @@ +#! /usr/bin/env perl +eval 'exec perl -S $0 ${1+"$@"}' + if $running_under_some_shell; + +# Copyright 2002, 2003, 2004 by Martin Quinson (mquinson#debian.org) +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of GPL v2.0 or later (see COPYING). + + +=head1 NAME + +msgsearch - Extract some messages of a po file based on several criteron + +=head1 SYNOPSIS + +msgsearch [-dhvV] -i E<lt>inputE<gt> -o E<lt>outputE<gt> E<lt>filterE<gt> + +=head1 DESCRIPTION + +msgsearch is an handy tool to extract some messages of a po file. Selection +depend on the file the message where extracted from, on the flags attached +to the message or even on their actual content. It can be seen as a +generalization of msggrep allowing you to use OR between different +categories. + +The used filters are very similar to the LDAP ones: + +=over + +=item * (E<lt>fieldE<gt>=argument) + +The EQ operator returns true (and thus select the message for +extraction) if and only if the value of the E<lt>fieldE<gt> is equal to the +string used as argument. The argument are Perl regular expression, so if +you want to get an equality (and not a substring search), you have to use ^value$. + +Existing fields are: + +=over + +=item - msgid + +The actual content of the message. + +=item - msgstr + +The actual content of the translation. + +=item - reference + +The location of the message in the file where it was extracted from. It is a +space separated list of positions, each ones being of the syntax +E<gt>fileE<lt>:E<gt>line numberE<lt>. + +=item - comment + +Comment added manually (by the translators). + +=item - automatic + +Comment automatically added by the string extraction program. See the +I<--add-comments> option of the B<xgettext> program for more information. + +=item - flags + +space-separated list of all defined flags for this entry. + +Valid flags are: c-text, python-text, lisp-text, elisp-text, librep-text, +smalltalk-text, java-text, awk-text, object-pascal-text, ycp-text, +tcl-text, wrap, no-wrap and fuzzy. + +See the gettext documentation for their meaning. + +=back + +=item * (!E<lt>expressionE<gt>) + +The NOT operator returns true if the sub-E<lt>expressionE<gt> return false. + +=item * (&E<lt>expression1E<gt>E<lt>expression2E<gt>...E<lt>expressionNE<gt>) + +The AND operator returns true when all the sub-expression return true. It +return false if at least one of them return false. + +=item * (|E<lt>expression1E<gt>E<lt>expression2E<gt>...E<lt>expressionNE<gt>) + +The OR operator returns true when at least one of the sub-expression return +true. It return false if all of them return false. + +=head1 OPTIONS + +=over 4 + +=item -h, --help + +Show a short help message. + +=item -V, --version + +Displays the version of the script and exits. + +=item -i, --input + +Input file. By default, files are taken from the standard input. + +=item -o, --output + +Output file. By default, files are sent on the standard output. + +=item -v, --verbose + +Increase the verbosity of the program. + +=back + +=head1 SEE ALSO + +This tool is part of the po4a project, even if it can well prove useful in +other contexts. See L<po4a(7)> for more information about the motivations of +the po4a project, and the other tools developed in that framework. + +=head1 AUTHORS + + Martin Quinson (mquinson#debian.org) + +=head1 COPYRIGHT AND LICENSE + +Copyright 2004 by SPI, inc. + +This program is free software; you may redistribute it and/or modify it +under the terms of GPL v2.0 or later (see COPYING file). + +=cut + +use 5.16.0; +use strict; +use warnings; + +use Getopt::Long qw(GetOptions); + +use Locale::Po4a::Po; +use Locale::Po4a::Common; + +use Pod::Usage qw(pod2usage); + +textdomain('po4a'); + +sub show_version { + Locale::Po4a::Common::show_version("msgsearch"); + exit 0; +} + +my ($help,@verbose,$input,$output); +$help = 0; +@verbose = (); +$input = '-'; +$output = '-'; + +Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev'); +GetOptions( + 'input|i=s' => \$input, + 'output|o=s' => \$output, + 'help|h' => \$help, + 'verbose|v' => \@verbose, + 'version|V' => \&show_version +) || pod2usage(1); +$input eq '-' || -e $input || die sprintf(gettext("msgsearch: File '%s' does not exist")."\n",$input); +my $verbose = scalar @verbose; + +# Argument check +$help && pod2usage (0); +my $filter = shift(@ARGV) || pod2usage(1); + + +my $poin = Locale::Po4a::Po->new(); +# All following function croak on problem +print STDERR gettext("Read $input")."\n" if $verbose; +$poin->read($input); + +print STDERR gettext("Filter")."\n" if $verbose; +my $poout = $poin->filter($filter); + +print STDERR gettext("Write result to $output")."\n" if $verbose; +$poout->write($output); +0; diff --git a/scripts/po4a-display-man b/scripts/po4a-display-man new file mode 100755 index 0000000..76dfe7b --- /dev/null +++ b/scripts/po4a-display-man @@ -0,0 +1,149 @@ +#!/bin/sh +# +# po4a-display-man shows a translated manpage, recompiling everything on the fly with po4a. +# Translators can see the effects of their work without reinstalling everything. +# + +OPTIONS="" + +usage() { + echo "Usage: $0 -p PO_FILE [-m MASTER_FILE] [-o PO4A_OPT]" + return 0 +} + +error () { + echo "Error: $1" 1>&2 + exit 1 +} + +while getopts m:p:ho: option +do + case $option in + m) + MASTER="$OPTARG" + ;; + p) + PO="$OPTARG" + ;; + o) + OPTIONS="$OPTIONS $OPTARG" + ;; + h) + usage + exit 0 + ;; + [?]) + usage 1>&2 + exit 1 + ;; + esac +done + +if [ -z "$PO" ] +then + usage 1>&2 + exit 1 +fi + +if [ ! -f "$PO" ] +then + error "could not find PO file: $PO" +fi + +if [ -z "$MASTER" ] +then + echo "No manpage specified." + echo "Trying to find the manpage according to a line reference in the PO." + MASTER=$(grep -m 1 "^#:" $PO | sed -e 's/^.* \(.*\):.*$/\1/') +fi + +find_man() +{ + section="$1" + man="$2" + echo -n "Looking for manpage $file" + [ -n "$section" ] && echo " in section $section" || echo "" + MAN_NUMBER=`man --all --where --locale=C $section "$man" 2> /dev/null | wc -l` + + if [ "$MAN_NUMBER" = "0" ] + then + return 1 + elif [ "$MAN_NUMBER" != "1" ]; then + MAN_NUMBER=`man --all --where --locale=C $section "$man" 2> /dev/null | \ + grep "\/$man\.$section\(.gz\)\?$" | wc -l` + if [ "$MAN_NUMBER" = "1" ] + then + MASTER=`man --where --locale=C "$section" "$man" | grep "\/$man\.$section\(.gz\)\?$"` + echo "Multiple manpages in section $section: $(man -aw -L C $section "$man"), only one exactly matches the section." + else + error "Too many possible manpages: $(man -aw -L C $section "$man"), you must specify the manpage or the section" + fi + else + MASTER=`man --where --locale=C "$section" "$man"` + fi + + return 0 +} + +if [ ! -f "$MASTER" ] +then + echo "Can't find the master man page $MASTER" + file=$(basename "$MASTER") + MASTER="" + section="" + if ! find_man "" "$file" + then + # Maybe $file contains a section + # (in the form of file.section.extension) + section=$(echo "$file" | sed -ne 's/^.*\.\([1-9].*\)$/\1/; s/\..*//; p') + file=$(echo "$file" | sed -e 's/\.[1-9].*//') + if ! find_man "$section" "$file" + then + # Maybe there is an extension at the end of the manpage (e.g. .man) + file=$(echo "$file" | sed -e 's/\..*//') + if ! find_man "$section" "$file" + then + echo "No manpage found" + echo "You must provide the manpage with the -m option" + MASTER="" + fi + fi + fi + if [ -n "$MASTER" ] + then + echo "Using: $MASTER as the original manpage" + fi +fi + +# checking mandatory options +if [ -z "$MASTER" ] +then + usage 1>&2 + exit 1 +fi + +# checking files +if [ ! -e "$MASTER" ] +then + error "could not find master file: $MASTER" +fi + + +if [ "${MASTER%.gz}" = "$MASTER" ] +then + MAINNAME="$MASTER" +else + MAINNAME=`mktemp` + trap "rm \"$MAINNAME\"" EXIT INT + gunzip -c "$MASTER" > "$MAINNAME" +fi + +CHARSET_MASTER=`file -i "$MAINNAME" | cut -d "=" -f 2` +CHARSET_PO=`file -i "$PO" | cut -d "=" -f 2` + +po4a-translate -f man -k 0 -m "$MAINNAME" -M "$CHARSET_MASTER" \ + -p "$PO" $OPTIONS| iconv -f "$CHARSET_PO" -t // | man -l - + +# TODO: man may need some options (e.g. -L) +# as we cannot detect what options are needed, they will have to be +# specified on the po4a-display-man command line. diff --git a/scripts/po4a-display-pod b/scripts/po4a-display-pod new file mode 100755 index 0000000..cd07f46 --- /dev/null +++ b/scripts/po4a-display-pod @@ -0,0 +1,63 @@ +#!/bin/sh +# +# po4a-display-pod shows a translated pod document, recompiling everything on the fly with po4a. +# Translators can see the effects of their work without reinstalling everything. +# + +MASTER="" +NAME="" +SECTION="" +PO="" +OPTIONS="" + +usage () { + echo "Usage : $(basename $0) -m POD_FILE -p PO_FILE [-o PO4A_OPT]" +} + +while getopts m:p:o:h option; do + case $option in + m) + MASTER=$OPTARG + ;; + p) + PO=$OPTARG + ;; + o) + OPTIONS="$OPTIONS $OPTARG" + ;; + h) + usage + exit 0 + ;; + [?]) + usage 1>&2 + exit 1 + ;; + esac +done + +if [ -z $PO ] || [ -z $MASTER ]; then + usage + exit 1 +fi + +if [ ! -f $PO ]; then + echo "Error: unable to find the file $PO." + usage + exit 1 +fi + +if [ ! -f $MASTER ]; then + echo "Error: unable to find the file $MASTER." + usage + exit 1 +fi + +# Can fail to retrieve the expected result with various files... +#NAME=$(basename $MASTER .pod | sed -e 's/\..//') +#SECTION=$(basename $MASTER .pod | sed -e 's/.*\.//') + +po4a-translate -f pod -m $MASTER -p $PO -L UTF-8 -k 0 $OPTIONS \ + | pod2man -r '' -c TRANSLATED -n $MASTER --utf8 \ + | man -l - + |