Gawk/I18N-Portability
From Get docs
Previous: Printf Ordering, Up: Translator i18n [Contents][Index]
13.4.3 awk
Portability Issues
gawk
’s internationalization features were purposely chosen to
have as little impact as possible on the portability of awk
programs that use them to other versions of awk
.
Consider this program:
BEGIN { TEXTDOMAIN = "guide" if (Test_Guide) # set with -v bindtextdomain("/test/guide/messages") print _"don't panic!" }
As written, it won’t work on other versions of awk
.
However, it is actually almost portable, requiring very little
change:
- Assignments to
TEXTDOMAIN
won’t have any effect, becauseTEXTDOMAIN
is not special in otherawk
implementations. - Non-GNU versions of
awk
treat marked strings as the concatenation of a variable named_
with the string following it.94 Typically, the variable_
has the null string (""
) as its value, leaving the original string constant as the result. - By defining “dummy” functions to replace
dcgettext()
,dcngettext()
, andbindtextdomain()
, theawk
program can be made to run, but all the messages are output in the original language. For example:function bindtextdomain(dir, domain) { return dir } function dcgettext(string, domain, category) { return string } function dcngettext(string1, string2, number, domain, category) { return (number == 1 ? string1 : string2) }
- The use of positional specifications in
printf
orsprintf()
is not portable. To supportgettext()
at the C level, many systems’ C versions ofsprintf()
do support positional specifiers. But it works only if enough arguments are supplied in the function call. Many versions ofawk
passprintf
formats and arguments unchanged to the underlying C library version ofsprintf()
, but only one format and argument at a time. What happens if a positional specification is used is anybody’s guess. However, because the positional specifications are primarily for use in translated format strings, and because non-GNUawk
s never retrieve the translated string, this should not be a problem in practice.
Previous: Printf Ordering, Up: Translator i18n [Contents][Index]