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

gawk: I18N Portability

 
 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, because
      'TEXTDOMAIN' is not special in other 'awk' implementations.
 
    * Non-GNU versions of 'awk' treat marked strings as the concatenation
      of a variable named '_' with the string following it.(1)
      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()', and 'bindtextdomain()', the 'awk' 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' or 'sprintf()' is
      _not_ portable.  To support 'gettext()' at the C level, many
      systems' C versions of 'sprintf()' do support positional
      specifiers.  But it works only if enough arguments are supplied in
      the function call.  Many versions of 'awk' pass 'printf' formats
      and arguments unchanged to the underlying C library version of
      'sprintf()', 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-GNU 'awk's
      never retrieve the translated string, this should not be a problem
      in practice.
 
    ---------- Footnotes ----------
 
    (1) This is good fodder for an "Obfuscated 'awk'" contest.
 
© manpagez.com 2000-2018
Individual documents may contain additional copyright information.