manpagez: man pages & more
info gettext
Home | html | info | man

File: gettext.info,  Node: The gettext.sh approach,  Next: The printf approach,  Prev: sh_-_Three_approaches.php">sh - Three approaches,  Up: sh

16.5.15.2 The ‘gettext.sh’ approach
...................................

   This approach uses shell functions defined in the ‘gettext.sh’ file.

   Here's an example that references a shell variable ‘pid’:
     eval_gettext "Running as process number \$pid."; echo

   A ready-to-use example is available in the ‘hello-1.sh’ file in the
‘examples/hello-sh’ directory.

Contents of ‘gettext.sh’
------------------------

   ‘gettext.sh’, contained in the run-time package of GNU gettext,
provides the following:

‘$echo’
     The variable ‘echo’ is set to a command that outputs its first
     argument and a newline, without interpreting backslashes in the
     argument string.

‘eval_gettext’
     See *note eval_gettext Invocation::.

‘eval_ngettext’
     See *note eval_ngettext Invocation::.

‘eval_pgettext’
     See *note eval_pgettext Invocation::.

‘eval_npgettext’
     See *note eval_npgettext Invocation::.

Advantages and Drawbacks
------------------------

   Advantages:
   • Portability: This is fully portable.

   Drawbacks:
   • The strings passed to the ‘eval_gettext’ et al. functions must not
     start nor end with a newline.  This means, in order to add a
     newline after a message, you need to add an explicit invocation of
     ‘echo’.
   • References to shell variables must be introduced with ‘\$’, not
     just ‘$’.
   • Speed: Each invocation of the ‘eval_gettext’ et al. functions uses
     a pipe and a subshell.  This is slower than the ‘printf_gettext’
     approach.

© manpagez.com 2000-2026
Individual documents may contain additional copyright information.