21.07.2015 Views

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

166 <strong>G<strong>AWK</strong></strong>: <strong>Effective</strong> <strong>AWK</strong> <strong>Programming</strong>}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 supportgettext at the C level, many systems’ C versions of sprintf do support positionalspecifiers. 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 underlyingC library version of sprintf, but only one format and argument at a time. Whathappens if a positional specification is used is anybody’s guess. However, since thepositional specifications are primarily for use in translated format strings, and sincenon-GNU awks never retrieve the translated string, this should not be a problem inpractice.9.5 A Simple Internationalization ExampleNow let’s look at a step-by-step example of how to internationalize and localize a simpleawk program, using ‘guide.awk’ as our original source:BEGIN {TEXTDOMAIN = "guide"bindtextdomain(".") # for testingprint _"Don’t Panic"print _"The Answer Is", 42print "Pardon me, Zaphod who?"}Run ‘gawk --gen-po’ to create the ‘.po’ file:$ gawk --gen-po -f guide.awk > guide.poThis produces:#: guide.awk:4msgid "Don’t Panic"msgstr ""#: guide.awk:5msgid "The Answer Is"msgstr ""This original portable object file is saved and reused for each language into which theapplication is translated. The msgid is the original string and the msgstr is the translation.

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

Saved successfully!

Ooh no, something went wrong!