gawk: I18N Example

1 
1 13.5 A Simple Internationalization Example
1 ==========================================
1 
1 Now let's look at a step-by-step example of how to internationalize and
1 localize a simple 'awk' program, using 'guide.awk' as our original
1 source:
1 
1      BEGIN {
1          TEXTDOMAIN = "guide"
1          bindtextdomain(".")  # for testing
1          print _"Don't Panic"
1          print _"The Answer Is", 42
1          print "Pardon me, Zaphod who?"
1      }
1 
1 Run 'gawk --gen-pot' to create the '.pot' file:
1 
1      $ gawk --gen-pot -f guide.awk > guide.pot
1 
1 This produces:
1 
1      #: guide.awk:4
1      msgid "Don't Panic"
1      msgstr ""
1 
1      #: guide.awk:5
1      msgid "The Answer Is"
1      msgstr ""
1 
1 
1    This original portable object template file is saved and reused for
1 each language into which the application is translated.  The 'msgid' is
1 the original string and the 'msgstr' is the translation.
1 
1      NOTE: Strings not marked with a leading underscore do not appear in
1      the 'guide.pot' file.
1 
1    Next, the messages must be translated.  Here is a translation to a
1 hypothetical dialect of English, called "Mellow":(1)
1 
1      $ cp guide.pot guide-mellow.po
1      ADD TRANSLATIONS TO guide-mellow.po ...
1 
1 Following are the translations:
1 
1      #: guide.awk:4
1      msgid "Don't Panic"
1      msgstr "Hey man, relax!"
1 
1      #: guide.awk:5
1      msgid "The Answer Is"
1      msgstr "Like, the scoop is"
1 
1 
1    The next step is to make the directory to hold the binary message
1 object file and then to create the 'guide.mo' file.  We pretend that our
1 file is to be used in the 'en_US.UTF-8' locale, because we have to use a
1 locale name known to the C 'gettext' routines.  The directory layout
1 shown here is standard for GNU 'gettext' on GNU/Linux systems.  Other
1 versions of 'gettext' may use a different layout:
1 
1      $ mkdir en_US.UTF-8 en_US.UTF-8/LC_MESSAGES
1 
1    The 'msgfmt' utility does the conversion from human-readable '.po'
1 file to machine-readable '.mo' file.  By default, 'msgfmt' creates a
1 file named 'messages'.  This file must be renamed and placed in the
1 proper directory (using the '-o' option) so that 'gawk' can find it:
1 
1      $ msgfmt guide-mellow.po -o en_US.UTF-8/LC_MESSAGES/guide.mo
1 
1    Finally, we run the program to test it:
1 
1      $ gawk -f guide.awk
1      -| Hey man, relax!
1      -| Like, the scoop is 42
1      -| Pardon me, Zaphod who?
1 
1    If the three replacement functions for 'dcgettext()', 'dcngettext()',
1 and 'bindtextdomain()' (⇒I18N Portability) are in a file named
1 'libintl.awk', then we can run 'guide.awk' unchanged as follows:
1 
1      $ gawk --posix -f guide.awk -f libintl.awk
1      -| Don't Panic
1      -| The Answer Is 42
1      -| Pardon me, Zaphod who?
1 
1    ---------- Footnotes ----------
1 
1    (1) Perhaps it would be better if it were called "Hippy."  Ah, well.
1