7 Text Messages with Message Catalogs
In many web applications, you will find that you need
to display text messages to the web user, such as
error messages, alert messages, success messages,
and so forth. Yet you do not wish to type these messages
directly into your STML templates; what if you use them
in many places on your Web site, and then you have to
change the text of a message? You do not want to have
to hand-edit each STML document to make the change.
STML provides a nice way to manage text messages
and avoid hard-coding them into your STML documents:
message catalogs. An STML message catalog acts somewhat
like a Python dictionary: you give it a key,
which is a string, and the mesage catalog looks up
the message for that key. Unlike a dictionary, an STML
message catalog does not raise an error if it cannot
find a message under the key you request; instead,
the message catalog returns an empty string "".
Unlike a dictionary, a message catalog is not an object
which you work with directly. Instead,
you use the <:msg:> tag to access messages
in the catalog.
There are two kinds of message catalogs in STML:
- Regular, or ``simple'', catalogs
- Dictionary-like
message catalogs. Each message ``name'' is like a dictionary
key, with a single message stored for each key.
- Multi-lingual, or ``complex'', catalogs:
- Like a
simple catalog, except that each message key stores
multiple messages, one message for each language in the
catalog. (Currently supported languages are 'esp' (Spanish),
'por' (Portuguese), and 'eng' (English).
The following sections explain the three tags which
provide message catalog features.
Subsections