Preparing a shell script for internationalization is conceptually similar to the steps described in Sources. The concrete steps for shell scripts are as follows.
near the top of the script.
gettext.sh is a shell function library
that provides the functions
eval_gettext (see eval_gettext Invocation) and
eval_ngettext (see eval_ngettext Invocation).
You have to ensure that
gettext.sh can be found in the
TEXTDOMAINDIRenvironment variables. Usually
TEXTDOMAINis the package or program name, and
TEXTDOMAINDIRis the absolute pathname corresponding to
$prefixis the installation location.
TEXTDOMAIN=@PACKAGE@ export TEXTDOMAIN TEXTDOMAINDIR=@LOCALEDIR@ export TEXTDOMAINDIR
"$(...)"), variable access with defaulting (like
}), access to positional arguments (like
$1, ...) or highly volatile shell variables (like
$?). This can always be done through simple local code restructuring. For example,
echo "Usage: $0 [OPTION] FILE..."
program_name=$0 echo "Usage: $program_name [OPTION] FILE..."
echo "Remaining files: `ls | wc -l`"
filecount="`ls | wc -l`" echo "Remaining files: $filecount"
When doing this, you also need to add an extra backslash before the dollar sign in references to shell variables, so that the ‘eval_gettext’ function receives the translatable string before the variable values are substituted into it. For example,
echo "Remaining files: $filecount"
eval_gettext "Remaining files: \$filecount"; echo
If the output command is not ‘echo’, you can make it use ‘echo’ nevertheless, through the use of backquotes. However, note that inside backquotes, backslashes must be doubled to be effective (because the backquoting eats one level of backslashes). For example, assuming that ‘error’ is a shell function that signals an error,
error "file not found: $filename"
is first transformed into
error "`echo \"file not found: \$filename\"`"
which then becomes
error "`eval_gettext \"file not found: \\\$filename\"`"