21.07.2015 Views

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9: Internationalization with gawk 167NOTE: Strings not marked with a leading underscore do not appear in the‘guide.po’ file.Next, the messages must be translated. Here is a translation to a hypothetical dialectof English, called “Mellow”: 6$ cp guide.po guide-mellow.poAdd translations to guide-mellow.po ...Following are the translations:#: guide.awk:4msgid "Don’t Panic"msgstr "Hey man, relax!"#: guide.awk:5msgid "The Answer Is"msgstr "Like, the scoop is"The next step is to make the directory to hold the binary message object file and then tocreate the ‘guide.mo’ file. The directory layout shown here is standard for GNU gettexton GNU/Linux systems. Other versions of gettext may use a different layout:$ mkdir en_US en_US/LC_MESSAGESThe msgfmt utility does the conversion from human-readable ‘.po’ file to machinereadable‘.mo’ file. By default, msgfmt creates a file named ‘messages’. This file mustbe renamed and placed in the proper directory so that gawk can find it:$ msgfmt guide-mellow.po$ mv messages en_US/LC_MESSAGES/guide.moFinally, we run the program to test it:$ gawk -f guide.awk⊣ Hey man, relax!⊣ Like, the scoop is 42⊣ Pardon me, Zaphod who?If the three replacement functions for dcgettext, dcngettext and bindtextdomain (seeSection 9.4.3 [awk Portability Issues], page 165) are in a file named ‘libintl.awk’, then wecan run ‘guide.awk’ unchanged as follows:$ gawk --posix -f guide.awk -f libintl.awk⊣ Don’t Panic⊣ The Answer Is 42⊣ Pardon me, Zaphod who?9.6 gawk Can Speak Your LanguageAs of version 3.1, gawk itself has been internationalized using the GNU gettext package.(GNU gettext is described in complete detail in GNU gettext tools.) As of this writing,the latest version of GNU gettext is version 0.17.6 Perhaps it would be better if it were called “Hippy.” Ah, well.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!