[pacman-dev] [RFC v3 13/13] bacman: make gettext useful

Dave Reisner d at falconindy.com
Fri Sep 30 12:14:40 UTC 2016


On Fri, Sep 30, 2016 at 01:48:01PM +0200, Gordian Edenhofer wrote:
> Export TEXTDOMAIN and TEXTDOMAINDIR in order for the strings to be
> translatable with gettext.
> ---
>  contrib/bacman.sh.in | 28 ++++++++++++++++++++++------
>  1 file changed, 22 insertions(+), 6 deletions(-)
> 
> diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
> index 39fbe99..cc243c9 100644
> --- a/contrib/bacman.sh.in
> +++ b/contrib/bacman.sh.in
> @@ -32,6 +32,17 @@ QUIET=0
>  # Required for fakeroot because options are shifted off the array.
>  ARGS=("$@")
>  
> +# gettext initialization
> +export TEXTDOMAIN='pacman'
> +export TEXTDOMAINDIR='@localedir@'
> +
> +# Determine whether we have gettext; make it a no-op if we do not
> +if ! type -p gettext >/dev/null; then
> +	gettext() {
> +		printf "%s\n" "$@"

Not sure if this is copypasted from somewhere, but it's wrong. Consider
the output of:

  printf '%s\n' 1 2 3

vs.

  printf '%s\n' '1 2 3'

You probably wanted this to be: printf '%s\n' "$*"

> +	}
> +fi
> +
>  m4_include(../scripts/library/output_format.sh)
>  m4_include(../scripts/library/parseopts.sh)
>  
> @@ -54,13 +65,18 @@ usage() {
>  	printf -- "$(gettext "Usage: %s [options] <package(s)>")\n" "$0"
>  	echo
>  	printf -- "$(gettext "Options:")\n"
> -	printf -- "$(gettext "  -h, --help       Show this help message and exit")\n"
> -	printf -- "$(gettext "  -q, --quiet      Silence most of the status reporting")\n"
> -	printf -- "$(gettext "  -m, --nocolor    Disable colorized output messages")\n"
> -	printf -- "$(gettext "  -o, --out <dir>  Write output to specified directory (instead of \$PKGDEST)")\n"
> -	printf -- "$(gettext "  --pacnew         Package .pacnew files")\n"
> +	printf -- "  -h, --help       "
> +	printf -- "$(gettext "Show this help message and exit")\n"

This splitting/wrapping doesn't really make me think that this is an
improvement. Other patches are subjectively worse IMO -- particularly
cases where the usage wraps onto multiple lines and you're adding
arbitrary amounts of whitespace wrapping. It's hard to get right and I
suspect it'll be broken in the future. There's a reason I used a heredoc
for paccache's usage function. It's natural, reads easily, and is easy
to extend.

Still wondering if we actually care about translations for contrib, or
if we care about contrib at all.

> +	printf -- "  -q, --quiet      "
> +	printf -- "$(gettext "Silence most of the status reporting")\n"
> +	printf -- "  -m, --nocolor    "
> +	printf -- "$(gettext "Disable colorized output messages")\n"
> +	printf -- "  -o, --out <dir>  "
> +	printf -- "$(gettext "Write output to specified directory (instead of %s)")\n" "\$PKGDEST"
> +	printf -- "  --pacnew         "
> +	printf -- "$(gettext "Package .pacnew files")\n"
>  	echo
> -	printf -- "$(gettext "Examples:")" 
> +	printf -- "$(gettext "Examples:")"
>  	printf -- "    %s linux-headers\n" "$myname"
>  	printf -- "    %s -o ~/packages libarchive\n" "$myname"
>  	printf -- "    %s --nocolor --pacnew gzip make binutils\n" "$myname"
> -- 
> 2.10.0


More information about the pacman-dev mailing list