gettext: Special Keywords
1
1 15.5.18.3 How to Extract Hash Keys
1 ..................................
1
1 Translating messages at runtime is normally performed by looking up
1 the original string in the translation database and returning the
1 translated version. The “natural” Perl implementation is a hash lookup,
1 and, of course, ‘xgettext’ supports such practice.
1
1 print __"Hello world!";
1 print $__{"Hello world!"};
1 print $__->{"Hello world!"};
1 print $$__{"Hello world!"};
1
1 The above four lines all do the same thing. The Perl module
1 ‘Locale::TextDomain’ exports by default a hash ‘%__’ that is tied to the
1 function ‘__()’. It also exports a reference ‘$__’ to ‘%__’.
1
1 If an argument to the ‘xgettext’ option ‘--keyword’, resp. ‘-k’
1 starts with a percent sign, the rest of the keyword is interpreted as
1 the name of a hash. If it starts with a dollar sign, the rest of the
1 keyword is interpreted as a reference to a hash.
1
1 Note that you can omit the quotation marks (single or double) around
1 the hash key (almost) whenever Perl itself allows it:
1
1 print $gettext{Error};
1
1 The exact rule is: You can omit the surrounding quotes, when the hash
1 key is a valid C (!) identifier, i.e. when it starts with an underscore
1 or an ASCII letter and is followed by an arbitrary number of
1 underscores, ASCII letters or digits. Other Unicode characters are
1 _not_ allowed, regardless of the ‘use utf8’ pragma.
1