I18N Portability (The GNU Awk User’s Guide)
From Get docs
Gawk/docs/latest/I18N-Portability
Previous: Printf Ordering, Up: Translator i18n [Contents][Index]
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
TEXTDOMAINwon’t have any effect, becauseTEXTDOMAINis not special in otherawkimplementations. - Non-GNU versions of
awktreat marked strings as the concatenation of a variable named_with the string following it.94 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(), andbindtextdomain(), theawkprogram 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
printforsprintf()is not portable. To supportgettext()at the C level, many systems’ C versions ofsprintf()do support positional specifiers. But it works only if enough arguments are supplied in the function call. Many versions ofawkpassprintfformats and arguments unchanged to the underlying C library version ofsprintf(), 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-GNUawks never retrieve the translated string, this should not be a problem in practice.
Footnotes
(94)
This is good fodder for an “Obfuscated awk” contest.
Previous: Printf Ordering, Up: Translator i18n [Contents][Index]