gawk: I18N Portability
1
1 13.4.3 'awk' Portability Issues
1 -------------------------------
1
1 'gawk''s internationalization features were purposely chosen to have as
1 little impact as possible on the portability of 'awk' programs that use
1 them to other versions of 'awk'. Consider this program:
1
1 BEGIN {
1 TEXTDOMAIN = "guide"
1 if (Test_Guide) # set with -v
1 bindtextdomain("/test/guide/messages")
1 print _"don't panic!"
1 }
1
1 As written, it won't work on other versions of 'awk'. However, it is
1 actually almost portable, requiring very little change:
1
1 * Assignments to 'TEXTDOMAIN' won't have any effect, because
1 'TEXTDOMAIN' is not special in other 'awk' implementations.
1
1 * Non-GNU versions of 'awk' treat marked strings as the concatenation
1 of a variable named '_' with the string following it.(1)
1 Typically, the variable '_' has the null string ('""') as its
1 value, leaving the original string constant as the result.
1
1 * By defining "dummy" functions to replace 'dcgettext()',
1 'dcngettext()', and 'bindtextdomain()', the 'awk' program can be
1 made to run, but all the messages are output in the original
1 language. For example:
1
1 function bindtextdomain(dir, domain)
1 {
1 return dir
1 }
1
1 function dcgettext(string, domain, category)
1 {
1 return string
1 }
1
1 function dcngettext(string1, string2, number, domain, category)
1 {
1 return (number == 1 ? string1 : string2)
1 }
1
1 * The use of positional specifications in 'printf' or 'sprintf()' is
1 _not_ portable. To support 'gettext()' at the C level, many
1 systems' C versions of 'sprintf()' do support positional
1 specifiers. But it works only if enough arguments are supplied in
1 the function call. Many versions of 'awk' pass 'printf' formats
1 and arguments unchanged to the underlying C library version of
1 'sprintf()', but only one format and argument at a time. What
1 happens if a positional specification is used is anybody's guess.
1 However, because the positional specifications are primarily for
1 use in _translated_ format strings, and because non-GNU 'awk's
1 never retrieve the translated string, this should not be a problem
1 in practice.
1
1 ---------- Footnotes ----------
1
1 (1) This is good fodder for an "Obfuscated 'awk'" contest.
1